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
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.
Update: Alternate Method
Yotam Praag sent in an alternate way of implementing this step. Instead of the previous instructions for “Edit Apache config file”, follow these steps:
1. Open up
2. Uncomment the line under the “Virtual Hosts” section, so it looks like this (note that the path may vary depending on your setup):
# Virtual hosts Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
3. Next open
4. Remove all example entries so you will have an empty file
5. Now add the following lines to your file:
<VirtualHost *:80> ServerAdmin email@example.com DocumentRoot "/Users/myusername/mysite/" ServerName example.com ServerAlias example.com *.example.com # Uncomment next line if you need to specify the location of your log file # ErrorLog "logs/dummy-host.example.com-error_log" <Directory "/Users/myusername/mysite/">Options Indexes FollowSymLinks Includes AllowOverride All Order allow,deny Allow from all</Directory> </VirtualHost>
6. You can add as many of the above as you need by changing the
Directory entries accordingly.
This method is very similar to the previous technique, but enables you to add more site definitions and keeps your config file slightly less cluttered.
Install & 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”:
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!