My Android Blog

To view my posts on Android you can visit my Android Blog

Search This Blog

Wednesday, September 11, 2013

How to install/enable PHP on Mac?


Once Apache web server is enabled, you can start the below mentioned steps to enable PHP:

You need to be able to manipulate hidden files for the next steps. In order to view hidden files follow the 10th tip in my earlier article with some basic tips on Mac usage.

Step 1: open the httpd.conf file in HD/private/etc/apache2/httpd.conf.

Step 2: this file is root locked. So, you need to change permissions to be able to edit it.  (you could use the chmod command as a super user or do it through the ‘get  Info’ window in the finder as shown:


 Step 3: Uncomment the PHP line in the conf file by removing # at the beginning of the line for php5_module and save the file.

Step  4: go to /private/etc folder and make a copy of the php.ini.default file and name it as php.default.  You could do this through the finder window or the terminal
If you are using the terminal, use the following commands:

Cd /private/etc
Sudo cp php.ini.default php.ini

Step 5: Restart the web server by going to system preference -> sharing - >  Web Sharing (as described in my previous article)
From the terminal if you want to restart apache, here is the command:
sudo apachectl restart.

Step 6: Now create a simple test file by just tying
<?php phpinfo() ?> and save it as ‘phpinfo.php’ file in your root web folder i.e. /Library/WebServer/Documents.

Step 7: In a browser, type http://localhost/phpinfo.php and the following kind of page should show up depending on which version of PHP is installed on your machine:

PHP is enabled on your machine !! Happy PHP coding :)

1 comment:

  1. nice and complete information of php mac installation thanks for sharing it was really helpful for me

    ReplyDelete