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.
Apache
- 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”).
PHP
- 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/libphp5.so"
and un-comment it by removing the # from the beginning. - 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. - 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.
- Test your PHP script!
If you have any simple questions, ask away! Complex questions, please Google. Thanks to Caffeine Lack for the tip!