February 11, 2008 in Development | 3 Comments
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
You also may prefer to use one of the 3rd party distributions of PHP, such as MAMP, XAMPP and Marc Liyanage.
Keep Up to Date
We will come up with more and more interesting topics over the time, make sure to keep yourself up to date using RSS Feeds or Email Subscription.
3 Comments
Mojo
You can't save httpd.conf without sudo.
Reply | Back to Top
K
Mojo is correct. Use this command (in the terminal) to open the file in TextEdit so that it can be modified: sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /private/etc/apache2/httpd.conf
Reply | Back to Top
e
mmm what happened to part 2...?
Reply | Back to Top
Post a Comment
You can't be anonymous
C'mon, I'm sure you've got something to say.