Now it’s time to continue with setting up Apache and PHP. If you’re coming here through search engine then you probably want to check our previous posts on [intlink id=”how-to-create-a-wordpress-development-environment-on-mac-os-x-snow-leopard” type=”post”]how to install and configure WordPress on Mac OS X Snow Leopard[/intlink].
Fortunately Snow Leopard comes with the latest PHP version (version 5.3.0 at the time of this post) so that’s covered. Please note that PHP is not by default turned on in Snow Leopard. To make sure that you’re configuring everything correctly it’s best to make Web Sharing active (System Preferences » Sharing » Web Sharing). Once that’s done we’re free to go ahead and configure setup PHP and configure Apache.
Lets setup PHP first
In order to do so copy php.ini.default to php.ini
cp /private/etc/php.ini.default /private/etc/php.ini. This way we’ll keep the original php.ini.default just in the right place for any future reference. If you know what you’re doing and need any special stuff then go ahead and modify the php.ini as you feel fit.
Configure Apache web server
If you have the default Apache installation (and I assume you do) then you find your httpd.conf under
/private/etc/apache2/httpd.conf. I expect that you have the technical ability of a software developer familiar with Linux commands. Now edit the httpd.conf file using root access with the sudo command and your favorite text editor. I personally prefer vim if I need to get something done on Terminal but you can also use TextMate or any other text editor.
Enable PHP5 module
Search for the PHP module (
/php5. Then it would be good idea to remove the comment from the following line in order to enable PHP to run with Apache:
# LoadModule php5_module. The line should look like that after you’re done:
Enable mod_rewrite for permalinks
If you like beautiful URLs (permalinks) then make sure that you have mod_rewrite Apache module enabled. It should look something like that in your httpd.conf:
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Change the user Apache runs as
I prefer not to use Mac OS X Snow Leopards default location for sites (the Sites folder in your Home folder). On my case I have a folder called “Development” in my Home folder that has all the development projects organized in there. So in this case it’s also good idea to run Apache under your own user in development environment (which your Snow Leopard installation most probably is). In your Apache configuration you’ll find that both user and group that Apache is run with is _www.
Find and change
to (replace Martin with your own users name)
Final check for virtual hosts
Make sure that you have these two lines at the end of your httpd.conf. Otherwise you’re most probably going to find out soon that your virtual hosts simply doesn’t work.
Now lets start (
sudo apachectl start) or restart (
sudo apachectl restart) the Apache web server and test if PHP is running by creating a file in your Web directory containing a call to the function
Final push – setup virtual hosts for your sites
At the time of writing this post I have 3 WordPress themes in development plus quite a few that I’m still maintaining. This kind of setup could easily become a mess and I really wouldn’t like that, now would I. Fortunately there’s a fix: create a virtual host for each WordPress installation.
Custom hostnames for your virtual server
I’m using a simple convention for my WordPress projects – projectname.wordpress.dev. Fortunately this keeps all WordPress installations in one clean convention which is also easy to deploy to production server (we’ll get to that later on).
To create your hostname just open up the hosts file with your text editor:
Write something like that at the end of the hosts file.
Done. You now have a hostname for your virtual host named perfectline.wordpress.dev which you can also access by www.perfectline.wordpress.dev if you like.
Configure a virtual host
Now that we are sure that we have PHP turned on, Apache working properly and even hostnames in place it’s time to create the actual virtual host that will be serving content for your WordPress installation.
First you need to create the necessary folders. In my case I’ve created Development folder where all my projects live plus one level to specify the type of the project (WordPress, Ruby, etc) and an actual WordPress project name:
Create a new configuration file for your WordPress related virtual hosts:
Paste these lines into the newly created wordpress.conf. You need to change the file paths as you’ve set up the folders on your own system.
DocumentRoot "/Volumes/Macintosh HD/Users/Martin/Development/Wordpress"
<directory "/Volumes/Macintosh HD/Users/Martin/Development/Wordpress">
Options Indexes FollowSymLinks
Allow from all
DocumentRoot "/Volumes/Macintosh HD/Users/Martin/Development/Wordpress/default"
<directory "/Volumes/Macintosh HD/Users/Martin/Development/Wordpress/default">
Options Indexes FollowSymLinks
Allow from all
Now it’s time to restart Apache for one more time and we are set. Enjoy your newly installed WordPress development platform.