This is part two of how I get LAMP server up and running again. In this article…
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…
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…
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 127.0.4.1.
<VirtualHost 127.0.4.1>
ServerName sparklegram
ServerAdmin markallenneil@yahoo.com
DocumentRoot /home/markallenneil/websites/sparklegram
ErrorLog /home/markallenneil/websites/logs/sparklegram.log
LogLevel warn
</VirtualHost>
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.
[Work In Progress]
Website Credits | Symphony | Fluid 960 Grid System