August 21, 2012

Installing LAMP Stack on OSX 10.8 Mountain Lion


This is a follow-up to my previous article on installing a LAMP Stack on 10.7 Lion and explains the steps that you need to get 10.8 Mountain Lion up and running for LAMP development.  (Linux, Apache, MySQL and PHP in case you don’t already know).  Mountain Lion comes pre-installed with Apache and PHP 5.3.6 so you only need to enable those features.  MySQL is the only component that you have to install.

1.Turn on Apache

Unlike previous versions there is no longer a “Web Sharing” option in System Preferences.  Apache is still installed by default but there is no UI to control it.  You have two options:

a) Install a web sharing preferences pane plugin so you can start/stop the server with a GUI.  Once installed you can start Apache by going to System Preferences.  There will be a new icon for Web Sharing that allows you to start/stop Apache.

b)  Open terminal and run the following if you want Apache to start automatically when your computer boots:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Once running you now can use the following Terminal commands to start/stop/restart Apache when necessary:

sudo apachectl start
sudo apachectl stop
sudo apachectl restart

2. Edit /private/etc/apache2/httpd.conf

To enable PHP uncomment (remove the number sign at the beginning of) the line:

#LoadModule php5_module libexec/apache2/

(optional) you can re-map the server root to your home website directory by editing DocumentRoot:

DocumentRoot “/Users/username/Sites”

If you wish to use .htaccess files then look a bit further down AllowOverride and set it to “All” like so:

Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all

3. Create the file /private/etc/apache2/users/[your-username].conf

If you re-mapped your server root to ~/Sites then you will need to create a user-specific configuration file to allow Apache access to your home directory.  The name of the file must match your home directory name with the following contents (replace [your-username] with your home directory name)

<Directory "/Users/[your-username]/Sites/">
 Options Indexes MultiViews FollowSymLinks
 AllowOverride All
 Order allow,deny
 Allow from all

4. Copy /private/etc/php.ini.default to /private/etc/php.ini

OSX includes a default php.ini file that you can use but you must rename or copy it first.  If you don’t do this then PHP will still run but it will just be using the default initialization settings with no way for you to override them.

Edit these settings in php.ini (some of these settings will not come into play until they are installed)

display_errors = On
mysql.default_socket = /tmp/mysql.sock
date.timezone = ‘America/Chicago’
include_path = “.:/usr/lib/php/pear”

sendmail_path = /usr/sbin/sendmail -t -i

Note that all instances of “/var/mysql/mysql.sock” are replaced with “/tmp/mysql.sock”

5. (Optional) Install PEAR

If you use the PEAR libraries you can install them using the included phar file like so:

sudo php /usr/lib/php/install-pear-nozlib.phar
sudo pear config-set php_ini /private/etc/php.ini
sudo pecl config-set php_ini /private/etc/php.ini
sudo pear upgrade-all

6.  Install MySQL

This doesn’t really require instructions, simply download the latest MySQL from  I installed the 64 bit version.

7. (Optional) Install Apache Plugins

If you use encryption you may need to install mcrypt.  Instructions have been provided by Remons TechNotes.  You most likely need to have Xcode installed with command line utilities enabled.  Also prior to running the mcrypt instructions on that page, I ran the following to install homebrew and autoconf:

ruby <(curl -fsSkL
brew install autoconf

8. (Optional) Install Zend Debugger

If you use the Zend debugger you can install that using these instructions.

9. (Optional) Enable mail delivery

Edit the file /etc/hostconfig and add the following line:


Edit the file /etc/postfix/ and update or add the following line (using your own domain name):

myhostname =

Calls to sendmail can be monitored with the command:

tail -f /var/log/mail.log

Custom Installs

These are here for my selfish purposes, install if you so choose!

sudo pear install --alldeps -f Spreadsheet_Excel_Writer

One Comment on “Installing LAMP Stack on OSX 10.8 Mountain Lion

March 1, 2013 at 3:24 pm

Really useful post. One suggestion. Don’t forget to restart apache after making these changes. Seems obvious, but is a missing step for those, like me, who slavishly followed these instructions.

sudo apachectl restart


Leave a Reply

Your email address will not be published. Required fields are marked *