OS X Leopard local web development with Apache and PHP5

Posted on November 20th, 2007 by Jeff

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.

	Options ExecCGI FollowSymLinks
	AllowOverride all
	Allow from all

# A basic virtual host config

	ServerName yoursite
	DocumentRoot /Users/username/Sites/yoursite

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.



	ServerName yoursite2
	DocumentRoot /Users/username/Sites/yoursite2

and add the corresponding record to the /etc/hosts file.


127.0.0.1       yoursite2
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

3 Comments so far

1 | Bust Out Solutions » Blog Archive » Local web development on Mac OS X

[...] See an updated posting for local web development on OS X Leopard [...]

Posted at 3:42 am on November 20th, 2007
2 | rushda » Blog Archive » OS X Leopard local web development with Apache and PHP

[...] check the full story here [...]

Posted at 10:53 am on November 20th, 2007
3 | GrirtyFortipt

The good convenient site is made.

Posted at 9:50 am on April 19th, 2008

Write a new comment


Comment: