I’m a Mac/OS X user and I like Homebrew. So when I wanted to install WordPress locally for the first time in years, I didn’t want to install some all-in-one MAMP package that might be difficult to administer and uninstall. Here’s what I did to get WordPress running.
Basically, I followed this guide: https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew. Here’s a summary of the steps:
- Install MySQL via Homebrew.
- Configure MySQL, in particular my.cnf.
- Add MySQL to brew services so that it starts on boot via launchd.
- Remove OS X’s built-in Apache from launchd’s list.
- Add the homebrew-dupes Homebrew repository to satisfy Apache’s zlib dependency.
- Install Apache via Homebrew (using the brewed OpenSSL and event MPM support options).
- Install the mod_fastcgi module for Apache via Homebrew (using the brewed Apache option).
- Remove any references to mod_fastcgi in Apache’s httpd.conf.
- Add logic to Apache’s httpd.conf to forward PHP requests to PHP-FHM via mod_fastcgi (a long command that you can copy and paste into the terminal is provided in the guide in order to do this).
- Make a ~/Sites directory to host the WordPress installation as well as “logs” and (optionally) “ssl” subdirectories.
- OPTIONAL: Populate a ~/Sites/httpd-vhosts.conf file in order to allow us to access our WordPress installs via URL’s like “projectname.dev”. (A template for the vhosts file is provided in the guide. Note, I skipped this and simply use localhost.)
- OPTIONAL: Create an SSL certificate to allow local encrypted connections.
- Add Apache to brew services so that it starts on boot via launchd. (NB: using the default httpd.conf, Apache will be listening on ports 8080 and 8443, since listening on ports 80 and 443 would require root.)
- OPTIONAL: Add a firewall rule to forward ports 80 and 443 to ports 8080 and 8443, respectively, so that you don’t have to specify the port in your web browser. (The guide has a template for this.)
- Install PHP via Homebrew.
- Set timezone and other settings for PHP in PHP.ini.
- Fix a pear and pecl permissions problem with chmod.
- OPTIONAL: Install the Opcache extension via Homebrew to speed up PHP.
- OPTIONAL: Bump up the Opcache memory limit.
- Add PHP to brew services so that it starts on boot via launchd.
- OPTIONAL: Install DNSMasq via Homebrew (for accessing Apache via URL’s).
- OPTIONAL: Configure DNSMasq.
- OPTIONAL: Add DNSMasq to brew services so that it starts on boot via launchd.
- OPTIONAL: Configure OS X to use localhost for URL requests that end in .dev.
It all worked perfectly for me. I left out all the steps that I marked as “optional” except for those relating to Opcache. The other optional steps had to do with SSL and setting up Apache so that you can access your WordPress installation via a URL like “http://projectname.dev” instead of “http://localhost:8080”. I didn’t think that all the extra complexity was worth it.
Note that in this install, Apache runs on port 8080, which can conflict with all manner of web server stacks. I discovered this when trying to fire up a Node server only to have it raise out an error about the port being taken (and I found out that Apache was listening on the port by running:
lsof -i tcp:8080
To stop Apache, simply run:
brew services start httpd22