Recently I have been working on a large WordPress multisite project. After working for a while it was clear that we needed a more robust development environment to work with, including local, staging and production. I use MAMP for local development and therefore I needed to get MAMP working with WordPress multisite and sub domains. Here is how I went about this.
For this I am assuming that you have MAMP installed and that you are comfortable using MAMP. The first thing to do is to make sure that MAMP is using the default Apache and MySQL ports (80 and 3306 respectively). To do this click on Preferences from the MAMP window and click the button titled “Set to default Apache and MySQL ports“.
The next thing to do is to edit your Macs hosts file. To do this enter the following into the Terminal:
sudo pico /etc/hosts
When prompted enter your password and you will then see the hosts file with a list of hosts defined. Use the arrow keys to move to the bottom of the list and then enter the domain you want to use locally for this Multisite install. For this example we are going to use mysite.dev. As this is going to be a sub domain install you will need to add any sub domains in here too that your sites in the multisite are going to use. Here we will just add some examples. The following provides an example of what to add:
127.0.0.1 mysite.dev 127.0.0.1 site1.mysite.dev 127.0.0.1 site2.mysite.dev
If you add additional sites to your multisite install in the future you will need to add these subdomains to the hosts file before setting up the site in WordPress. The next task is to edit the apache config files to create a virtual host. The file to edit (just use textedit) is located in the following location:
In this file find the following:
# Virtual hosts # Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Remove the hash in front of the “include” line to include the virtual hosts extra. The next step is to edit this file with can be found here:
At the bottom of this file add the following, obviously replacing the domain name to the one you want to use.
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot "/Applications/MAMP/htdocs/" ServerName mysite.dev ServerAlias mysite.dev *.mysite.dev </VirtualHost>
The above uses the default MAMP document root although you could place you files elsewhere should you wish too. You could also create a folder in the htdocs file and then use that.
Restart MAMP by clicking “Stop Server” and then “Start Servers” in order to activate the virtual host changes.
Now all you need to do is install WordPress and activate WordPress multisite and you are ready to go with running a WordPress multisite install locally.
Leave a Reply