Mac OS X comes with Apache,PHP pre-installed but is not enabled by default. Just when you get on to your new Mac OS X you definitely want to enable these. The following steps should help you enable PHP over Apache and you can start rolling.
Enable PHP module in httpd.conf
- We first need to enable PHP module in Apache’s configuration file i.e. httpd.conf. This configuration file,httpd.conf, is stored in /etc/apache2 folder which is hidden by default.
- You can directly jump into this folder by clicking on Go > Go To Folder and type /etc/apache2 .
- From this folder open httpd.conf in your favorite text editor. I am using Text Wrangler for this example.
- Since this file requires root permission to edit, you can unlock this before editing. Alternatively, if you are not using TextWrangler, then you can open this file in OS X’s default editor called Text Edit, using this command, sudo open -t /etc/apache2/httpd.conf
- In the config file, search for the line which says “#LoadModule php5_module libexec/apache2/libphp5.so” . Notice, that it has a hash sign (#) at the start, this means that it is commented. Just uncomment this line, by removing the hash sign (#) from the start and save the file. For my httpd.conf the line no. is 111, you can search for string “php5” to quickly search this line.
- With this step we have enabled the PHP5 module on Apache server.
Creating the default php.ini
Next we need to create a default php.ini file for PHP to run successfully. A default php.ini exists in the /etc folder with the name php.ini.default . You first need to duplicate this file and simply save it with the name php.ini . If you are an advanced user or need to make any changes to the default php configuration, you can do it now or later in this very file.
Starting the Apache services
Now that we have the Apache and PHP settings right on place, it’s time we start the server and see if everything worked great !
Goto System Preferences and Click Sharing. In the sharing tab, tick the Web Sharing option to turn it on. On the right pane, you will see a private IP , from where you can open your website. Apparently, you can also open it by using http://localhost/ , cause that is there in hosts file by default.
Open http://localhost/ in the browser and you should see Apache’s default message “It Works !” as shown below –
Now go ahead and create some awesome stuff for the web using your Mac. Hope that helps.