My previous posting regarding local web development on Mac OS X was geared towards those running OS X Tiger and Apache 1.3. The new Mac OS X Leopard comes with the 2.2 version of Apache, and with it some tweaks to the way things are set up.
PHP comes pre-installed, giving Marc Liyanage a lot more free time and making your life much nicer. First thing to do is to activate PHP5 by opening up the httpd.conf file.
sudo vi /etc/apache2/httpd.conf
To include PHP5, simply uncomment the following line:
# LoadModule php5_module libexec/apache2/libphp5.so
In order to develop multiple sites locally, use virtual hosts. I had trouble using the default httpd-vhosts.conf file, so I added my own sites.conf file. Add this line to the bottom of your httpd.conf file:
Include /etc/apache2/other/sites.conf
Next, create the actual conf file you just referred to.
vi /etc/apache2/other/sites.conf
Create a new virtual host for MySite by adding a record to the sites.conf file
# Enable named virtual hosts
NameVirtualHost *:80
# Override the default httpd.conf directives. Make sure to
# use 'Allow from all' to prevent 403 Forbidden message.
<Directory />
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
</Directory>
# A basic virtual host config
<VirtualHost *:80>
ServerName yoursite
DocumentRoot /Users/username/Sites/yoursite
</VirtualHost>
Edit the hosts file…
sudo vi /etc/hosts
… and add a line with your new site
127.0.0.1 yoursite
You should create a folder called “yoursite” in the default Sites folder. At this point you will need to restart Apache to pick up the changes.
sudo apachectl restart
You should now be able to view your site locally at http://yoursite/. In order to maintain multiple virtual hosts, simply add another record to your sites.conf file.
<VirtualHost *:80>
ServerName yoursite2
DocumentRoot /Users/username/Sites/yoursite2
</VirtualHost>
and add the corresponding record to the /etc/hosts file.
127.0.0.1 yoursite2


7 Comments
Bust Out Solutions » Blog Archive » Local web development on Mac OS X
—
[...] See an updated posting for local web development on OS X Leopard [...]
rushda » Blog Archive » OS X Leopard local web development with Apache and PHP
—
[...] check the full story here [...]
GrirtyFortipt
—
The good convenient site is made.
Adam
—
Thanks! This is just what I was looking for.
One issue I’m having is — when I run apachectl configtest, I get messages:
Syntax error on line 7 of /private/etc/apache2/other/sites.conf:
AllowOverride not allowed here
Might I be doing something wrong?
Jeff
—
Here is another great tutorial: http://tinyurl.com/yppamz
Frans-Jan Wind
—
This works perfect on my local machine. Thanks for that.
I’m using Parallels Desktops to test in the Windows environment. The new subdomain isn’t found (the old syntax did macname.local/project) How can I make this work from an other test machine?
Frans-Jan Wind
—
I’ve found a solution:
http://terminalapp.net/accessing-mac-virtual-hosts-from-a-parallels-vm/