Developing WordPress sites on a local MAMP server provides flexibility, privacy, and security throughout the development process. Setting up a WordPress environment on MAMP is definitely worth the effort, especially if you’re building and testing multiple sites using WordPress’ built-in MultiSite functionality.
The easiest and recommended way of setting up WordPress MultiSite is to use sub-directories. So when you create a new site named “business”, it will be located at http://localhost/business/. Here’s a mini-tutorial on how to use sub-domains for your network sites.
Edit Mac hosts file
After installing MAMP, change the default Apache port to 80. Next, add your sub-domains to the Mac hosts file. To do this, open Terminal and type “sudo pico /etc/hosts” (without the quotes), and then enter your password at the prompt. Use the arrow keys to scroll down to the end of the hosts file and add the following lines:
127.0.0.1 example.com
127.0.0.1 site1.example.com
127.0.0.1 site2.example.com
Edit these entries to match the domain and sub-domains that you want to create with MultiSite. Add as many sub-domains as needed, now or later. Then save the file and exit by typing Ctrl+O, Enter, and then Ctrl+X.
Edit Apache config file
The next step is to add virtual hosts to your Apache configuration file. Open /Applications/MAMP/conf/apache/httpd.conf in a text editor and scroll down to the line that says “#NameVirtualHost *”. Replace that line with the following code:
NameVirtualHost *
<virtualHost *>
ServerName example.com
ServerAlias example.com *.example.com
DocumentRoot "/Applications/MAMP/htdocs/"
<directory "/Applications/MAMP/htdocs/">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</directory>
</virtualHost>
Change each instance of example.com to match your domain, save the file, and then Restart Apache by clicking “Stop” and then “Start” in the MAMP control panel.
Intall & configure WordPress
Now to install WordPress by placing the WordPress installation files in your /htdocs/ directory, creating the database via phpMyAdmin (@ http://localhost/MAMP/), and editing wp-config.php with your database credentials. Then complete the install process by accessing http://example.com/wp-admin/install.php in your browser.
Next, enable MultiSite by adding the following line to your wp-config.php file, just above the line that says, “That’s all, stop editing! Happy blogging”:
define('WP_ALLOW_MULTISITE', true);
With that in place, return to the WP Admin and click on Tools > Network. On this page you will now see an option to use sub-domains for your site addresses. Make sure that’s selected, check the other details, and then click the “Install” button to make it happen. Note that you’ll see a warning message that says, “Wildcard DNS may not be configured correctly!” – we can ignore this warning because we know our DNS is correct.
Finally, complete the steps outlined there on the “Enabling the Network” page (i.e., create a blogs.dir folder and add the required code snippets). After that, re-login to the Admin area and go to Network Admin > Sites > Add New to begin adding your sub-domain network sites.
That’s it! You’re now rolling tuff with WordPress subdomains on a local MAMP development server. The sky’s the limit!
19 Responses
Konstantin – September 28, 2011 •
Nice Jeff, thank you! I spent like 3 hours on that issue the other day.
There is no way to get wildcard subdomains working in the hosts file, is there?
Jeff Starr – September 28, 2011 •
I wouldn’t say it’s impossible, but it kinda looks that way when using the hosts file.
Konstantin – September 28, 2011
Okay, let me rephrase that:
Is there a way you know of to get wildcard subdomains working with MAMP?
:)
Jeff Starr – September 28, 2011
I’ll look into it again and post afresh with any breakthroughs :)
Peter Wilson – September 28, 2011 •
On the advanced tab in MAMP PRO, I add a wildcard server alias in ‘customised vertual host general settings’.
http://yfrog.com/mf9ekp
I’ve got the same fixed IP at work and at home, so I just point a wildcard domain in a handy DNS server at the relevant 192.168.x.x address.
My mamp server is then available to others on the network so I can send links on my machine to my business partner
Jeff Starr – September 29, 2011 •
Ah that’s the ticket – MAMP PRO FTW. Thanks for sharing this with us, Pete. I needed an excuse to shell out for the Pro version.
Ben – September 29, 2011 •
For those who use WAMP with Windows, follow the same steps as above for the hosts file and
httpd.conffile except try the following.First, your config file will be somewhere like:
c:\wamp\bin\apache\apache.ver#\htdocs\You will need to enable virtual hosts. Search for:
"
# Virtual hosts" <- without the quotesRemove the hash from the line below that. It will look like:
"
#Include conf/extra/httpd-vhosts.conf"Save the config file.
The actual editing that Jeff was talking about will be in a subfolder called "
extra". The file to edit is "httpd-vhosts.conf".Edit it as Jeff instructed.
Once you have the config file edited, open your hosts file. You will need to open it as administrator. For Windows users, it is located in: "
C:\Windows\System32\drivers\etc".Copy the info in that file and put it into a new file called "
hosts_2". Edit this file to reflect the idea Jeff spoke of above.Now, somewhere on your system, create a batch file. Put this code into it.
cd\cd C:\Windows\System32\drivers\etcrename hosts hosts_3rename hosts_2 hostsrename hosts_3 hosts_2Now, all you have to do is run this batch file as administrator and it will swap your host files from the everyday file to the development file. Doing this will allow you to switch back and forth between the local development site and the live site.
BONUS:
By editing the
httpd.conffile correctly, you could change the document root of your development site to your DropBox folder.Here is an example of my config for my todo list.
ServerAdmin webmaster@localhostDocumentRoot "S:/My Documents/Dropbox/todo"ServerName todoOptions Indexes FollowSymLinksAllowOverride allOrder Deny,AllowDeny from allAllow from 127.0.0.1Chris Krycho – October 4, 2011 •
Out of curiosity, is there a particular reason to use MAMP versus the built-in server capabilities of the Mac? (I had to do a MySQL install and tweak a few PHP settings, but otherwise my default install, both in Snow Leopard and Lion, is perfectly happy running a local server…)
Thanks for the tutorial, as it’ll be immensely helpful for me as I set up a new site using Multisite over the next month or two!
Jeff Starr – October 4, 2011 •
Not really. Ultimately they do the same thing, but MAMP provides some additional options and makes it all easier to change settings from it’s handy little control panel. I’m not sure if there’s anything like that for the built-in Mac files..?
Chris Krycho – October 4, 2011
No, you end up digging around in the back end apache files a lot. The GUI alone may make it worth my time to come at from that angle.
Thanks for the quick response. :)
James – October 5, 2011 •
I’m wondering if anybody else finds this not possible – I keep revolving back to the WordPress Codex which states;
You cannot choose Sub-domain Install in the following cases:
WordPress install is in a directory (not in document root).
“WordPress address (URL)” is localhost.
“WordPress address (URL)” is IP address such as 127.0.0.1.
http://codex.wordpress.org/Create_A_Network
Jeff Starr – October 5, 2011 •
Yep, the Codex is correct, but none of those cases apply here.
James Osterhout – October 6, 2011
Thanks – any thoughts or suggestions for migrating an existing Sub-domain install to MAMP as described?
Costas – October 16, 2011 •
Any ideas how to make the subdomain in the host file added automatically? Giving the chance to the user to create its own subdomain ( as it is in wordpress blog new account registration)
Rafael – April 3, 2012 •
Web server must be restarted after httpd.conf changed, so I think it’s impossible.
Mike – October 22, 2011 •
Thanks for this tutorial. After much searching I was able to get MAMP running multisite using your post.
I followed the steps above but here’s how I configured the FREE MAMP version:
Got to MAMP’s apache folder and open the httpd.conf file. Uncomment the following line under # Virtual hosts:
Include
/Applications/MAMP/conf/apache/extra/httpd-vhosts.confThen go into the extras folder and open your httpd-vhosts.conf file. Add the following code and replace example with your site.
ServerName example.comServerAlias example.com *.example.comDocumentRoot "/Applications/MAMP/htdocs/example/wordpress"Options Indexes FollowSymLinks IncludesAllowOverride AllOrder allow,denyAllow from allErrorLog "/private/var/log/apache2/example.localhost-error_log"CustomLog "/private/var/log/apache2/example.localhost-access_log" commonRestart MAMP and you should be good to go. Also, it’s very important to make sure you have Web Sharing turned off in your Mac System Preferences. Your system Apache interferes with MAMP’s Apache.
victor – July 13, 2012 •
I’m stuck at the line that says “#NameVirtualHost *”. where is it? I simply don’t see it on /Applications/MAMP/conf/apache/httpd.conf
Mannie – July 30, 2012 •
There appears to be a change with the latest versions of MAMP.
Now, look for “#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf” and remove the hash at the beginning of the line. Then edit the file referenced in that line.
Jeff Starr – August 3, 2012
Thanks Mannie!