Home > Mac OSX > Enabling PHP and Apache in Leopard

Enabling PHP and Apache in Leopard


Mac OS X 10.5 (Leopard) comes with both Apache 2.2.6 and PHP 5.2.4 preinstalled, but they’re not enabled by default. The following instructions should help you get up and running.

  1. Open BBEdit or TextWrangler (a free, cut-down version of BBEdit available from www.barebones.com). From the File menu, select Open Hidden. In the Open dialog box, select All Files from the Enable drop-down menu. Then navigate to Macintosh HD:private:etc:apache2:httpd.conf, and click Open.
  2. This opens the main configuration file for Apache 2.2.6. It’s a system file, so you need to unlock it by clicking the icon of a pencil with a line through it at the top-left of the toolbar, as shown in the following screenshot:
    Apache configuration file in TextWrangler
  3. You will be told that the document is owned by “root”, and be asked to confirm that you want to unlock it. Click Unlock. This removes the line through the pencil, and readies the file for editing. Normally, when editing system files, it’s a good idea to make a backup. However, it’s not necessary in this case, because backup copies of all the Apache configuration files are in the original subfolder of the Apache2 folder.
  4. Scroll down until you find the code shown on line 114 in the following screenshot (although the line number is likely to be the same in your version, it’s the code that’s important, not which line it’s on):
    Load PHP module command
  5. Position your cursor at the beginning of that line, and remove the hash or pound sign (#). It should now look like this:
    LoadModule php5_module      libexec/apache2/libphp5.so
    This enables PHP 5 on your computer.
  6. Save the file. Because it’s owned by “root”, you will be prompted to enter your Mac password. That takes care of the basic configuration. In theory, you could now start Apache and PHP would be up and running. However, the default installation doesn’t use the PHP configuration file php.ini. You need to need to make a copy of a file called php.ini.default, and edit it.
  7. Unfortunately, you can’t open php.ini.default in BBEdit or TextWrangler and save it with a different name. You need to go under the hood of OS X by opening Terminal in the Applications:Utilities folder. Similar to the Command Prompt in Windows, Terminal gives you direct access to the underlying operating system on a Mac.
  8. With Terminal open, type the following series of commands, each followed by Return:
    cd /private/etc
    sudo cp php.ini.default php.ini

    This moves you into the private:etc folder, and then copies php.ini.default to php.ini in the same folder, using the sudo command. You need to use sudo because it’s a system file. Enter your Mac administrator password when prompted. Terminal should now look something like this:
    Copying php.ini.default in Terminal
  9. Open php.ini in BBEdit or TextWrangler using Open Hidden in the same way as with http.conf. You should find php.ini in Macintosh HD:private:etc. Click the icon of a pencil with a line through it to enable editing.
  10. How you edit php.ini is mainly a question of preference, but the most important change is to a command called error_reporting. The default setting (it should be on line 305) looks like this:
    error_reporting = E_ALL & ~E_NOTICE
    Change it to this:
    error_reporting = E_ALL
    This ensures that PHP reports all errors. Although no one likes error messages, it’s vital to eliminate any errors (even seemingly minor ones) before deploying scripts on a live web server.
    NOTE: There are several lines that look similar. Make sure that you edit the line that does NOT begin with a semicolon. A semicolon at the beginning of a line in php.ini indicates a comment, which is ignored by the server.
  11. Save php.ini.
  12. You can now start Apache by going to System Preferences. Click Sharing in Internet & Network. Then place a checkmark in Web Sharing. When Apache starts up, System Preferences should display Web Sharing: On.
  13. Click the link under Your computer’s website. This should launch Safari and display an Apache web page.
  14. Create a page called test.php, and type in the following code:
    <?php phpinfo(); ?>
    Save it in Macintosh HD:Library:WebServer:Documents.
  15. Load the following URL into your browser:
    http://localhost/test.php
    If you see the PHP configuration screen, you’re up and running!

NOTE: If you did an upgrade install of Leopard, you cannot view pages stored in your personal Sites folder, because the necessary file(s) won’t have been copied to the correct folder for Apache 2. To copy the file(s), open Terminal and type the following commands, both followed by Return:
cd /private/etc/httpd/users
ls

You should see at least one file that uses your Mac username followed by .conf. For example, on my computer, it’s called davidpowers.conf. You need to copy this file for each user to a folder where Apache 2 can find it. Type the following command, using the name of the file on your computer instead of davidpowers.conf:
sudo cp davidpowers.conf /private/etc/Apache2/users

If there are several .conf files to copy, you can use the following command instead:
sudo cp *.conf /private/etc/Apache2/users

However, if you have previously installed the Mac PHP package from Marc Liyanage, do not copy entropy-php.conf.

For this (or any other) change to take effect, go to Sharing in System Preferences, deselect Web Sharing, and then reselect it. This restarts Apache and implements any changes made to the Apache or PHP configuration.

My thanks to Dan Brown for the additional information he provided for these instructions.

Categories: Mac OSX Tags:
  1. December 31, 2012 at 7:56 pm

    Somebody necessarily help to make significantly posts I would state.
    This is the very first time I frequented your web page and up to now?
    I surprised with the research you made to create this particular submit extraordinary.
    Wonderful activity!

    • Budi Setiyawan
      January 26, 2013 at 3:43 pm

      Thank You,,,

  2. March 11, 2013 at 4:12 am

    This is very interesting, You are a very professional blogger.
    I’ve joined your rss feed and look ahead to in search of more of your excellent post. Additionally, I’ve
    shared your site in my social networks

    • Budi Setiyawan
      April 8, 2013 at 3:36 am

      Thank You Very Much…🙂

  3. March 14, 2013 at 4:29 pm

    I was curious if you ever thought of changing the layout
    of your website? Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people could connect with
    it better. Youve got an awful lot of text for only having 1 or two
    images. Maybe you could space it out better?

    • Budi Setiyawan
      April 8, 2013 at 3:44 am

      okey,, thanks..🙂

  4. August 17, 2014 at 3:26 am

    With havin so much content do you ever run into any issues of plagorism or copyright violation? My blog has
    a lot of unique content I’ve either written myself or outsourced but
    it appears a lot of it is popping it up all over the web without
    my authorization. Do you know any techniques to
    help prevent content from being stolen? I’d definitely
    appreciate it.

  5. April 2, 2015 at 10:55 am

    This post gives clear idea in favor of the new users of blogging, that genuinely how to do blogging.

  6. May 16, 2015 at 9:14 am

    I visit each day a few web pages and sites
    to read content, but this blog provides feature based writing.

  7. January 13, 2016 at 4:56 am

    I’m more than happy to find this site. I need to to thank you for
    your time for this wonderful read!! I definitely enjoyed every bit
    of it and i also have you book-marked to look at new stuff
    on your web site.

  8. February 29, 2016 at 8:46 pm

    Since the admin of this site is working, no question very quickly it will be famous, due to its feature contents.

  9. March 24, 2016 at 10:44 am

    Hey I am soo delighted I fpund your blog page, I really foud you by accident, while I wwas searching on Askjeeve for something else,
    Regardless I am here now aand would just
    like to say cheers for a tremendous polst and a all round entertaining blog (I also
    love the theme/design), I don’t have time to look ver itt all at the minute but I hae
    book-marked it and also added in your RSS feeds, so when I have time I
    wkll be back to read more, Please doo keep up the awesome work.

  10. May 13, 2016 at 7:04 am

    Howdy! This is my first comment here so I just wanted to give a quick shout out and tell
    you I really enjoy reading through your posts.
    Can you recommend any other blogs/websites/forums that deal with the same subjects?
    Appreciate it!

  11. June 4, 2016 at 3:42 am

    WOW just what I was searching for. Came here by searching for miami
    real estate

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: