How to setup, install Apache, PHP and MySQL on Mac OS?

Apache server is installed by default on Mac. Access the configuration settings for Apache by going to

$ cd /etc/apache2/
$ vi httpd.conf

To enable php, edit httpd.conf and uncomment the line
#LoadModule php5_module libexec/apache2/

Uncomment other lines that you may want to load in your system. As you are enabling PHP in your system, you may want to change the DirectoryIndex to
DirectoryIndex index.php index.html

Default group/user settings inside Apache on Mac is _www:_www

If you would like to have a custom directory for web root, you can edit the DocumentRoot path
DocumentRoot “/Library/WebServer/Documents”
<Directory “/Library/WebServer/Documents”>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all

To setup multiple sites on the system, you may want to turn on virtual hosts. Uncomment the below line to activate vhosts file
# Inclue /private/etc/apache2/extra/httpd-vhosts.conf

Edit httpd-vhosts to add virtual hosts
$ sudo vi /etc/apache2/extra/httpd-vhosts.conf

Enable PHP on APACHE

To enable php, go to /etc/
$ cd /etc/
$ sudo cp php.ini.default php.ini
$ sudo chmod +w php.ini

We need to restart the server for the configuration changes to take effect
$ sudo apachectl -k [restart | start | stop | reload]

Create a file index.html under /Library/WebServer/Documents and add some dummy content to it
$ touch /Library/WebServer/Documents/index.html

Access the webserver by going to

If there are any problems in accessing the web server, check the system log
$ tail -20 /var/log/system.log

PHP with MySQL

First thing that we need to do is to download the MySQL .dmg file from their website and install it on Mac. Look for three file install (MySQL application)
MySQLstartupitem.pkg (start MySQL when Mac boots)
MySQLPrefPane (system preference control over Mac)

To make PHP talk to MySQL, edit /etc/php.ini and set the following values

mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

To go to MySQL

$ cd /usr/local/mysql/bin/
$ ./mysql -u root

You need to edit ~/.bash_profile to set the PATH settings of MySQL if you do not typing in the entire path to the MySQL commands.

$ vi ~/.bash_profile
# Add the below line
export PATH=”/usr/local/mysql/bin:$PATH”
$ source ~/.bash_profile
$ mysql -u root (to access mysql from command line anywhere on the system)

If the configuration for Apache is messed up and you want to restore the configuration settings to its original state, you can grab the copy of the files under /etc/apache2/original


Written by kurinchilamp

Website: http://

Leave a Reply

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

Kurinchi Calendar
July 2013
« Jun   Dec »