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

I am using Apple OS X Mountain Lion 10.8.4 on my Macbook pro. For my school project I need to write an app in PHP 5 and Apache. However, I am unable to find the Web Sharing option from the Sharing panel in System Preferences. How do I install Apache and PHP5 in OS X version 10.8.4? How do I enable HTTPD and test my web app?

Tutorial details
Difficulty level Advanced
Root privileges Yes
Requirements OS X 10.8.x+/Terminal
Est. reading time 15m
Apple removed the web-sharing option from the Sharing panel in System Preferences in OS X version 10.8.x. But worry not, Apple still ships Apache+PHP5 and it is disabled by default for security reasons. In this tutorial, you will learn how to enable and run Apache server with PHP 5.

Configuration files

  1. Apache configuration file – /etc/apache2/httpd.conf
  2. PHP 5 configuration file – /etc/php.ini

Finding default Apache DocumentRoot

Open the Terminal and type the following command:

grep --color DocumentRoot /etc/apache2/httpd.conf


grep --color '^DocumentRoot' /etc/apache2/httpd.conf

Sample outputs:

DocumentRoot "/Library/WebServer/Documents"

You need to store or create php/html/images/js/css app files at DocumentRoot i.e. /Library/WebServer/Documents directory.

How do I start / stop / restart Apache server?

Type the following command to start / stop / restart apache web-server in OS X:

sudo apachectl start
sudo apachectl stop
sudo apachectl restart
sudo apachectl graceful

Test your setup

Fire a browser and type url:
Sample outputs:

Fig.01: Running Apache for the first time

Fig.01: Running Apache for the first time

How do I change the default index.html?

Type the following command to create or edit the index.html file:
sudo vi /Library/WebServer/Documents/index.html
Sample code:

	<title>My first html page</title>
<h1>Hi, User</h2>
<p>This is a test web-page. It was created on OS X 10.8 Mountain Lion using the following:</p>
	<li>Vim text editor</li>
	<li>Apache 2.x</li>
	<li>PHP 5.x</li>
	<small>&copy; 2013 nixCraft.</small>

Save and close the file. Fire a browser and type url:
Sample outputs:

Fig.02: Updated index.html file

Fig.02: Updated index.html file

Configure and Turn on PHP 5 support for Apache

Edit the file /etc/apache2/httpd.conf
sudo vi /etc/apache2/httpd.conf
OR better try vi/vim syntax to open file and go to line called php5_module:
sudo vi +/php5_module /etc/apache2/httpd.conf
Find and make sure the following line is uncommented:

LoadModule php5_module libexec/apache2/libphp5.so

Sample outputs:

Fig.03: Enabling php5

Fig.03: Enabling php5

Type the following command to restart apache web-server in OS X:
sudo apachectl -k restart
sudo apachectl restart
Create a test php script as follows:
sudo vi /Library/WebServer/Documents/phpinfo.php
Add the following code:

 //Display the configuration info, line, php.ini location, build date, Web Server, System, Version and more.

Type the following url:
Sample outputs:

Fig.04: Testing PHP 5 in OS X v10.8.x

Fig.04: Testing PHP 5 in OS X v10.8.x

How do I start/reload Apache on boot?

Make sure Apache+PHP5 get reloaded when you reboot the system:
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

And, there you have it, the Apache and PHP 5 installed, configured and working correctly on the latest version of Mac OS X 10.8.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • mudfly Aug 25, 2013 @ 17:09

    The better option is to install a virtualization product and run your development code there. I would check out virtualbox and vagrant.

  • shanky Nov 29, 2013 @ 15:11

    Thank You very much for sharing this Info …. Works perfectly ….

  • Manuel Jan 5, 2014 @ 18:15

    Hi, I have been struggling for a while trying to configure my MAMP, I’ve work with Linux before and I manage to configure my LAMP pretty well. But MAC is ginving me a hard time. What I’ve could do so far is starting the apache serve although i dont know if the apache server I started is the one that i am seeing on my browser, that because when i go to localhost i see the It Works! message, but if i change the index.html in /Library/WebSever/Documents/ and reload the browser or open another browser and search the address localhost, I am still getting the same It Works message and not the one i’d change. I have try different browsers, clearing cache, incognito windows. I getting crazy here. I would appreciate some help

  • Michael Apr 24, 2014 @ 3:35

    Followed your tutorial exactly as written.
    However, when I run the url http://localhost/phpinfo.php all that displays is:

    Seems for some reason either Apache and/or my localhost are not executing the php code but just displaying the contents????

    Is a chmod required??
    Have thrashed a bit on this with no luck.

    Any thoughts???
    I am running Mac OS X 10.8.5 on a MacBook Pro.
    I am using Google Chrome, Safari, and Firefox as browsers for testing.


    • Michael Apr 24, 2014 @ 3:39

      Ok got it to work. So no reply is necessary.

  • Darren Aug 10, 2014 @ 3:25

    Hey there,
    This worked well. There are a bunch of instructions out there for using PHP + Apache on Mac OS X with their default install libraries (or XCode or whatever installs it), and they all seem dated.

    This one worked perfectly. Very easy.


  • Shawn Jul 22, 2015 @ 19:10

    Perfect tutorial!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum