Install PHP on Mac OS X

Admin   PHP   494  2020-09-07 23:08:59

Mac users have the choice of installing either a binary or a source. Really, your OS X can go with Apache and PHP preinstalled. This could be an old architecture and it lacks many popular extensions.

However, if you want to install Apache + PHP + MySQL / PostgreSQL fast on your laptop, then this is the fastest way. All you need to do is edit your Apache configuration file and start the Web Server.

Follow these steps:

Open the Apache config file in a Text Editor as root.

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

Edit file. Uncomment the following lines:

Load Module php5_module
AddModule mod_php5.c
AddType application/x-httpd-php .php

You may want to uncomment the <Directory/home/ * /Sites> block or otherwise you tell Apache the directory to serve.

Restart WebServer.

sudo apachectl graceful

Open a Text Editor. Type <?php phpinfo (); ?>. Save this file in Document Root as info.php of the Web Server.

Start any web browser and browse this file. You should always use an HTTP Request ( or http://localhost/info.php or instead of a filename (/home/httpd/info.php) so that the file is parsed correctly.

You should observe a long information sheet about your PHP installation notice.