Bookmark and Share

PHP on Mac OS X 10.5 Leopard

Posted: Saturday, May 2nd, 2009 at 12:25 pmUpdated: Sunday, May 3rd, 2009 at 8:53 am

On the previous page, we’ve discussed the easy way to enable MAMP stack on your Mac. On this page, we’ll discuss utilizing the built-in PHP and Apache that already comes with Mac OS X.

The default way

Apple has bundled PHP 5 with Mac OS X 10.5 Leopard. At the time of this writing, the bundled PHP version is 5.2.6. It has built-in support for MySQL database. For most PHP programs, I think the built-in bundled version works just fine.

To enable the default Apache in Mac OS X Leopard, open system preferences then click on Sharing then make sure web sharing is checked.

The default Apache is configured to serve local users website from Sites folder under current user’s home directory. Also by default, PHP is not enabled in Apache configuration. To enable it, open terminal console by clicking Go -> Utilities on Finder. Then double click Terminal. Once you’re on terminal, you need to edit httpd.conf to enable PHP.

user:~ user$ sudo vi /etc/apache2/httpd.conf

Provide your password if asked. Then search for the line below and delete the hash (#) sign to uncomment it. On my version of httpd.conf, the line below is on line 115. Yours may be different, but I think it should be around the same neighborhood.

#LoadModule php5_module        libexec/apache2/

Once it is uncommented, restart apache by either issuing the command below, or by unchecking and then checking Web sharing on preferences window.

user:~ user$ sudo /usr/sbin/apachectl restart

The last thing is to test if Apache can correctly handle PHP. The easiest way to do this is to create a file and save it under Sites folder on your home directory. Here’s how I do it:

user:~ user$ echo “<?php phpinfo(); ?>” > ~/Sites/test_php.php

Then you can either click on “Your personal website” link under Sharing window or type http://localhost/~/test_php.php. If you see the screen similar to the one below, then you’re all set.


Note that my screen shot above has a slightly different version of PHP and Apache as I’ve upgraded my default one. I’m discussing it in my other article on how to compile MAMP stack from scratch and replacing the default Apache & PHP installation. For now, happy programming on your MAMP platform.

Pages: 1 2

Leave a Reply

Time limit is exhausted. Please reload the CAPTCHA.