macOS Update: While these instructions still work, there are new posts for recent versions of macOS, the latest being Install Apache, PHP, and MySQL on macOS Mojave.
Mac LAMP development - MAMP summary MAMP is a great free tool for running Apache, MySQL, and PHP on the Mac OS X platform. If I wasn't a Mac Terminal command line user, or if I didn't need to use the CakePHP cake bake command, the MAMP installation might have been flawless. Install MySql on Mac OS X Download the MySql DMG file from MySql Download Website. Open the DMG file and install MySql server and Preference Pane for starting and stopping MySql server easily. Start the MySql server if its not running and optionally you can select the checkbox to automatically start MySql server on startup. I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each version of Mac OS X having some minor difference. This post serves as much for my own record as to outline how to install Apache, MySQL, and PHP for a local development environment on Mac OS X.
PHP Update: Mac OS X Yosemite comes pre-installed with PHP version 5.5 which has reached its end of life. After you complete this post, you should upgrade PHP on Mac OS X.
I recently upgraded to Mac OS X Yosemite. It seems Mac OS X Yosemite makes my original post on installing Apache, PHP, and MySQL on Mac OS X obsolete. Specifically, Yosemite includes Apache 2.4. This post is a complete update for installing Apache, PHP, and MySQL on Mac OS X Yosemite.
A reminder that Mac OS X runs atop UNIX. So most UNIX software installs easily on Mac OS X. Furthermore, Apache and PHP come packaged with Mac OS X. To create a local web server, all you need to do is enable them and install MySQL.
I am aware of the web server software available for Mac OS X, notably MAMP. These get you started quickly. But they forego the learning experience and, as most developers report, can become difficult to manage.
First, open the Terminal app and switch to the root user to avoid permission issues while running these commands.
Verify It works! by accessing http://localhost
First, make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.
Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.
Uncomment the following line (remove #):
Restart Apache:
You can verify PHP is enabled by creating a phpinfo() page in your DocumentRoot.
The default DocumentRoot for Mac OS X Yosemite is /Library/WebServer/Documents. You can verify this from your Apache configuration.
Now create the phpinfo() page in your DocumentRoot:
Verify PHP by accessing http://localhost/phpinfo.php
Note: If you are upgrading MySQL you should skip this section and instead read this.
The README suggests creating aliases for mysql and mysqladmin. However there are other commands that are helpful such as mysqldump. Instead, I updated my path to include /usr/local/mysql/bin.
Note: You will need to open a new Terminal window or run the command above for your path to update.
I also run mysql_secure_installation. While this isn't necessary, it's good practice.
You need to ensure PHP and MySQL can communicate with one another. There are several options to do so. I do the following:
The default configuration for Apache 2.4 on Mac OS X seemed pretty lean. For example, common modules like mod_rewrite were disabled. You may consider enabling this now to avoid forgetting they are disabled in the future.
I edited my Apache Configuration:
I uncommented the following lines (remove #):
Note: Previous version of Mac OS X ran Apache 2.2. If you upgraded OS X and previously configured Apache, you may want to read more about upgrading to to Apache 2.4 from Apache 2.2.
If you develop multiple projects and would like each to have a unique url, you can configure Apache VirtualHosts for Mac OS X.

If you would like to install PHPMyAdmin, return to my original post on installing Apache, PHP, and MySQL on Mac OS X.
Find this interesting? Let's continue the conversation on Twitter.
Note: This post assumes you followed installing Apache, PHP, and MySQL on Mac OS X Mojave and have since upgraded to macOS Catalina. If you did not follow the original post, you should follow installing Apache, PHP, and MySQL on macOS Catalina.

When Mac OS X upgrades it overwrites previous configuration files. However, before doing so it will make backups. For Catalina the original versions may have a suffix of mojave or be copied to a backup folder on the Desktop. Most of the time, configuring your system after updating Mac OS X is simply a matter of comparing the new and old configurations.
This post will look at the differences in Apache, PHP, and MySQL between Mac OS X Mojave and macOS Catalina.
Mac OS X Mojave and macOS Catalina both come with Apache pre-installed. As noted above, your Apache configuration file is overwritten me when you upgrade to macOS Catalina.
There were a few differences in the configuration files. However, since both Mojave and Catalina run Apache 2.4, you could simply backup the configuration file from Catalina and overwrite it with your Mojave version.
However, I encourage you to stay up-to-date. As such, you should take the time to update Catalina's Apache configuration. First, create a backup and compare the two configuration files for differences.
Now edit the Apache configuration. Feel free to use a different editor if you are not familiar with vi.
Uncomment the following line (remove #):
In addition, uncomment or add any lines you noticed from the diff above that may be needed. For example, I uncommented the following lines:
Finally, I cleaned up some of the backups that were created during the macOS Catalina upgrade. This will help avoid confusion in the future.
Note: These files were not changed between versions. However, if you changed them, you should compare the files before running the commands.
Restart Apache:
Mac OS X Mojave came with PHP version 7.1 pre-installed. This PHP version has reached its end of life. macOS Catalina comes with PHP 7.3 pre-installed. If you added any extensions to PHP you will need to recompile them.
Also, if you changed the core PHP INI file it will have been overwritten when upgrading to macOS Catalina. You can compare the two files by running the following command:
Note: Your original file may note be named something else. You can see which PHP core files exist by running ls /etc/php.ini*.
I would encourage you not to change the PHP INI file directly. Instead, you should overwrite PHP configurations in a custom PHP INI file. This will prevent Mac OS X upgrades from overwriting your PHP configuration in the future. To determine the right path to add your custom PHP INI, run the following command:
Note: It appears Catalina does not include the PHP Zip extension. This is a popular extension used by many packages. Once I determine a work around, I will post an update.
MySQL is not pre-installed with Mac OS X. It is something you downloaded when following the original post. As such, the macOS Catalina upgrade should not have changed your MySQL configuration.
Find this interesting? Let's continue the conversation on Twitter.