Recently I had to perform and upgrade of my XServer running Mac OS X Leopard Server. The precipitating events that lead up to this moment are not as relevant as what happened after the upgrade. It took nearly a fully 24 hours to sort out all of the ripples caused by this the worst was getting the stock Apache server to play nice with my hosted sites.
These sites were happily hosted on FreeBSD 8.0 where I have the finite control I am used to in a UNIX environment. Unfortunately the server hardware is a rather old and extremely noisy power hog. The times as they are I decided that I need to consolidate these machines. The XServer is much more efficient than the old HP Proliant DL340 and well let’s face it a hell of a lot quieter.
All of that aside the office experienced a dead UPS and several power fluctuations that pushed things forward a bit earlier than planned. Fortunately I am a huge fan of redundancy and backups thus I was able to start the migration as soon as I upgraded the XServer to Snow Leopard. After the migration I did have some difficulty with directory services but through the shear force of will I was able to sort that out in an afternoon and pretty much got everything up and rolling by late yesterday evening.
Apache on the other hand was a little less cooperative. truth be told my experience hosting web site especially one run on PHP under Mac OS X Server has always been less than fruitful. First the version that shipped with 10.5 lacked many of the standard options that almost every other BAMP stack (also known as LAMP stack) has available. Fortunately in Mac OS X 10.6 Snow Leopard Server Apple corrected this to a certain extent but building a kitchen sink PHP5 module.
At this point it is a matter of setting up databases and migrating the current web content from the old server to it new home on the XServer. The issue you run into is that Apple’s Server Admin GUI is tailored to IP addressed vhosting which is fine if you have a surplus of spare IP addresses at your disposal. This is also great if you are only hosting the built-in intranet, webmail, wiki and iCal service, however; if this is not the case and you are among the IP address poor then you are out of luck. Your only resort is to turn on the Apache directive NameVirtualHost which forces the web server to reference ALL vhosts by the name requested in lieu of the IP address routed. This can be extremely handy on multi-homed servers or machines behind NAT.
NameVirtualHost *
In order for this to work you set the directive immediately prior to the standard vhost directives in /etc/apache2/httpd.conf (which really points to /private/etc/apache2/httpd.conf). It’s really that simple as far as Apache is concerned. Of course you will also need to properly setup DNS so that your server knows how properly reference the names to your local addresses.
#### #### The following Include directive is essential for the virtual hosts to be usable. #### Include "/etc/apache2/sites/*.conf"
If you only have a handful of sites you can modify /etc/hosts but bind is probably a better choice. It is likely that if you are running OS X Server you are already running named anyway so my recommendation is to leverage that service over static host files. Host files are not very resilient and can cause problems if they are not kept up to date which can be a lot of extraneous effort in even a mid sized environment.
Therefore let us assume that you are a DNS ranger and have properly set up your servers DNS using the Server Admin of course and are ready to build some vhosts in the Web manager as shown in the following screen shot. Remember to save any changes you make fortunately Apple has assume that you will forget and the GUI will kindly remind you.
With name based vhost resolution you set the vhost address to any. In fact if you specify an address unusual things can happen. It has been my experience that you should not mix name based and IP address based vhosting in the same server. I mean you can do whatever you want I wont stop you but I will not mix the two it tend to disrupt the whole space time continuum thing because it is like mixing your matter and antimatter in the same cup.
Finally you need to examine your server aliases because the Apple GUI in the Server Admin loves to make assumptions for the user. Basically it’s the old adage that the easier it is to point and click the dumber the user needs to be. The issue here is that if you do not know what is going on under the hood you can be a very effective point and clicker but a truly pathetic engineer. By default the system will set the aliases to be a wildcard of ALL which of course can wreak havoc on your system if you really wanted to host multiple sites by name. Simply edit that field and set it explicitly to what you want.
Since I do not want every site to resolve to this vhost I have explicitly set the desired aliases for jafdip.com. #TroubleShootingTip: If you neglect to perform this then you will see all sites listed below this one in the GUI routed to this one. All sites above it will be properly routed. Obviously if you have a catchall site then make certain it is the LAST site listed. Think of this like a bash case statement. Refer to the following image for details.
As you can see working with the Mac OS X Server Admin GUI is not difficult be sometimes you need to understand how these things work before you can bend them to your will. Fortunately since the operating system is based on FreeBSD and many other open source ports it is relatively trivial to learn how to adjust the results. One thing worth noting is that if you make a change to a core system file like the httpd.conf it may get reverted when you perform a system update. It is wise to keep a backup of these files and some detail notes about these changes just in case.
In the future I plan on upgrading to Mac OS X 10.7 Lion Server but only after the dust settles on this upgrade. I am even considering deploying a bank of mini’s to replace this Xserver in the future so I hope to utilize some of OS X’s clustering features.
ABOUT THE AUTHOR: Mikel King has been a leader in the Information Technology Services field for over 20 years. He is currently the CEO of Olivent Technologies, a professional creative services partnership in NY. Additionally he is currently serving as the Secretary of the BSD Certification group as well as a Senior Editor for the BSD News Network and JAFDIP.
Related articles
- Why IT Won’t Like Mac OS X Lion Server (apple.slashdot.org)
- Apple Issues Mac OS X 10.6.8 Supplemental Update for Snow Leopard (techie-buzz.com)
- New Snow Leopard Patch Fixes Lion Migration Issues (mashable.com)
- OS X Lion Server: Making servers accessible to all (tuaw.com)
kran-rf.ru says
It is the second entry I read tonight. And I am on my third. Got to think which one is next. Thank you.
kran-rf.ru says
Thank you very much for that wonderful article