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


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

After intallation, when you write 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


No comments:

Post a Comment