# Mac OS X LEMP Configuration [This Gist](https://gist.github.com/petemcw/9265670) is a collection of configuration files that can be used to easily setup a [Homebrew](http://brew.sh/)-based LEMP stack on Mac OS X. Files in this repository are numbered and named for ordering purposes only. At the top of each file is a section of metadata that denote what component the file belongs to and the default name & location of the file. Feel free to implement it however you want. **Note: some configuration files have hard-coded paths to my user directory -- fix it for your setup** ## Setup Before any of this will work you'll need to have both Xcode Command Line tools and [Homebrew](http://brew.sh/) installed. Here are a few shortcuts to get you started: ```bash xcode-select --install /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` ## Nginx Files numbered `02` through `12` are [Nginx](http://nginx.org/) configuration files. If you haven't already, install via Homebrew: ```bash brew install nginx ``` ### Running on Port 80 To run Nginx on as your primary web server on port 80, the configuration files need to be owned and run as the user `root`. I have found it easiest to use the system's `LaunchAgents` directory rather than the one in my user's folder -- in fact, it may be required. ```bash sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchAgents sudo chown root:wheel /Library/LaunchAgents/*.plist ``` ## PHP Files numbered `13` through `15` are [PHP-FPM](http://php-fpm.org/) configuration files. If you haven't already, install via Homebrew: ```bash brew tap homebrew/php brew install php71 --with-fpm --without-apache --with-homebrew-curl --with-homebrew-openssl --without-snmp brew install php71-intl brew install php71-mcrypt brew install php71-opcache brew install php71-xdebug ``` ### Change PHP Versions As a developer you may find that you need to change between versions of PHP. Homebrew makes this process easy! The basic steps are to `brew unlink` the current version of PHP and link another installed version. ```bash brew unlink php71 brew link php56 ``` ## MySQL Files numbered `16` through `18` are [MySQL](http://www.percona.com/software/percona-server) configuration files. I personally use Percona Server as my flavor of MySQL. If you haven't already, install via Homebrew: ```bash brew install percona-server ``` Before you start the MySQL service, create the configuration directory and place the configuration files: ```bash mkdir -p ~/.my.cnf.d/ ``` **Note:** if you have trouble getting MySQL to start, you probably need to remove the default `ib_logfile` and `ibdata` files in `/usr/local/var/mysql`. ## dnsmasq Files numbered `19` through `20` are [dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html) configuration files. If you haven't already, install via Homebrew: ```bash brew install dnsmasq ``` DNS takes slightly more setup than the others. You'll need to create the configuration files and update with the edited one from this repo: ```bash sudo mkdir -p /etc/resolver/ sudo touch /etc/resolver/dev touch /usr/local/etc/dnsmasq.conf ``` Then you'll want to flush your local DNS cache to ensure `dnsmasq` takes over: ```bash sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist dscacheutil -flushcache ```