Now that our ACME stack has been installed, let's setup some isolated development areas. To do this, we need to create one or more Virtual Hosts in Apache and setup some local domains.

Apache Virtual Hosts

In part 1, we talked about how Apache sets up the localhost domain pointed to files in /var/www/. This is why http://127.0.0.1/ displays It works! (index.html) when you first visited it and why it should display the current date and time (index.cfm) when you go there now.

Rather than run all of your projects under the same root folder and under the localhost domain, it's often a good idea to create a local domain and separate root folder for each project.

http://dev.acme.localhost

Rather than place project files under /var/www/, I often place them under my home directory or in a folder on another disk or partition.

1. Create a new root web directory.

I'm going to create a new directory at the system's root level. This will contain files for all of my projects. You'll have to use sudo to create the folder as the root user.

view plain print about
1amoreno@amoreno-desktop:~$ sudo mkdir /webroot
2[sudo] password for amoreno:
3amoreno@amoreno-desktop:/$
4amoreno@amoreno-desktop:/$ ls -l
5drwxr-xr-x 2 root root 4096 2008-06-24 23:22 webroot

Now we need to change the owner of the folder to that of your user account.

view plain print about
1amoreno@amoreno-desktop:/$sudo chown amoreno.amoreno webroot
2amoreno@amoreno-desktop:/$ ls -l
3drwxr-xr-x 4 amoreno amoreno 4096 2008-06-24 23:22 webroot

Now we can enter this folder under your normal user account and create files and folders without having to use sudo. Let's create a folder for an ACME website:

ACME root: /webroot/iknowkungfoo/acme/
view plain print about
1amoreno@amoreno-desktop:/$ cd /webroot/
2amoreno@amoreno-desktop:/$ mkdir iknowkungfoo
3amoreno@amoreno-desktop:/$ cd iknowkungfoo
4amoreno@amoreno-desktop:/webroot/iknowkungfoo$ mkdir acme
5amoreno@amoreno-desktop:/webroot/iknowkungfoo$ cd acme
6amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$

Create a default page:

Editing files You can use the vi editor to create this file. This is a screen based text editor. Info and commands can be found here.

view plain print about
1amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$ vi index.cfm

Or you can use the gedit editor, which is like Notepad on Windows.

view plain print about
1amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$ gedit index.cfm

index.cfm
view plain print about
1<h1>The ACME Guide: 64-bit Ubuntu Edition</h1>
2<cfoutput>#now()#</cfoutput>

Save the file and quit the editor.

2. Create a new Virtual Host entry.

Now we need to let Apache know how to find the files for the ACME website. For that, we need to go to the Apache folder.

/etc/apache2/
view plain print about
1amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$ cd /etc/apache2/
2amoreno@amoreno-desktop:/etc/apache2$ ls -l
3total 52
4-rw-r--r-- 1 root root 10587 2008-05-14 02:58 apache2.conf
5drwxr-xr-x 2 root root 4096 2008-06-12 23:14 conf.d
6-rw-r--r-- 1 root root 378 2008-05-14 02:58 envvars
7-rw-r--r-- 1 root root 904 2008-06-06 01:54 httpd.conf
8-rw-r--r-- 1 root root 0 2008-06-06 01:54 httpd.conf.1
9drwxr-xr-x 2 root root 12288 2008-06-12 23:14 mods-available
10drwxr-xr-x 2 root root 4096 2008-06-03 00:03 mods-enabled
11-rw-r--r-- 1 root root 59 2008-05-14 02:58 ports.conf
12drwxr-xr-x 2 root root 4096 2008-06-24 22:47 sites-available
13drwxr-xr-x 2 root root 4096 2008-06-24 22:52 sites-enabled
14amoreno@amoreno-desktop:/etc/apache2$

Let's go into the sites-available folder and open the default website configuration file.

Actually, let's create a copy so that we don't lose the default settings.

view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-available$ ls -l
2total 4
3-rw-r--r-- 1 root root 985 2008-05-14 02:58 default
4amoreno@amoreno-desktop:/etc/apache2/sites-available$ sudo cp default acme
5amoreno@amoreno-desktop:/etc/apache2/sites-available$ ls -l
6total 8
7-rw-r--r-- 1 root root 985 2008-06-25 00:04 acme
8-rw-r--r-- 1 root root 985 2008-05-14 02:58 default

To make things easy, open the acme file in gedit. Notice that the file is owned by the root user.

file: acme
view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-available$ sudo gedit acme
2[sudo] password for amoreno:
gedit: acme
view plain print about
1NameVirtualHost *
2<VirtualHost *>
3    ServerAdmin webmaster@localhost
4    
5    DocumentRoot /var/www/
6    <Directory />
7        Options FollowSymLinks
8        AllowOverride None
9    </Directory>
10    <Directory /var/www/>
11        Options Indexes FollowSymLinks MultiViews
12        AllowOverride None
13        Order allow,deny
14        allow from all
15    </Directory>
16
17    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
18    <Directory "/usr/lib/cgi-bin">
19        AllowOverride None
20        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
21        Order allow,deny
22        Allow from all
23    </Directory>
24
25    ErrorLog /var/log/apache2/error.log
26
27    # Possible values include: debug, info, notice, warn, error, crit,
28    # alert, emerg.
29    LogLevel warn
30
31    CustomLog /var/log/apache2/access.log combined
32    ServerSignature On
33
34 Alias /doc/ "/usr/share/doc/"
35 <Directory "/usr/share/doc/">
36 Options Indexes MultiViews FollowSymLinks
37 AllowOverride None
38 Order deny,allow
39 Deny from all
40 Allow from 127.0.0.0/255.0.0.0 ::1/128
41 </Directory>
42
43</VirtualHost>

In the normal distribution of Apache, these settings would be broken up across a few files. The version that is maintained in the Synaptic Package Manager keeps them all in one file, so copying and making changes will be very easy.

Changes to acme 0. Remove or comment out the first line (thanks bpickens)

A "#" before any line marks a comment.

view plain print about
1#NameVirtualHost *

1. Add a ServerName

view plain print about
1<VirtualHost *>
2    ServerName dev.acme.localhost
3    ServerAdmin webmaster@localhost

2. Change the DocumentRoot

view plain print about
1DocumentRoot /webroot/iknowkungfoo/acme/

3. Give Apache permission to access the new folder you created.

view plain print about
1<Directory /webroot/iknowkungfoo/acme/>
2        Options Indexes FollowSymLinks MultiViews
3        AllowOverride None
4        Order allow,deny
5        allow from all
6    </Directory>

4. Change the Error Log.

view plain print about
1ErrorLog /var/log/apache2/acme-error.log

5. Change the CustomLog.

view plain print about
1CustomLog /var/log/apache2/acme-access.log combined

6. Optional: Create an alias to /CFIDE and other folders.

view plain print about
1Alias /CFIDE /var/www/CFIDE

7. Save the file and exit the editor.

view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-enabled$

3. Create a new link in sites-enabled.

We just edited the acme file in the sites-available folder. Apache only loads Virtual Host configurations in the sites-enabled folder.

view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-available$ ls -l
2total 8
3-rw-r--r-- 1 root root 985 2008-06-25 00:04 acme
4-rw-r--r-- 1 root root 985 2008-05-14 02:58 default
5amoreno@amoreno-desktop:/etc/apache2/sites-available$ cd ../sites-enabled/
6amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ ls -l
7total 0
8lrwxrwxrwx 1 root root 36 2008-06-03 00:03 000-default ->
/etc/apache2/sites-available/default
9amoreno@amoreno-desktop:/etc/apache2/sites-enabled$

In the sites-enabled folder, you can see that there is a link to the default Virtual Host file. Let's create one for acme.

view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ sudo ln -s ../sites-available/acme
2[sudo] password for amoreno:
3amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ ls -l
4total 0
5lrwxrwxrwx 1 root root 36 2008-06-03 00:03 000-default ->
/etc/apache2/sites-available/default
6lrwxrwxrwx 1 root root 23 2008-06-25 00:18 acme -> ../sites-available/acme
7amoreno@amoreno-desktop:/etc/apache2/sites-enabled$

4. Restart Apache

Apache has to be restarted to load the new Virtual Host configurations.

view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ sudo /usr/sbin/apache2ctl restart

5. Create a new hosts entry.

Every OS has a file that acts like a local Domain Name Server. Open it and add the ServerName you created in the acme file, pointing to 127.0.0.1.

Hosts file: /etc/hosts
view plain print about
1amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ sudo gedit /etc/hosts
gedit: /etc/hosts
view plain print about
1127.0.0.1    localhost
2127.0.1.1    amoreno-desktop
3127.0.0.1    dev.acme.localhost

Save and exit gedit.

6. Open the URL in a browser.

You should now be able to enter http://dev.acme.localhost into your browser and see the output from /webroot/iknowkungfoo/acme/index.cfm.

http://dev.acme.localhost The ACME Guide: 64-bit Ubuntu Edition
{ts '2008-06-25 00:34:28'}

That's it for now

Your 64-bit Ubuntu ColdFusion development environment is now up and running at full steam. If you have any questions or if you'd like to see something else added to this version of The ACME Guide, let me know in the Comments or through my Contact form.

Now that I've got my own ACME setup running, I can get back to the CF + OOP Primer and get some work done on that book I'm supposed to be writing. :)