Skip to content

Instantly share code, notes, and snippets.

@linuslundahl
Last active August 17, 2019 06:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuslundahl/02a6eccef5b998bd3baa to your computer and use it in GitHub Desktop.
Save linuslundahl/02a6eccef5b998bd3baa to your computer and use it in GitHub Desktop.
MAMP with Brew

XAMP/MAMP stack with brew

For Brew driven MAMP with Apache2, PHP 5.3 and MySQL 5.x

Install brew (assuming that you have Xcode installed).

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Install git and bash completion.

$ brew install git
$ brew install bash-completion

Install dnsmasq for local wildcard domain.

$ brew install dnsmasq
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
$ sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Edit your dnsmasq.conf and add an entry for your local development domain. At Good Old we generally use the develpers first name or nick as top level domain. That way we can check out each others work without having to change the IP for *.dev or a similarly generic domain. For me that would be:

address=/.linus/127.0.0.1

You can also add your colleagues like this:

address=/.anders/192.168.4.123

Restart dnsmasq to let the configuration changes take effect.

$ sudo launchctl stop uk.org.thekelleys.dnsmasq
$ sudo launchctl start uk.org.thekelleys.dnsmasq

Install mysql and follow the instructions:

$ brew install mysql

Open the apache config:

$ subl /etc/apache2/httpd.conf

...uncomment the following:

LoadModule php5_module        libexec/apache2/libphp5.so

...and add the following (it doesn't have to be located in ~/Sites):

# add this at the end of the file
Include /Users/[USERNAME]/Sites/apache.conf

Create the apache.conf file:

$ touch ~/Sites/apache.conf

...and add the following contents:

# get the server name from the Host: header
UseCanonicalName Off

# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /Users/[USERNAME]/Sites/%0/public_html
<Directory "/Users/[USERNAME]/Sites">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Require all granted
  allow from all
</Directory>

...and restart.

$ sudo apachectl graceful

Now you should have a working XAMP stack. Just add a "domain.linus" directory to ~/Sites with a public_html dir inside and it will be available as a local site.

Now create a password for your MySQL root user. See here for instructions.

@beginnertutorials
Copy link

@towers1209
Copy link

towers1209 commented Aug 17, 2019

I see that this document is four years old. Is this still good? Has anything changed for the latest macOS Mojave? I will be installing a local WordPress on my MacBookPro.

@linuslundahl
Copy link
Author

linuslundahl commented Aug 17, 2019

@towers1209 Hey, I'm not doing much PHP coding nowadays, but that guide is definitely out of date... I'd probably have a look at something like this: https://getgrav.org/blog/macos-mojave-apache-multiple-php-versions and this https://getgrav.org/blog/macos-mojave-apache-mysql-vhost-apc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment