An Apache, MySQL, PHP stack is really easy to setup on a Mac. MAMP is a very easy solution to achieve this. Apache can be replaced with the lightweight Nginx server and an NMP stack can be created, but may take a little more time to set it up.

Following configuration is tested with Mac OS X v10.10 Yosemite

Before we start, make sure that you install Homebrew – dubbed as the missing package manager for OS X. Its a CLI tool and is used in a way similar to YUM or APT. You can install,  update packages easily via the command line. It uses Ruby and git under the hood. Install it using

More details about Homebrew.

After you install Homebrew, run the below commands

Install Nginx

Install Nginx using the below commands

Now start Nginx

This should start Nginx and will use the default port 8080. Try to access http://localhost:8080/ and you should see the welcome page. Nginx configuration can be changed to use a different port and we will explore that shortly.

Install MySQL

Use the below commands to install MySQL.

After installing MySQL, set the root password and other options using

 Install PHP-FPM

The default PHP in Homebrew is different from the one that we need. We will tap a special channel to obtain this formula.

Install phpMyAdmin

Before installing phpMyAdmin, check the value of $PHP_AUTOCONF by echoing it.

If PHP_AUTOCONF is not setup, check if autoconf is installed.

If that does not return a value, install autoconf.

Find the value of autoconf path and set the PHP_AUTOCONF variable, then reload bash profile.

Now, install phpMyAdmin


Now, lets configure the installed components and make sure they work as expected.

To make the services run at startup, provide a link to the .plist files of the components in ~/Library/LaunchAgents. Mac will use the information in the plist files to launch the services at startup.




Using the commands above, start Nginx(if not already started), MySQL and PHP-FPM

To make sure that  PHP-FPM started correctly, use the command below.

The final piece is to add virtual host configurations to access phpMyAdmin and your other websites using Nginx.

Nginx config file is usually found in the location below

Create 3 directories in the location to hold the configuration, virtual host definitions and the log files.

Now create the configuration to use PHP-FPM for the php pages in conf.d directory. Create a file named php in conf.d folder

Add the following contents to the file.

Lets create a virtual host for phpMyAdmin that uses the config file that we just created. We will create the definition in sites-enabled directory and lets name the file phpmyadmin(or any name of your choice).

The contents of the file should be similar to the one below

The listen port is set as 8060. You can change that to use your preferred port.

Lets create another virtual host for your php web application. I use Sites folder under my home directory as the root folder.

Create another file named webapp in sites-enabled directory and use the below content

I used 8070 as the port here and the root folder is set as the Sites directory.

Lets create a test page named index.php in the webapp root folder

Set the contents as below.

Now, configure nginx.conf to include all virtual hosts and set log folder.

Edit nginx.conf in any text editor and make the highlighted changes.

Reload Nginx configuration.

Now access the phpMyAdmin url – http://localhost:8060

You should see the login screen and should be able to login with the root password that you set.

Access your webapp – http://localhost:8070

You should see the PHP configuration(output of phpinfo()).