I will write series of articles about Web Development Using PHP, this is the part one of those, about activating and installing PHP first. Mac OS X Leopard comes with Apache 2.2 bundle with PHP 5 by default. Beside they still provide option to switch back to PHP4 and also you can actually activate back Apache 1.3 web server. But for PHP, we need to activate it with few steps, which we will cover on this tutorial. We can start the apache web server use the System Preferences » Sharing » Just check the Web Server option.
Once it start, you can go to http://127.0.0.1/~username/ for your own personal website which located at /Users/username/Sites. And for the root website, which you can access from http://127.0.0.1/ and it located at
The configuration file for apache2 located at /private/etc/apache2/httpd.conf, we will need to edit the file to activate PHP5, by default PHP5 module is not activated. Open the file by clicking on your finder then press Command-Shift-G then key in /private/etc/apache2/ then open up httpd.conf using your TextEdit application.
Search for the line with:
#LoadModule php5_module libexec/apache2/libphp5.so
Then uncomment the line to become:
LoadModule php5_module libexec/apache2/libphp5.so
Save first, then go to System Preferences » Sharing and restart the web server again to get PHP up and running. To test whether the PHP its ON, lets create a file called: index.php inside ~/Sites/ folder. Below is the content of index.php:
You can see this page, mean you already success activate PHP
Another way to do this is to type the following in the Terminal application:
sudo apachectl start
You will be prompted to enter your root password. After that, your apache server should now be running. If you need to restart the server from the terminal, you can type this:
sudo apachectl restart