Based on various forum postings and conversations in the community, it seems like some folks are running Magento 2 development instances on OS X via a PHP environment that doesn't use the built-in Apache/PHP combo and instead uses packages from brew to get a FastCGI PHP environment up and running with nginx and/or apache.

Does anyone have a list of commands and configuration instructions for getting Magento 2 up and running on OS X using brew packages OR some other means for running PHP in a FastCGI environment on OS X? I'm not looking for Docker or Vagrant -- I want to run PHP natively on OS X and dont want to use mod_php.

  • Not sure if it's helpful, but I was never a Fan of brew so I always installed PHP to use natively from php-osx.liip.ch Commented Jul 6, 2017 at 6:42
  • @mhauri If you have instructions for getting the php-fpm from the liip packages running a full answer would be great. Commented Jul 6, 2017 at 7:47

5 Answers 5


Apache + PHP-FPM with Homebrew

Step 0: Before we start

brew update
brew tap homebrew/services

Step 1: Apache

1.- Let's make sure to stop the build-in apache service

sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
sudo apachectl stop

2.- Install apache2.4

brew install homebrew/apache/httpd24 --with-privileged-ports

This step will take a while since it has to compile Apache.

3.- Verify it was installed correctly, you should see a message similar to:

To have launchd start homebrew/apache/httpd24 now and restart at startup: sudo brew services start homebrew/apache/httpd24

Let's run the command:

sudo brew services start homebrew/apache/httpd24

Verify everything is running by loading, http://localhost after which we should see the It Works! message It Works

Step 2: PHP-FPM

1.- Let's continue by installing PHP

brew install -v homebrew/php/php70

2.- Start PHP-FPM, the beauty about homebrew/php is that it installs PHP and FPM, so we only need to run the following:

brew services start homebrew/php/php70

For now let's use the default configuration, if we need to change it the configuration is located at /usr/local/etc/php/7.0/

Step 3: Configuration

1.- Open the Apache configuration:

vim /usr/local/etc/apache2/2.4/httpd.conf

2.- Uncomment the following lines:

LoadModule proxy_module libexec/mod_proxy.so
LoadModule proxy_fcgi_module libexec/mod_proxy_fcgi.so

3.- Setup the proxy config for PHP-FPM:

<IfModule proxy_module>
  ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://$1

Typically I would setup this per vhost to point it to the right directory

4.- Finally let's create a phpinfo() page inside /usr/local/var/www/htdocs/ and confirm everything is working by loading the test page: We have php

There are a few more tweaks and turns, but this should get you up and running directly on OSX.

For a more detailed walkthrough of the configuration we use check the configuration(vhost, php pools, etc) on this vagrant box:


  • I had to a brew install homebrew/apache/httpd24 --with-privileged-ports instead of a brew install httpd24 --with-privileged-ports. Does that match your real world experience? Commented Aug 16, 2017 at 23:40
  • @AlanStorm I followed the same procedure but some how .htaccess is creating an issue while loading Magento's index.php. It does not let the page open however if I remove .htaccess from root folder then atleast Magento opens which again gets distorted for reasons. Could you please guide me on this? Commented Oct 17, 2017 at 14:59
  1. Follow one of the many Mac + Nginx + PHP-FPM + Mysql setup tutorials like this (be sure to use brew services):
  2. brew install php70-intl php70-mcrypt
  3. In /usr/local/etc/nginx/nginx.conf inside http define new upstream

    upstream fastcgi_backend {

    9000 is the default port, but I'd recommend to add PHP version number as a last two digits, to be able to use few versions of PHP at the same time i.e. for M1. You can modify FPM port in file /usr/local/etc/php/7.0/php-fpm.d/www.conf - listen = and then restart PHP using brew services restart php70.

  4. Copy nginx.conf.sample form M2 repository and save as /usr/local/etc/nginx/magento2.conf. This config will use fastcgi_backend defined in the previous step.

  5. Setup vhosts and domains
    server {
      listen 80;
      server_name magento2.dev;
      set $MAGE_ROOT /path/to/m2/project;
      set $MAGE_MODE developer;
      include /usr/local/etc/nginx/magento2.conf;
  6. Restart Nginx
  • that first gist asks you to tap homebrew/dupes, which is depreciated and will (if I recall) no longer give you the formulae you need. Warning: homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated Commented Jul 5, 2017 at 22:37
  • Looks like dupes are now part of the core, so you can just ignore it and stick with brew tap homebrew/php only.
    – igloczek
    Commented Jul 5, 2017 at 23:06
  • Thank you. This is exactly what I needed. Followed Magento setup but for Ubuntu and line 'listen = /run/php-fpm/php-fpm.sock' was causing me sooo much problems. All I needed is not to add that just to use: listen = and change it to listen = if I wanted to use multi PHP version. Spent ages looking for a solutions.
    – iva
    Commented Apr 25, 2018 at 10:43

Step 1 : Stop the existing apache service and install Apache thru Brew.

$ sudo apachectl stop
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
$ brew install httpd24 --with-privileged-ports --with-http2

This step takes a little while as it builds Apache from source. Upon completion you should see a message like:

/usr/local/Cellar/httpd24/2.4.23_2: 212 files, 4.4M, built in 1 minute 60 seconds

Step 2 : This is important because you will need that path in the next step.

$ sudo cp -v /usr/local/Cellar/httpd24/2.4.23_2/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons

$ sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist

$ sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist

$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist

Now we have installed Homebrew's Apache, and configured it to auto-start with a privileged account.

Server can be reached http://localhost

Step 3 : Apache Configuration

Configuration file Path


if you want to change the configuration , you should make it here

Note : we should now enable mod_rewrite which is commented out by default.

LoadModule rewrite_module libexec/mod_rewrite.so

For Magento installation mod_rewrite should be enable in this configuration file.

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
AllowOverride All

Step 4 : PHP installation

we can get a full list of available options to include by typing

$ brew install php71 --with-httpd24

We can choose which version we are going to use.

For configure the tweak configuration setting of PHP for our needs for example , memory_limit, date.timezone, display_errors...etc/apache2/2


Step 5 : Apache PHP Setup

Now we have successfully installed your PHP versions, but we need to tell Apache to use them . we need to edit apache configuration file


by modifying the php path.

LoadModule php7_module    /usr/local/opt/php71/libexec/apache2/libphp7.so

Handle the php requests in apache by the following configuration needs to be modified

<IfModule dir_module>
    DirectoryIndex index.php index.html

<FilesMatch \.php$>
    SetHandler application/x-httpd-php

Save the configuration file and restart the apache.

$ sudo apachectl -k restart

Step 6 : Validating PHP

create an php file info.php in document root directory

Content of info.php is

<?php phpinfo(); ?>

Step 6 : Check the dependency extension of PHP for Magento in php.ini file.

Required PHP extensions for Magento2:

gd, ImageMagick 6.3.7 (or later) or both
PHP 7 only:

Then you can proceed with Magento installation.

  1. Install PHP 7:

    brew install php70-intl php70-mcrypt php70-xdebug
  2. You can then use Laravel Valet to automate the Nginx+PHP-FPM install: https://laravel.com/docs/5.4/valet

    composer global require laravel/valet
    valet install
  3. Create a project directory if you don't already have one (can be named whatever you want)

    mkdir ~/projects
  4. Tell Laravel Valet that you store your projects there

    cd ~/projects
    valet park
  5. At time of this post the version of Laravel Valet that contains the Magento2 driver has not yet been released (it has been merged, but not yet released via a tag). To use it you can either:

    • Install Laravel Valet via the dev-master branch:

      composer global require laravel/valet:dev-master`
    • or download the driver and use it as a local Valet driver:

      curl https://github.com/laravel/valet/raw/master/cli/drivers/Magento2ValetDriver.php -o ~/.valet/Drivers/Magento2ValetDriver.php

You can now browse to http://[projectname].dev/ to see your local project (where [projectname] corresponds to a directory in ~/projects. eg:

~/projects/my-super-awesome-client => my-super-awesome-client.dev

FULL DISCLOSURE: I am one of the authors of the Magento2 driver for Laravel Valet

  • It's possible that I'm being quite dense, but these steps seem incomplete (e.g. valet linking, nginx m2 setup...). Am I overthinking this?
    – benmarks
    Commented Jul 15, 2017 at 14:18
  • The valet park takes care of the linking. As long as you "park" in your projects directory and each project is a sub directory containing an M2 install, there is nothing more to do. The Magento2 driver for valet takes care of everything so that Valet knows how to server an M2 site (so no additional nginx config needed). Yes, it really is that simple. Valet was built to remove the pain of setting up Laravel sites. They made it possible to use it for non-Laravel projects as well so everyone wins Commented Jul 16, 2017 at 17:20

You can use Valet+ instead configuring it on your own, b/c it's automated bare-metal Mac OS solution based on Homebrew packages. Setup steps and other things are described on Github.

Blog post about it - Introducing Valet+, Blazing fast PHP development environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.