Whatterz


Setting up PHP on Mac OSX 10.6 (Snow Leopard)

by Simon. Average Reading Time: about a minute.

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:

  1. 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.

  2. Restart Apache via the command line:
    sudo apachectl restart -t

    The -t is used to run a syntax check on the Apache file, to ensure you haven’t broken anything.

  3. Locate the php.ini.default file in the /etc/ directory and rename it to simply php.ini by running the following commands:
    cd /etc
    sudo cp php.ini.default php.ini
    sudo chmod 666 php.ini
  4. Create a file in the web server’s document root, in this case an index.php file, 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.

This article has been tagged

, , , , , , , , ,

Other articles I recommend

Configuring Your First Local Apache Website

Apache is controlled by a series of configuration files but the one we will be dealing with here is httpd.conf. This file contains instructions on how Apache should run. Several companies offer GUI-based Apache front-ends, but it’s easier to edit the configuration files by hand.

Configuring ColdFusion 8 with Apache

After installing ColdFusion 8 and Apache successfully you may still see an “HTTP 500 Internal Server Error” when navigating to a ColdFusion page. All is not lost, you simply need to configure, or check the configuration of Apache. Apache requires very little post installation modification, but it is always good practice to check the httpd.conf file to ensure that the ColdFusion “install” scripts did what they were supposed to do.

Configuring PHP with Apache on Windows Vista

Installing PHP with Apache on Windows Vista is a relatively simple task until you try an configure the settings in php.ini. Problems can occur and stem from the fact that when you install PHP and edit the php.ini file, you need to not only be logged in as Administrator, but run the installer and Notepad text editor as Administrator. The php.ini file also needs to be located in the Windows directory.

  • JayBee

    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)

  • enzodad

    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,

  • Yenrak

    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

  • Yenrak

    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/timez

    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