Search:

Configuring a local Apache server under OS X 10.3 (Panther)

Please notice that there exist an updated version of this document for configuring Apache under OS X 10.7.

When editing PHP scripts, it is rather convenient to be able to "dry run" the code locally, without having to upload them onto your web host each time. On Apple OS X, the configuration of a local Apache server is rather simple, as the system is delivered with a pre-installed server which only has to be configured for your local needs.

In order to configure the local Apache server on OS X (in this example assuming that your user name on the system is 'hakkasberra', simply apply the following:

  1. Open System Preferences: System Preferences -> Sharing -> Services -> Personal Web Sharing
  2. In a terminal window (Xterm), move to the /etc/httpd/ directory and open httpd.conf in your favourite editor (say Emacs). (Most likely, you will need root privileges in order to edit this file.)
    
    dirac:~ hakkasberra$ cd /etc/httpd/
    dirac:/etc/httpd hakkasberra$ sudo emacs httpd.conf
    
    
  3. In httpd.conf, uncomment the following two lines:
    
    LoadModule php4_module
    AddModule mod_php4.c
    
    
  4. Make sure that 'AddType application/x-httpd-php .php' and 'AddType application/x-httpd-php-source .phps' (that is to say, the lines which determine which file suffixes will be recognized as PHP scripts by the Apache server) are uncommented in the following block:
    
    <IfModule mod_php4.c>
        # If php is turned on, we respect .php and .phps files.
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
    
        # Since most users will want index.php to work we
        # also automatically enable index.php
        <IfModule mod_dir.c>
            DirectoryIndex index.html index.php
        </IfModule>
    </IfModule>
    
    
  5. Comment out the lines related to DocumentRoot and change to the default file repository you wish to use instead:
    
    #
    # DocumentRoot: The directory out of which you will serve your
    # documents. By default, all requests are taken from this directory,
    # but symbolic links and aliases may be used to point to other
    # locations.
    #
    # DocumentRoot "/Library/WebServer/Documents"
    DocumentRoot "/Users/hakkasberra/Sites"
    
    #
    # This should be changed to whatever you set DocumentRoot to.
    #
    # <Directory "/Library/WebServer/Documents">'
    <Directory "/Users/hakkasberra/Sites">
    
    
  6. Restart the Apache server: Start System Preferences -> Sharing -> Services -> Personal Web Sharing Stop/Start
    Starting the local apache server
  7. Open a browser and open http://localhost/ to view the (X)HTML delivered by the local PHP parser, reading the contents located at /Users/hakkasberra/Sites/ on your disk.

Done!

Return to previous page

Leave a message

Your name:

Your email: (required)

Message:

Generated by ::emailform::

Last modified Wednesday 15 Feb 2023