Home Codex Mac OS X Localhost Development with Mac OS X v10.5.5

Twiners Codex

Web Hosts

Lunarpages.com Web Hosting
Localhost Development with Mac OS X v10.5.5

You may have noticed that some things have changed in regard to localhost development on Mac OS X Leopard (10.5.5)

Namely, with the switch to Apache2, the configuration files are in new places...   this article will discuss what the new settings are and how to fix your configuration to support the new paradigm.  More than that, we’d like to share with you how to set up your localhost development so that your Parallels Windows instances will be able to see the sites you’re working on.

There are a lot of variations on this technique out there... some people use Bonjour, while others go into their windows configurations and edit subnet masks and the like.   I prefer this way of doing it because it touches the least amount of files, it’s simple, and it works.

Getting Started

The first thing you should do is activate the latest PHP.  To do this, use a text editor to open /etc/apache2/httpd.conf and un-comment the following lines by removing the # symbol (around line 114):

LoadModule php5_module        libexec/apache2/libphp5.so
LoadModule fastcgi_module     libexec/apache2/mod_fastcgi.so

You may notice that your MySQL is not working in Leopard — The problem now is that PHP thinks MySQL is located at /var/mysql/mysql.sock while Apple has seen fit to move it to /private/tmp/mysql.sock.  Here’s how to update the config file to point it to the correct location for Leopard:

Open /etc/php.ini and edit the mysql.default_socket (around line 760) to read:

mysql.default_socket = /private/tmp/mysql.sock

If you don’t already have a php.ini file, you can make one by using Terminal 
to copy a default one to the correct location and then make the edit there.
The command in Terminal would be: sudo cp /etc/php.ini.default /etc/php.ini ...make the edit to mysql.default_socket and MySQL and PHP should be happy together again.

And now for the fun part!  To set up virtual hosts with Apache2, open /etc/apache2/httpd.conf again and un-comment the following line by removing the # symbol (around line 461):

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

Now, open /private/etc/apache2/extra/httpd-vhosts.conf and make the following edits:

Make sure that NameVirtualHost is un-commented (around line 24):

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

...and then add virtual hosts for each of your sites (go to 
System Preferences -> Sharing Panel -> Web Sharing to get the IP address 
to use for localhost — in my case it’s 10.0.1.195):

Listen 8081
<VirtualHost *:8081>
  DocumentRoot /Users/[your user account]/Sites/[your project’s directoy]
  ServerName 10.0.1.195:8081 
</VirtualHost>

You can assign port numbers as you wish, of course, but I started at 8081 to keep things in close logical relationship to localhost.

Now when you go into Windows via parallels you will be able to find the project you’re working on by entering http://10.0.1.195:8081 into your browser’s url bar. The only downside is that you have enter the IP and port rather than something easier to remember like ‘myproject’, but, hey, that’s what bookmarks are for.