Virtual hosts, PHP and MySQL on Mac OS X 10.5 Leopard
A couple of weeks ago when I posted Mac OS X 10.5 Leopard improves accessibility I mentioned that I hadn’t yet been able to get hold of a copy of Leopard to try the new features out for myself.
Well, later that week I decided to give it a try, so I went out and bought myself a copy along with a new hard drive so I could clone my current disk before installing Leopard. And that proved to be a very good thing.
Relying on my previous experiences of upgrading to a new major release of Mac OS X I decided to play it safe and use the Archive and Install option. I wanted a “clean” OS without having to create a new user and reinstall everything.
Archive and Install has worked fine for me before, but not this time. I’m not blaming Apple or anyone else for the trouble I had, but I think others may find themselves having similar problems, so describing my problems and what I did to work around them will hopefully be of help to someone.
First try: Archive and Install
As I write this I am running Leopard again, and this time everything seems to work properly. I say again, because after running into too many problems after my initial install I thanked myself for taking the time to make a bootable clone of my hard drive before installing.
Getting a working setup back was just a matter of visiting the Startup Disk panel in System Preferences and switching to the clone. A reboot and I was back to where I was before I started, except for one thing that I’ll get to shortly.
The web development-related problems I had were these:
- The hostnames for my development sites were gone
- My Apache Virtual Hosts were gone
- PHP didn’t work
- MySQL didn’t work
The above were serious enough that after spending many hours trying and failing to get my local web development stuff up and running again, I told myself to get over it and switch back to Tiger. So I did.
When I told my colleagues at work about this I was met with surprised looks and “Well I didn’t have any problems. Everything works fine for me. I just inserted the Leopard disk and upgraded.” It turned out that the difference was that they had all picked the default Upgrade option instead of choosing Archive and install. That’s what I got for trying to be smart.
Not really wanting to leave that brand new copy of Leopard on my shelf to collect dust I decided to try it again, but just upgrading this time.
Preparing for the second try: cloning a disk used by Time Machine
To prepare for the upgrade I wanted to clone my Tiger disk again, and that gave me my next headache: Time Machine. Immediately after installing Leopard the first time I was foolish enough to switch on Time Machine and let it make a full backup of my Leopard disk. Making backups is good after all. But not if you later decide to make a clone of the disk that is used by Time Machine, even after you have rebooted into Tiger.
I deleted a visible folder called “Backups.backupdb” that Time Machine had created, and I thought that was where all the Time Machine data was stored. Apparently not. I tried cloning the disk with Carbon Copy Cloner and SuperDuper!, and both got stuck when they tried to copy a hidden folder called “.HFS+ Private Directory Data”.
Reluctant to delete this folder without being sure that it was harmless I tried cloning everything else, but that also failed. What I did in the end was delete (in the Terminal) these files and folders:
.HFS+ Private Directory Data
I’m not sure that deleting the
.fseventsd folder is necessary, but as far as I can tell it is a Leopard thing, and I wanted to get rid of all traces of Leopard from this disk, so delete it I did.
After that scary episode of deleting files I wasn’t sure that I should be deleting I verified that everything seemed to still be working OK and breathed a sigh of relief. I was then able to clone the disk with Carbon Copy Cloner without any further problems (other than it taking an hour and a half).
I suppose wanting to clone a disk with Time Machine data on it is a somewhat unusual situation, so perhaps there won’t be many others who run into the same problem. Just in case someone does, knowing that deleting these files and folders fixed the issue for me without causing any apparent problems might be helpful.
Disclaimer: In no way do I guarantee that doing this is safe. If you delete the files and folders mentioned here and end up losing valuable data, do not blame me. If there is data that you cannot afford to lose on the disk, make sure you have a reliable backup.
Second try: Upgrade and web server configuration
A quick couple of reboots to verify that the clone really worked and I was finally ready to install Leopard again, this time without doing an Archive and Install.
The upgrade went smoothly, and after about half an hour I had rebooted into Leopard with no noticeable problems. So far so good. Time to get my development sites up and running again. To do that I had to do a number of things.
- Create a hosts file. I previously used Netinfo Manager to handle hostnames for my development sites. There is no Netinfo Manager in Leopard, so I had to reenter all hostnames into the
hostsfile. It’s easy though – all I had to do was open
/private/etc/hostsand add the hostnames I need, using the same format as the hosts already in the file.
- Enable PHP. By default PHP is disabled in Leopard, so I had to uncomment the line
# LoadModule php5_module libexec/apache2/libphp5.soin
- Tell Apache where my sites are located. Since I like to keep my sites in a different location than the default
/Library/WebServer/Documents, I had to add a new
/private/etc/apache2/httpd.conf(I could also have edited the default).
Copy my virtual hosts. Virtual hosts used to be configured in
/etc/httpd/httpd.conf, but Leopard comes with Apache 2, where virtual hosts are setup in
/private/etc/apache2/extra/httpd-vhosts.conf. To enable virtual hosts I uncommented the line
# Include /private/etc/apache2/extra/httpd-vhosts.confin
I then copied my
/private/etc/apache2/extra/httpd-vhosts.conf, but the virtual hosts didn’t work until I enclosed the DocumentRoot paths in quotes (""). As far as I can tell from the Apache 2 documentation, that shouldn’t be necessary, so I’m not sure why I had to do it. Either way, adding the quotes made it work. The
NameVirtualHostdirective in my
httpd.conffile had an argument of
*instead of the
*:80that was in the
httpd-vhosts.conffile, so I had to change that as well.
- Tell PHP where the socket for MySQL is. I had to open
mysql.default_socket = /private/tmp/mysql.sock.
- Increase PHP’s memory allocation. When I tried to access one of my sites I got a
PHP Fatal error: Allowed memory size of 8388608 bytes exhausted, which means PHP has run out of memory. The default is 8 MB, which I increased to 16 MB by changing line 232 in
memory_limit = 16M.
- Restart Apache. While going through this I restarted Apache several times, but once is enough if you do it after making all of the above changes:
sudo apachectl graceful.
Not too bad once you know what to do. It can take forever to find all the info though, so when it’s time to upgrade my office machine I’ll only need to revisit this article to find everything in one place.
After all of that, I finally have a Leopard install that I can use for Web development.
I got the info I needed to get my install of Mac OS X 10.5 Leopard working properly from various sources, including the following:
- Mac OS X: How to Add Hosts to Local Hosts File
- Apache PHP and Mysql on Leopard
- Solve PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried…
- How do you delete a Time Machine created backup directory?
Subscribe / follow
DreamHost web hosting
Use the promo code 456BEREASTREET3 to save USD 20 when you sign up for DreamHost