i Know Kung Foo Consulting

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

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 based text 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
<h1>The ACME Guide: 64-bit Ubuntu Edition</h1>
<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 0. Remove or comment out the first line (thanks bpickens)

A "#" before any line marks a comment.

#NameVirtualHost *

1. Add a ServerName

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

2. Change the DocumentRoot

DocumentRoot /webroot/iknowkungfoo/acme/

3. 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>

4. Change the Error Log.

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

5. Change the CustomLog.

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

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

Alias /CFIDE /var/www/CFIDE

7. Save the file and exit the editor.

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

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.

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


Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
John Wise's Gravatar Yo Adrian! (no, it never gets old :)

Thanks for putting these ACME guides together. I upgraded from Vista to Ubuntu (and then to Mint for its admin tools & aesthetics) a few months back, but hadn't really setup any local dev stuff other than Eclipse. This guide made it pretty easy to get up and running with a full local dev environment in just a short amount of time.

If you've got any tips on making VNC as fast as (or faster than) RDP, I'd love to hear them. In the meantime, I look into setting up an RDP server on Mint.
# Posted By John Wise | 6/27/08 9:53 AM
bpickens's Gravatar Thanks again Adrian for another great Primer. I learned alot from your CF-OOP/Mach-II primers

I think just about the only thing I would add to this is to remove the 'NameVirtualHost *' directive at the top of the new configuration file. Else apache throws an error.
# Posted By bpickens | 7/12/08 4:33 PM
Hem Talreja's Gravatar Hi Adrian,

How do we start-up ColdFusion as a service?

Thanks for your help
# Posted By Hem Talreja | 9/4/08 12:46 AM
T-Man's Gravatar Would be nice to add some sort of FTP server just to round out the whole thing. I use Linux for testing of applications only and do all my dev work on a Win Server system, but after playing with Ubuntu I may be changing that. First Linux install that I like.

Anyway, thanks for a great How-To!!
# Posted By T-Man | 10/22/08 11:19 PM
Nik's Gravatar I can't seem to start coldfusion service at startup? Any suggestions?
# Posted By Nik | 11/7/08 11:47 AM
Adrian J. Moreno's Gravatar @Nik: Shane Zehnder has a post about that.

http://www.kisdigital.com/index.cfm/2008/11/13/Sta...
# Posted By Adrian J. Moreno | 11/13/08 2:07 PM