My steps of moving away from MAMP to stand-alone Apache, PHP and MySQL on OS X Mavericks.


First of all, it's more geeky, which is the most important. Secondary, running stand-alone Apache and MySQL servers feels closer to Linux environment. Which is also important as most of all websites are running on Linux servers. And finally, there is no reason to keep and maintain two copies of the same softrware on your computer.

Setting up Apache, PHP, MySQL


OS X comes with Apache already installed, so it's as simple as starting up the server.

Basic commands

# Start Apache
$ sudo apachectl start

# Stop Apache
$ sudo apachectl stop

# Restart Apache
$ sudo apachectl restart

# Test Apache
$ sudo apachectl -t

Start Apache, open a browser and go to http://localhost/. You should see It works!.

Web Root Directory

The default web root directory is /Library/WebServer/Documents/, that is where current http://localhost/ index file is stored.

Let's change it to the Sites directory which is located in the user level root. /Users/roman/Sites in my case.

Edit Apache configuration file /etc/apache2/httpd.conf:

# Line 170
DocumentRoot "/Users/roman/Sites"

# Line 197
<Directory "/Users/roman/Sites">

# Line 217: allow .htaccess files override default settings
AllowOverride All

# Line 131: run Apache as your user
User roman
Group staff

Transfer Apache configuration from MAMP

You could also move your custom Apache settings from /Applications/MAMP/conf/apache/httpd.conf to /etc/apache2/httpd.conf if needed.


Turn on PHP

Let's enable php5_module by editing Apache config httpd.conf:

# Uncomment line 118
LoadModule php5_module libexec/apache2/


# set up PHP configuration file by copying php.ini.default
$ sudo cp /etc/php.ini.default /etc/php.ini

# Line 211: allow short <? ?> php tags
short_open_tag = On

If you have any other custom PHP settings in your MAMP configuration, then copy them from /Applications/MAMP/bin/php/php5.3.6/conf/php.ini to the newly created /etc/php.ini.

Testing PHP

Create index.php in the Sites directory with the following code:

<? phpinfo(); ?>

Then restart Apache and open http://localhost/ in your browser. There should be PHP info data if everything is working properly.



There are a few ways to install MySQL on Mac. I've used Homebrew which is the easiest way for me.

# install
$ brew install mysql

# start the server
$ mysql.server start


# secure mysql installation by setting up 'root' user password and
# answering 'y' to all questions
$ mysql_secure_installation

# copy the default configuration file to /etc/my.cnf for your custom settings
$ sudo cp /usr/local/opt/mysql/my.cnf /etc/my.cnf

# there is an error with MySQL socket:
# MySQL puts the socket into /tmp folder when OS X is looking for it in /var/mysql/
# let's fix this by creating a symbolic link from /tmp/mysql.sock to /var/mysql/mysql.sock
$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

# restart the server
$ mysql.server restart

You will find out that MySQL server configured by default uses a lot (~500MB) of RAM. Let's fix this by changing some of the default options to reduce the memory usage (Reducing MySQL's memory usage on OS X Mavericks by Robby Russell).

Add the following to your MySQL config /etc/my.cnf and don't forget to restart the server to see the effect:

# add to '/etc/my.cnf'
max_connections = 10
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K

# restart mysql
$ mysql.server restart

And lastly, transfer your custom settings from MAMP /Applications/MAMP/conf/my.cnf to the new configuration file /etc/my.cnf.


Add to your ~/Sites/index.php and open http://localhost/ in a browser:

<? $con = mysqli_connect('localhost', 'root', '<root_password>');
// check connection
if (mysqli_connect_errno($con)) {
    echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
// ping server
if (mysqli_ping($con)) {
    echo 'MySQL connection is working!';
} else {
    echo 'Error: ' . mysqli_error($con);
mysqli_close($con); ?>

Virtual Hosts


Edit Apache config /etc/apache2/httpd.conf to enable virtual hosts:

# Uncomment line 478
Include /private/etc/apache2/extra/httpd-vhosts.conf


Next, let's set up the first virtual host. Add the following to /etc/apache2/extra/httpd-vhosts.conf:

# localhost
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /Users/roman/Sites/
# virtual host example
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /Users/roman/Sites/
    # I like to keep log files in the same directory as the website
    ErrorLog /Users/roman/Sites/
    CustomLog /Users/roman/Sites/ combined

Now, point to our local Apache server by adding the following to /etc/hosts:


# create the required directories for site files and logs
$ mkdir -p ~/Sites/
$ mkdir -p ~/Sites/

# create index.php for testing
$ nano ~/Sites/
<h1> virtual host works!</h1>
<? phpinfo(); ?>
# save the file by pressing ^X, Y, Enter

# restart Apache
$ sudo apachectl restart

Go to in you browser.

Transfer virtual hosts from MAMP

Follow the steps above to move your virtual hosts from /Applications/MAMP/vhosts/ to ~/Sites/. As well as the configurations from /Applications/MAMP/conf/apache2/extra/httpd-vhosts.conf to /etc/apache2/extra/httpd-vhosts.conf.