Setting up PHP on Mac OSX 10.6 (Snow Leopard)
Posted on Wednesday, 31st March 2010 in Development by Simon
Since Apple launched Mac OS X 10.5 (Leopard), PHP has been installed by default, albeit disabled. Here is a quick run through of what you need to do to get it up and running:
- Enable the PHP5 module in Apache:
LoadModule php5_module libexec/apache2/libphp5.so
This will normally involve simply removing the hash symbol (#) at the beginning of the line.
- Restart Apache via the command line:
sudo apachectl restart -t
The
-tis used to run a syntax check on the Apache file, to ensure you haven’t broken anything. - Locate the
php.ini.defaultfile in the/etc/directory and rename it to simplyphp.iniby running the following commands:cd /etc sudo cp php.ini.default php.ini sudo chmod 666 php.ini
- Create a file in the web server’s document root, in this case an
index.phpfile, with the following text included:<?php phpinfo() ?>
When you browse to that file, it will display information regarding your PHP installation. (Be sure to remove this after use and certainly don’t include it in a production environment.)
That is all you need to do. Easy huh?
As a point to note, if you need to make changes to either the http.conf file or php.ini, you will need administrative access and will need to restart the Apache server for the chances to take effect.
Hi,
thanks for this excellent step by step guide.
I would add that the new location of the apache config file is under /etc/apache2/httpd.conf
(I was looking for the old /etc/httpd.conf at first)
Um nothing you said did anything, i mean when i nav to that page all i get is the <?php phpinfo crap no information at all just text.
i did all the commands you said and nothing,,,,,,why cant i get it to display PHP information.. PHP is saposed to be really easy to get up and running yet i cant get it to work s i can learn it,
So, why did you not put any directories in this article?
It appears Apple has 3 places where its Apache will look for an index.
~/Sites
/Library/WebServer/Documents
and a third I can’t determine.
Each one is used based on whether or not you have internet connectivity.
I feel I should mention to anyone who comes here looking to configure PHP on Snow Leopards Apache that the file you need to modify to enable PHP is called the httpd.conf file. This is located in the following directory
/etc/apache2/httpd.conf
Secondly, it should be mentioned that if anyone plans on doing anything with times then the timezone needs to be set in the /etc/php.ini file
open /etc/php.ini
search for ‘date.timezone’. You should see this section of code
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone =
delete the ‘;’ from the beginning of the line ‘date.timezone’ and then choose your timezone from one of the following listed here: http://php.net/manual/en/timezones.php
Since, I’m in the central timezone, I would choose America/Chicago. So my date section would be:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone = “America/Chicago”
Then restart Apache with sudo apachectl restart