The ACME Guide: 64-bit Ubuntu 8.04 LTS Hardy Heron Edition - Part 5

Posted on June 25, 2008

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.

amoreno@amoreno-desktop:~$ sudo mkdir /webroot
[sudo] password for amoreno:
amoreno@amoreno-desktop:/$
amoreno@amoreno-desktop:/$ ls -l
drwxr-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.

amoreno@amoreno-desktop:/$sudo chown amoreno.amoreno webroot
amoreno@amoreno-desktop:/$ ls -l
drwxr-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/

amoreno@amoreno-desktop:/$ cd /webroot/
amoreno@amoreno-desktop:/$ mkdir iknowkungfoo
amoreno@amoreno-desktop:/$ cd iknowkungfoo
amoreno@amoreno-desktop:/webroot/iknowkungfoo$ mkdir acme
amoreno@amoreno-desktop:/webroot/iknowkungfoo$ cd acme
amoreno@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 basedtext editor. Info and commands can be found here.

amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$ vi index.cfm

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

amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$ gedit index.cfm

index.cfm

# The ACME Guide: 64-bit Ubuntu Edition
<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/

amoreno@amoreno-desktop:/webroot/iknowkungfoo/acme$ cd /etc/apache2/
amoreno@amoreno-desktop:/etc/apache2$ ls -l
total 52
-rw-r--r-- 1 root root 10587 2008-05-14 02:58 apache2.conf
drwxr-xr-x 2 root root  4096 2008-06-12 23:14 conf.d
-rw-r--r-- 1 root root   378 2008-05-14 02:58 envvars
-rw-r--r-- 1 root root   904 2008-06-06 01:54 httpd.conf
-rw-r--r-- 1 root root     0 2008-06-06 01:54 httpd.conf.1
drwxr-xr-x 2 root root 12288 2008-06-12 23:14 mods-available
drwxr-xr-x 2 root root  4096 2008-06-03 00:03 mods-enabled
-rw-r--r-- 1 root root    59 2008-05-14 02:58 ports.conf
drwxr-xr-x 2 root root  4096 2008-06-24 22:47 sites-available
drwxr-xr-x 2 root root  4096 2008-06-24 22:52 sites-enabled
amoreno@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.

amoreno@amoreno-desktop:/etc/apache2/sites-available$ ls -l
total 4
-rw-r--r-- 1 root root  985 2008-05-14 02:58 default
amoreno@amoreno-desktop:/etc/apache2/sites-available$ sudo cp default acme
amoreno@amoreno-desktop:/etc/apache2/sites-available$ ls -l
total 8
-rw-r--r-- 1 root root  985 2008-06-25 00:04 acme
-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

amoreno@amoreno-desktop:/etc/apache2/sites-available$ sudo gedit acme
[sudo] password for amoreno:

gedit: acme

NameVirtualHost *
<VirtualHost *>
  ServerAdmin webmaster@localhost

  DocumentRoot /var/www/
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>

  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>

  ErrorLog /var/log/apache2/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog /var/log/apache2/access.log combined
  ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</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

Remove or comment out the first line (thanks bpickens).

A “#” before any line marks a comment.

#NameVirtualHost *

Add a ServerName

<VirtualHost *>
  ServerName dev.acme.localhost
  ServerAdmin webmaster@localhost

Change the DocumentRoot

  DocumentRoot /webroot/iknowkungfoo/acme/

Give Apache permission to access the new folder you created.

  <Directory /webroot/iknowkungfoo/acme/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>

Change the Error Log.

  ErrorLog /var/log/apache2/acme-error.log

Change the CustomLog.

  CustomLog /var/log/apache2/acme-access.log combined

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

  Alias /CFIDE /var/www/CFIDE

Save the file and exit the editor.

amoreno@amoreno-desktop:/etc/apache2/sites-enabled$

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

amoreno@amoreno-desktop:/etc/apache2/sites-available$ ls -l
total 8
-rw-r--r-- 1 root root  985 2008-06-25 00:04 acme
-rw-r--r-- 1 root root  985 2008-05-14 02:58 default
amoreno@amoreno-desktop:/etc/apache2/sites-available$ cd ../sites-enabled/
amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ ls -l
total 0
lrwxrwxrwx 1 root root 36 2008-06-03 00:03 000-default -> /etc/apache2/sites-available/default
amoreno@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.

amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ sudo ln -s ../sites-available/acme
[sudo] password for amoreno:
amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ ls -l
total 0
lrwxrwxrwx 1 root root 36 2008-06-03 00:03 000-default -> /etc/apache2/sites-available/default
lrwxrwxrwx 1 root root 23 2008-06-25 00:18 acme -> ../sites-available/acme
amoreno@amoreno-desktop:/etc/apache2/sites-enabled$

4. Restart Apache

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

amoreno@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

amoreno@amoreno-desktop:/etc/apache2/sites-enabled$ sudo gedit /etc/hosts

gedit: /etc/hosts

127.0.0.1  localhost
127.0.1.1  amoreno-desktop
127.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.

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. :)

About the Author
Adrian J. Moreno

Adrian is a CTO and solution architect specializing in software modernization. More information