Notes on installing Apache’s virtual hosts on OpenSolaris 2008.11; part of a series that started with Installing OpenSolaris.
On Debian, you have to set up virtual hosts using separate files, called sites-enabled and sites-available, part of the Debian Way Of Doing Things, which is not documented on the Apache site. (I’ve written about this before; the link I refer to there is no longer available, so try this one if you’re on a Debian or Ubuntu platform.) Fortunately, OpenSolaris seems to use the standard Apache methods, so named virtual hosts can be set up using the documentation at Name-based Virtual Host Support (the method you choose when you want to run multiple web sites from one IP address). It’s easy to find the httpd.conf
file, it’s in the Web Stack Options application, under Advanced Configuration on the Apache2
tab (and even labelled “edit httpd.conf“).
I set up a virtual host for each web site on the development machine. This is a little more complicated than it is if you’re starting from scratch with a new site, since I want to be able to set up all the software and systems on each web site on a test basis, before switching the old server off and the new one on. In the meantime of course, the old server is still serving those websites with the same URLs. So I needed a system that allows the computer I’m developing on to see the new sites reached from those URLs, while the rest of the world sees the old sites.
The way to do this is to edit the hosts file on the development machine. In a terminal window, type pfexec vim /etc/hosts
. After the bottom line, which should look something like 127.0.0.1 machinename.local localhost loghost
, add the line(s) 127.0.0.1 websitename
. You don’t even need to reboot or restart the Apache server, which is nice. If it doesn’t work (you don’t see what you expect in your browser), take a look at your /etc/nsswitch.conf file and make sure that the hosts
line has the files
directive before the dns
directive, otherwise the system will ask the DNS server (which will return the site the rest of the world sees) before asking the hosts file on your system. One way to check which IP address you’re looking at to make sure you’re looking at your test system, not the outside one on the net, is to use getent hosts websitename
. This should tell you the IP address is 127.0.0.1. The common alternative command, host websitename
, asks the DNS server and thus will tell you what the outside world sees.
Debugging the httpd.conf file is the next step, to make sure you have those virtual hosts set up correctly. In the end, I just added
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainname
ServerAlias domainname www.domainname
DocumentRoot "/var/apache2/2.2/htdocs/domain"
CustomLog "/var/apache2/2.2/logs/access_log" combined
</VirtualHost>
to the end of the existing httpd.conf file.
Update: I also had to add
<Directory /var/apache2/2.2/htdocs/domain>
Options Indexes MultiViews FollowSymLinks
AllowOverride FileInfo
Order allow,deny
Allow from all
</Directory>
to the virtual host directive (just above the custom log line) to make WordPress’s prettier permalinks work.
The one thing OpenSolaris does that is different to the Apache documentation is putting things somewhere different, so instead of using /usr/local/apache2/bin/httpd -S
to debug the virtual host configuration, you use /usr/apache2/2.2/bin/httpd -S
. I learned the hard way that if you want to use a default virtual host, you have to define a ServerName
for it.