10 August 2008 ~ 0 Comments

Serving PHP with Mac OS X




In my last Post, we fired up the Apache server, respectively v 1.3 in Tiger & v 2.2 in Leopard. By now putting up Hello World! static page is just blink of an eye effort. And we can also start and stop our server via Terminal. Nice! From here we take on to start the native PHP available in Max OS X. Tiger Supports PHP 4.4.7 and Leopard supports PHP 5.2.4. To start PHP we have to make changes in the Apache configuration file.

Apache Httpd:

In Tiger, you can edit the Httpd.conf a.k.a Apache Configuration file through Terminal. This configuration file controls almost everything about the web server. Be sure to make copy of the file before altering it. The location of the httpd.conf file is /etc/httpd. You can reach the location by entering the following command:

cd /etc/httpd/

On requesting directory listing “ls”, httpd.conf file is listed among other config files.

In Leopard, the location of the file is changed to /etc/apache2/httpd.conf, which you can reach by entering:

cd /etc/apache2/

Now lets make respective changes in the file in each OS and start PHP. Type in Tiger:

sudo pico /etc/httpd/httpd.conf

Editing Httpd.conf

Terminal in Mac OS X Leopard

Pico is our editor through which we will be editing the file to Uncomment 2 enteries. Its text based but very powerful. As you have guessed it, we have to use Root privileges to edit the file. Now we need to locate the following files:

# LoadModule php4_module libexec/httpd/libphp4.so
# AddModule mod_php4.c

Easy would be to use the Where command in Pico by entering the following key combination “Control + W”. Now enter “Loadmodule php4″ and you’ll be taken to the exact location. Now again perform Where for “AddModule” and uncomment the function call. Now enter “Control + X” for exit, press “Y” to save the file and exit from pico.

In Leopard, we just need to uncomment one entry by performing similart task with pico:

LoadModule php5_module

Testing PHP

To test if our editing effort has been successful, we will invoke the PHP Info function to see the results. Using any text editor, save the file in /user/<username>/sites directory with the name test.php. Enter the following code in the file:

<?php phpinfo() ?>

Now enter the URL in your favorite browser:

http://localhost/~<username>/test.php (e.g. http://localhost/~munirsalman/test.php)

The result should be similar to the following in Tiger.

php.ini http response

A very good resource on PHP on mac, PHPMac

Reblog this post [with Zemanta]

Related Posts


Leave a Reply