Using Apache and PHP on Snow Leopard
If you are a Mac user and a web developer, probably you would like to transform your Mac in a perfect instrument for your work, by installing Apache and PHP. This simple guide will help you to do that.
First of all, in Mac OS X PHP and the Apache Web Server have been already installed on your machine without your knowledge, so you don’t have to download nothing. The only things to do are to enable them.
Apache Web Server: to start Apache Web Server, you must go into the “System Preferences Control panel located on the “Apple Menu”. Click on the Icon labeled “Sharing”. Then locate the tab labeled “File & Web”. You will want to click the button labeled “Start” in the “Web Sharing ” section. This starts up Web sharing which starts the Apache Web Server.
Apache Web Server is now running. So, start up your web browser and type in the url field “http://localhost”. If everything is okay, your browser will display “It works!”. If so, Apache is running.
Since Mac OS X is a multi-user system, every person has their own account and with that brings it’s own set of web pages. To access your personal web pages you must type in the browser address “http://localhost/~yourname/”. If you don’t know how to type the “~” character, just press ALT+5. Obviously, “yourname” is your account name.
Your personal web pages are located in your account name directory under “Users”: /Users/yourname/Sites/
PHP: Now it’s time to enable PHP scripting.
First of all, you have to configure http.conf file, the Apache HTTP configuration file. Your file is located in /private/etc/apache2/ directory but you can’t gain access there so easy. A way to do that is open a terminal application (go to spotlight e type “terminal”).
In the terminal windows just type this set of commands:
cd /private/etc/apache2
sudo cp httpd.conf httpd.conf.old (make a backup copy of httpd.conf file)
now, type your admin password. So, continue by typing:
sudo pico httpd.conf
This command will open simple text editor (pico) where you are able to modify httpd.conf file. Now, you just have to locate the row where is written
‘#LoadModule php5_module libexec/apache2/libphp.so
and remove the # char. After that, presse CRTL-X and type Y to save the file.
This is not the end. You have to do another thing. Also in you terminal window, type:
cd /etc
to enter in etc directory. Here, there are two files called php.ini.defaultand php.ini.default-5.2-previous. These two files are the ini files for PHP interpreter, respectively 5.3 and old but always good 5.2 version.
You just have to rename one of these two file in php.ini (you just have to choose what PHP version you would use) by typing:
sudo cp php.ini.default php.ini
for example. By this way, you also leave a backup copy of that file. If always’s gone well, PHP should be enabled. You can try this by creating a file called phpinfo.php, located in your web site directory. Its content should be the following:
<?php phpinfo(); ?>
If everything it’s ok, by typing in your web browser
http://localhost/phpinfo.php
it should appear a table with many information about PHP.