Mark Allen Neil photo

Mark Allen

An online résumé, blog, biography and digital sandbox


Getting my Ubuntu LAMP server running (part 2)

Posted 2010-02-09 in Web

This is part two of how I get LAMP server up and running again. In this article…

  • I’ll setup Apache to “virtual host” my three websites on my system
  • I’ll clone my sites from the web to my local system

Configuring Virtual Hosts

What I want to be able to do on my local system is to host my three websites simultaneously on the same system. I want to be able to use a different name for each (Sparklegram, AuthorCollector and MarkAllenNeil). Entering these different names into the browser address field should direct the server to route the request to a different path on the server.

To implement virtual hosts, my first thought was to use Name-based Virtual Host Support… a different way than how I’d done this previously with IP-based Virtual Host Support. After three or four frustrating hours where I just couldn’t get name-based to work, I gave up and wnet back to the ip-based approach… which I got working the first time I tried. A few interesting notes…

  • With either approach, you have to edit the “host” file for name-based (as you do for ip-based). So Name-based hosting isn’t simpler in this respect.
  • I discovered (or perhaps rediscovered) that you have to clear the browser’s cache to test this stuff. If you don’t, you may make a change yet not see an impact in your browser. To be sure, I learned to exit all instances of FireFox… restart, clear cache… then visit my virtual host.
  • Most of the files to be changed require root access. I found issuing a gksudo nautilus command from a terminal window handy. I won’t preface commands henceforth with “sudo” as I’ll assume you’re logged in as root.

Step 1: Create virtual host files in the sites-available directory

In the version of Apache2 I’m using, the /etc/apache2/sites-available/default file is used to define virtual hosts… it can define one or more hosts. If there are more than one hosts, you can either replicate the information bracketed by <virtualhost> directive and tailor the information within each block… or you can create multiple copies of the default file and edit each file accordingly. When doing the latter, you’ll need to issue an a2ensite command for each virtual site… this is the approach I took so we’ll see that later in this article.

So what is in each of these virtual host files? A lot of configuration data… probably best to go to the Apache documentation to see everything. The minimum values required are ServerName and DocumentRoot. I included a few additional values, as follows…

  • A VirtualHost directive to map this website to an IP address (requires an equivalent statement in the hosts file)
  • A ServerAdmin directive to define the server admin (me)
  • A ServerName directive to define the mnemonic I’ll use to refer to the site when browsing
  • A DocumentRoot directive which references the folder in which I’ll host that particular site
  • ErrorLog and LogLevel directives to set up where and how much will be logged

There are a few other directives in the default file which I didn’t use… ScriptAlias is one (for CGI scripting, which I’m not using)… which I didn’t need.

So the following is an example of the virtual host file used for the Sparklegram website… mapped to IP address

    ServerName sparklegram
    DocumentRoot /home/markallenneil/websites/sparklegram
    ErrorLog /home/markallenneil/websites/logs/sparklegram.log
    LogLevel warn

I intentionally located my log files for each website in the same directory… and outside of the accessible web path. I’d read somewhere that this was a good security practice.

Step 2: Modify the hosts file to reflect the virtual hosts above

[Work In Progress]

Website Credits | Symphony | Fluid 960 Grid System