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 :)

Start a Apache Webserver on Mac

Knowing that the OS X on Mac is built on Linux, I was expecting some web server to be installed by default on Mac book air too. And I was not disappointed to see that Apache server is indeed available.

It is so simple to turn it on and here are the steps for the same:

Click on System preferences: (This is based on Mac OS X 10.7.5 – MacBook Air).


Click on Sharing

Check Web Sharing

And start the start the computer’s website as well as the personal website by clicking on the respective buttons

And what you will see is that an IP address is allotted for your machine and 2 folders are created – 1 within your personal folders and the other at the computer hard disk level.

You should see this screen after you have started both:

A site is created under your personal folder, which can be tested by typing in http://[you ip as shown above]/~[personalfolder]

You will see a default web page that is installed.

Also, you will find another website root available at
/Library/WebServer/Documents.

This is accessible from your web browser by typing just your ip address as shown above or ‘http://localhost/’. You will see a page like this appear.
If that is so, you have enabled your apache web server on mac OS correctly.
Wish you all the best with web site creation!!