SEARCH References

HomeReferencesMac PHP

Run Apache and PHP on Mac OS X

Following the instructions in this article a tdevarticles.com I modified the httpd.conf file to enable Apache and PHP on Mac OS X:

The steps I followed on my OS X 10.3.5 installation.

  1. Start Apache Web Server
    1. Open the “System Preferences" Control panel.
    2. Click on "Sharing".
    3. Check the "Personal Web Sharing" box. This starts up Web sharing which starts the Apache Web Server.
    4. Open a web browser and type http://localhost in the address box.
      1. If Apache is working the browser should display:
        1. "If you can see this, it means that the installation of the Apache Web server software on this system was successful. You may now add content to this directory and replace this page."
  2. Enable PHP by "uncommenting" four lines in the httpd.conf "Apache HTTP Server Configuration" file.
    1. Start the Terminal.app located in the "/Applications/Utilities/" directory.
      1. in Terminal, change the directory to the "httpd" directory using the command:
        1. cd /etc/httpd
      2. in Terminal, start up the text editor named "Pico" and edit the httpd.conf file using the command:
        1. sudo pico httpd.conf
          1. (You'll be asked for the root password)
      3. Locate the 4 lines:
        1. #LoadModule php4_module
        2. #AddModule mod_php4.c
        3. #AddType application/x-httpd-php .php
        4. #AddType application/x-httpd-php-source .phps
        5. (This is a long script - much scrolling will be needed)
      4. Very carefully remove only the pound signs (#) from the beginning of these four lines. Warning: Only remove the pound signs!! Don't move the lines of code around!! You have been warned!
      5. The changed lines should look like this:
        1. LoadModule php4_module
        2. AddModule mod_php4.c
        3. AddType application/x-httpd-php .php
        4. AddType application/x-httpd-php-source .phps
      6. Save the file by hitting the CTRL + X keys and hit the Y key to say “YES”.
  3. For this change to take effect the Apache Web Server must be restarted.
    1. Stop Apache Web Server
      1. Open the “System Preferences" Control panel.
      2. Click on "Sharing".
      3. Uncheck the "Personal Web Sharing" box (or click the Stop button).
      4. Check the "Personal Web Sharing" box (or click the Start button).

To check that all is working:

<html>
  <head>
   <title>phpinfo</title>
  </head>
  <body>

   <?php phpinfo(); ?>

  </body>
 </html>

http://localhost/~yourname/phpinfo.php

To access your personal web pages:

Put them in the sites folder at the root level of your user account. Create one if needed. Open a web browser and type http://localhost/~yourusername/ in the address box.

Tags: Macintosh