9/02/2012

How to Run PHP Scripts in Mac OS X 10.8

It is generally hard to configure server side application for first time. I know there are a lot of sources about this topic but i just want to share my experience about this topic.

1)Install PHP and Apache server:
After activating port:
$>install php5
Then to activate server:
$>launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist

or

You can just download and install MAMP which is a bundle that contains PHP,Apache and MySQL

After intallation, when you write 127.0.0.1(or localhost), you should see :

It works.


2)Changing path:
In IIS wwwroot is the folder that IIS looks as default. In Apache, this folder is /Library/WebServer/Documents

If you want to change this default path,you need to find httpd.conf file and open it via a text-editor which allows modification. 
httpd.conf is located in /etc/apache2. You may not be able to access etc directly. So you can just open it via terminal. Instead of text-edit, I used pico editor which allows direct modification of config files in mac.
$>sudo pico httpd.conf
After opening the conf file, you need to replace default path. 

3)Allowing php files:
httpd.conf file also contains informtion about allowed file formats. php is commented, so you should uncomment it. 
LoadModule php5_module modules/libphp5.so

4)After changing httpd.conf, you need to restart Apache server:
$>sudo apachectl restart

Sources:
http://www.phpied.com/installing-php-and-apache-on-mac-osx-that-was-pretty-easy/
http://www.codingforums.com/archive/index.php/t-82735.html
http://foundationphp.com/tutorials/php_leopard.php
http://www.cis.uab.edu/courses/cs401/pico.htm
http://smartwebdeveloper.com/mac/httpd-conf-location-mac


No comments:

Post a Comment