Skip to content
TrySitePrice

OS X Mountain Lion 10.8 Set Apache and PHP Web-Server

Best/Tutorial

To set up an Apache and PHP web server on OS X Mountain Lion 10.8, follow these steps:

  1. Install the Apache web server:
    • Open Terminal.
    • Run the following command to start the Apache web server:

    $ sudo apachectl start

  2. Install PHP:
    • Download the PHP package from the official website.
    • Install the package using the following command:

    $ sudo installer -pkg php-5.x.x.pkg -target /

    Replace php-5.x.x.pkg with the name of the actual package you downloaded.

  3. Configure Apache to use PHP:
    • Open the Apache configuration file:

    $ sudo nano /etc/apache2/httpd.conf

    • Add the following line to the file:

    LoadModule php5_module libexec/apache2/libphp5.so

    • Find the DirectoryIndex line and add index.php as one of the options, like this:

    DirectoryIndex index.html index.php

    • Save the changes and exit the editor.
  4. Restart Apache to apply the changes:

    $ sudo apachectl restart

  5. Test your PHP installation:
    • Create a file named info.php in the document root directory (/Library/WebServer/Documents/ by default) with the following contents:

    <?php
    
    phpinfo();
    
    ?>

    • Open a web browser and navigate to http://localhost/info.php to see information about your PHP installation.

Your Apache and PHP web server is now set up and ready to use.