Install PHP on Mac OS X with Apache Web Server

Mac users have the opportunity to choose either a binary or a source installation. Actually,  OS X may came up with Apache and PHP installed by default. This is more likely to be an old build, and in that case that may lack many of the less common extensions.

So if you want to set up Apache, PHP and MySQL or PostgreSQL in your machine, this is easiest way to do. You need to edit your Apache Configuration file and turn on the Web Server. That is it!

Follow these steps:


  •  In your Text editor open Apache config file as root.



sudo open -a TextEdit /etc/httpd/httpd.conf



  • Edit the file and uncomment the following lines:



Load Module php5_module

AddModule mod_php5.c

AddType application/x-httpd-php .php



– You might also want to uncomment the <Directory /home/*/Sites> block or otherwise point out Apache which directory to server from.

  • Restart the Web server



sudo apachectl graceful



Now lets test if PHP is working or not.

For that open a text editor and type


<?php phpinfo(); ?>


Save this file in your Web server’s document root directory as “info.php”.


Open Web browser and type the file. You must always use an HTTP request ( or http://localhost/info.php or http://ip-address/info.php) rather than a filename (/home/httpd/info.php) for the file to be parsed correctly.

You should see a table of information about your new PHP installation message. If this is then Congratulations!

Was this article helpful?

Related Articles

Leave A Comment?