Setup a local PHP enabled Web Server on your Mac

On Windows I’ve always used XAMPP for all the small PHP scripts I used to write. I was about to download it’s Mac version today but I thought, “Snow Leopard is basically *nix. I’m sure they have some PHP!”. I was right. The procedure to setup a basic web server with PHP support is something that Apple may not be proud of but it’s fairly simple for someone who knows his way around a terminal. Read ahead for the steps.


  1. Goto “System Preferences->Sharing” and enable Web Sharing. That’s it! The URL is http://localhost/~<yourusername> or http://<Your IP Address>/~<yourusername> as shown in the Web Sharing info screen. This links to the files stored in “Sites” folder of your home directory (“/Users/<yourusername>/Sites”).


  1. Enable PHP Module loading. Open the Terminal, edit "/private/etc/apache2/httpd.conf" using your favorite editor using sudo. Look for the line "#LoadModule php5_moduleĀ  libexec/apache2/" and un-comment it by removing the # from the beginning.
  2. Create a php.ini file. cd to “/etc/” in the Terminal and type "sudo cp php.ini.default php.ini". This will create a php.ini based on the latest PHP 5.3. If you want to use 5.2 use “php.ini.default-5.2-previous” instead.
  3. Restart Web Server. Goto the “Web Sharing” preference, disable it and then re-enable it. Clearly, itĀ  restarts the Apache Web Server to load the PHP module.
  4. Test your PHP script!

If you have any simple questions, ask away! Complex questions, please Google. Thanks to Caffeine Lack for the tip!

Liked this article? Like us on Facebook!


Read previous post:
iPhone 4 working in India on MTNL & BSNL 3G

I got my iPhone 4 last week. I ordered a factory unlocked one from the UK apple store and got...