UsingMac.com

Mac Tricks and Tips, Wallpapers and Applications for Mac Users

Web Development PHP (Part 1)

Advertisements

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.

Start Web Server

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.

Location of httpd.conf

Location of httpd.conf

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:

phpinfo

You can see this page, mean you already success activate PHP

php info

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.

Categories: Development
Tags: PHP

Subscribe to RSS Leave a Comment (3)

Related Entries

Some articles taken from our resource base, tightly related to current article, to empower you with more knowledge on tweaking the most out of your Mac.

3 Comments

Mojo

You can't save httpd.conf without sudo.

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

e

mmm what happened to part 2...?

Leave a Comment