To set up an Apache and PHP web server on OS X Mountain Lion 10.8, follow these steps:
- Install the Apache web server:
- Open Terminal.
- Run the following command to start the Apache web server:
$ sudo apachectl start
- 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. - 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 addindex.php
as one of the options, like this:
DirectoryIndex index.html index.php
- Save the changes and exit the editor.
- Restart Apache to apply the changes:
$ sudo apachectl restart
- Test your PHP installation:
- Create a file named
info.php
in the document root directory (/Library/WebServer/Documents/
by default) with the following contents:
phpinfo();
- Open a web browser and navigate to
http://localhost/info.php
to see information about your PHP installation.
- Create a file named
Your Apache and PHP web server is now set up and ready to use.