How to Set Up a Killer WordPress Testing Environment Locally

How to Set Up a Killer WordPress Testing Environment Locally

If you’re a heavy WordPress developer like me, you might find that you need to create a new installation for each site that requires a strange structure or specific posts, instead of using your uniform local test WordPress installation. Cue WordPress Mu. WordPress Multi User is a platform created by the geniuses at Automattic that is basically a WordPress installation that allows multiple blogs to run using the same software.

In this tutorial, I’m going to show you how to set up WordPress Mu locally so that it can be viewed in VMWare Fusion too, a piece of software that allows for cross-browser testing on Microsoft XP and Vista. Mac only, sorry, however I’m sure something similar can be done with the PC versions of MAMP.

Preface

Unfortunately this tutorial requires a few paid things, so it can get expensive. You’ll need MAMP PRO, Microsoft XP and VMWare Fusion- Only MAMP PRO is essential if you don’t need to cross-browser test. MAMP PRO has some functionality on MAMP that we need when defining our new developer site. Download WordPress MU as well, we’ll need that!

Note: MAMP PRO comes with MAMP- just stick both of them in Applications because you need the two.

Run Down

OK, so if you don’t know completely what we’ll be doing, I’m going to break it down further. If you use WordPress to develop your websites, then each time you create a new website you need to download a new installation of WordPress, install it, and go through that entire process just for a new site. This takes time AND hard drive space. What we’ll be doing, is setting up a type of WordPress installation that allows you to use the same WordPress files, and set up a new WordPress site via wp-admin instead of going through the famous 5 minute install.

At the end of the tutorial you’ll be able to visit http://wordpress.mu/ to see your local WordPress MU installation. You’ll also be able to open the same page in VMWare Fusion, which will be running Windows XP. This means you’ll be able to see it in ALL major browsers- IE5.5-8, Chrome, Safari Mac, Safari PC, Firefox Mac, Firefox PC, etc. The list goes on.

Step 1 – Changing Ports on MAMP PRO

Once you’ve installed MAMP PRO, open it up and the servers should start running. We need to change the ports. Ports are basically the ‘door’ that a server tells the browser to go through. You might be familiar with CPanelX’s port 8082. CPanel has told your server that to get to the CPanel, you need to go through door 8082. By default, MAMP PRO likes to have it’s own ports- 8888 for apache and 8889 for MySQL. We need to change this back to the default settings. You can either turn it to 80 / 3306 manually or simply click ‘Default Ports’

MAMP PRO will then tell you that the servers need to restart in order for changes to take effect. Click OK and let it do it’s thing. If it tells you that Apache’s failing to restart, check that ‘Web Sharing’ is un-ticked in your Sharing Prefs pane. You should now be able to visit http://localhost:80 to see either the ‘If you can see this page Apache is successfully installed’ page or the default MAMP index page. Great.

Step 2 – editing httpd.conf

httpd.conf is what Apache reads when it looks at what hosts or URLs to run on. You can find httpd.conf in ~/Applications/MAMP/conf/apache/httpd.conf

Scroll down to the very bottom, and you will probably find this:

<VirtualHost *>
	DocumentRoot "/Applications/MAMP/htdocs"
	ServerName localhost
</VirtualHost>

or nothing at all. We are going to add this, or change it to the following code. We’ll also be adding our own Virtual Host, which will be wordpress.mu (Just a side note, when doing this it’s important to never pick a URL that will conflict with an actual site, because while the settings are like you’ll never be able to visit your local site’s url online. e.g. if I set my host to be example.com, example.com would always resolve to my local machine as opposed to example.com online). So like I said, add this (or change the default one)

<VirtualHost *>
	DocumentRoot "/Users/YOU/wordpres.mu"
	ServerName localhost
</VirtualHost>

<VirtualHost *>
	DocumentRoot "/Users/YOU/Sites/wordpress.mu"
	ServerName http://wordpress.mu/
</VirtualHost>

Don’t forget to change YOU to your user name. This will also require a restart of the Apache and MySQL servers. You’ll probably notice that wordpress.mu doesn’t exist in your sites folder- so create it!

Step 3 – editing /etc/hosts

This file, hosts is the configuration for exactly that, the hosts. So httpd.conf set the hosts for your mac! This requires some Terminal work, but I promise you it’s as easy as copying and pasting the command, and then typing a single line!

Open Terminal (it’s in Utilities in the Applications folder) and type:

sudo pico /etc/hosts

And hit enter. sudo means it’s an admin action, pico is the Terminal’s editor (which you’ll soon see) and /etc/hosts is the path to what we want to edit. You’ll be prompted for your password, so type it in. You should now see this screen:

That last line may or may not be there- if it isn’t don’t worry we’ll be changing it anyway. Put the cursor at the bottom (clicking doesn’t work) and where that last line of code is, change localhost to wordpress.mu. It should read:

127.0.0.1 wordpress.mu

127.0.0.1 is the computer’s way of saying ‘me’. Save the file by pressing ctrl+o (o for write out and then ctrl+x to quit pico.

Step 4 – Adding a host for MAMP PRO

The final piece of the puzzle is to create a host alias in MAMP PRO. Now that the hosts are all set up, we need to tell MAMP PRO that it’s actually there. In MAMP PRO click on the ‘Hosts’ tab. You need to add an alias. Click the little plus in the bottom left. You need to set a few things. Server name: wordpress.mu, port: 80, Disk Location: /Users/YOU/Sites/wordpress.mu, and add an alias in the bottom right of wordpress.mu.

Click apply, and once again restart the servers

Step 5 – WordPress MU

Grab your wordpress-mu Download and rename it to wordpress.mu. Stick it in your sites folder. Hey presto, you can go through with the installation! Unfortunately I found no easy way to use sub-domains on a local server, so I just stuck to sub-folders as the structure. Great! You can now use WordPress mu on your local computer! Go ahead with the 5 minute install, and then you can add blogs under the ‘Admin Menu’. I wont go too much into the actual functionality of WPMU, but I’ll explain how I use when working at the end.

VMWare Fusion

I’m not going to go into depth on this topic, because there are many tutorials on it. I will however explain how to modify a brand new installation (even if you’ve used it for ages there probably isn’t a lot that will have changed anyway). Start up VMWare Fusion, and activate Unity if you so please. Unity allows you to run Windows XP windows natively in your mac- see screenshot below!

Step 6 – \etc\hosts (windows)

The /etc/hosts file in XP needs editing too. You can find it in C:\Windows\system32\drivers\etc\hosts. Open it up with Notepad, and we’re about to put our line in. We need to grab an IP address first. Open a new terminal window and type ifconfig -a. You will get a whole lot of junk back- scroll down a bit until you can see ‘vmnet8′. Grab that IP address, the one I’ve highlighted in the image below.

Then go back to your \etc\hosts file in windows, and at the bottom, paste that IP address in followed by wordpress.mu.

Step 7 – flushdns

Sadly, windows needs to be slapped for it to noticed that a change has taken place, so you now need to open Command Prompt. It is in Accessories in the start menu. Simply type ipconfig /flushdns. What this does is flush all the DNS names (localhost mainly) so that it recognises the updated hosts file.

Voila!

You are now able to visit your MAMP running WordPress MU installation on every windows browser there was- looks like I have a bit of work to do!

A practical use for it

So as promised, I said I’d tell you how I use it. What I’ve done is gone ahead and downloaded every browser I need/support and installed it into my XP install. This way I can compare my WordPress sites window beside window and easily have access to modify whatever I need to, without having to save it and refresh an online installation!

Take a Wrap

So there you have it. The ultimate guide to the ultimate WordPress setup. It feels like I haven’t put enough emphasis on WordPress MU itself, but it is just an install tutorial. WordPress MU saves loads and loads of disk space by taking all your separate WordPress blogs and putting them into 1- you have a universal theme folder/manager which makes it super easy to quickly swap between editing sites.


Tags: Wordpress
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.wpdone.com Adrian – WPDONE

    Thanks Harley. Great TUT

  • http://www.thomaswornall.com thomas wornall

    i have set this up completely and utterly free. 1 xamp is free. wordpress mu is free. all browsers are free. search multi ie if you want to test in ie 6 and & 7. personally i say let ie 6 die.

    i would like to know how to set this up in windows server. i downloaded php for it and cant get it to install properly i keep getting an error saying i dont have permission to run isapi from that folder. the tut i found suggested i dont use the cgi. so i guess what i am really asking for is how to install php on to windows server 2003

  • http://www.justvouchercodes.co.uk Paul

    Another great tutorial. Thanks very much!

  • Frustrated Ryan

    I keep getting, “Error establishing a database connection” when I hit ‘Submit’ from the WordPress install page.
    I am able to do everything you have outlined in the TUT up until that point.

    Any thoughts?

  • Frustrated Ryan

    I also mean “WordPress MU” when I say “WordPress”

  • Frustrated Ryan
    • http://baffleinc.com/ Harley Alexander
      Author

      That’s extremely odd- try from scratch and use something like AppZapper to get rid of all files attributed to MAMP/MAMP PRO. That error is what I got whilst installing without changing my host from localhost:8888, as WPMU can’t be installed on domains that have ports (thus the need to resolve to wordpress.mu).

  • http://www.pushmedia.no Magone

    When you use this setup with wpmu, do you use it with sub-domains or sub-directories. I couldn`t get sub-domains to work.

    Great tutorial, been looking for this.

    • http://baffleinc.com/ Harley Alexander
      Author

      Sub-directories, I am yet to figure out how to do sub-domains, as that requires some htaccess stuff that I am not sure how to do locally (or online for that matter :P)

      • http://iphone3g.in JAX

        You cant do subdomain locally unless u run a dns server locally. if u are using dynamic dns, some prividers allow wildcard dns. Then u can use subdomain.

    • http://www.zendesk.com Ross

      To get subdomains working locally (and at this point I assume you’re running WordPress 3.x multisite), simply add each subdomain in your hosts file and as additional aliases in MAMP Pro under the hosts tab. So your hosts file looks like:

      127.0.0.1 mydomain.com http://www.mydomain.com sub.mydomain.com sub2.mydomain.com

      Easy peasy.

      • http://nathanrjones.com Nathan Jones

        Definitely easy peasy once you know what you’re doing. For those just getting started, here’s a Stack Overflow question that goes into a little more detail on the setup:

        http://stackoverflow.com/questions/6986770/wordpress-subdomain-on-localhost

        Here’s an example httpd.conf for using subdomains:

        NameVirtualHost *:80
        <VirtualHost *:80>
        ServerName mydomain.local
        ServerAlias site1.mydomain.local
        DocumentRoot “..\htdocs\wordpress\site1″
        DirectoryIndex index.php index.html index.html index.htm index.shtml
        </VirtualHost>

  • http://www.stylozero.com Gianfranco

    I got a question about the local path to the directory where the websites are stored.

    The tutorial (and screenshots) shows a setup like: /Users/YOU/Sites/wordpress.mu

    Now, as far as I know, MAMP doesn’t allow you to have such configuration, but in order to work, you are obliged to have your site folder in the MAMP folder.

    As so: Applications/MAMP/wordpress.mu

    Or is there a workaround that I was never able to get?

    If there is, I’d love to know more about.
    Thanks.

    • http://baffleinc.com/ Harley Alexander
      Author

      As described in step 4, you can and MAMP automatically changes the PHP directory to whatever path you wish- not restricted to htdocs in the MAMP folder. This allows you to have php files in both Sites and htdocs, and basically anywhere on your computer- MAMP recognises them all as places for PHP files!

  • RJ

    Hey Harley, Your attention for a couple of moments.
    Right, I do everything as you tell me to, right to the letter, but when I do the terminal commands, I get an error message saying that it can not find wordpress.mu and it does not exist – how on earth do I fix this? Basically it might be the same thing Gianfranco is saying – how on earth does this directory at YOU work?

    • http://baffleinc.com/ Harley Alexander
      Author

      The ‘YOU’ should be replaced with your username for your computer, so for me YOU would be replaced with ‘Harley’. the Command ifconfig -a will only return a vmnet8 IP address if you have VMWare Fusion installed and running, thus why we didn’t get that IP previously. If you could post the Error you get to pastie.org or something that’d be awesome!

      • Hassan

        Harley? Windows version not coming?

  • bruno

    Very nice tuto.
    I have setup a couple of virtual hosts in windows and they work but now i can´t access to phpmyadmin (error 404).

    I am using wamp.
    Is anybody out there with experience in wamp and virtual hosts?

    • http://baffleinc.com/ Harley Alexander
      Author

      Have you flushed your DNS’s? Open Command Prompt and type ‘ipconfig /flushdns’.

  • http://www.kevinleary.net Kevin

    Thanks for this Harley, I’m loving it. Especially the faster cross browser testing with VMware. Now the next question I’m working on is: What’s the best process for creating a WordPress staging environment on the web.

  • Simon

    Your attention for a second Harley?

    I’m getting the same error Ryan above, but I don’t see why. Everything is working until the point where I’m sending the WPMU installation.

    “Error establishing a database connection
    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost:3306. This could mean your host’s database server is down.”

    Upon looking up the wp config file it is correctly set up. Also when starting Mamp and launching the Web it says that MAMP was set up correctly for localhost and port 3306.

    Help please?

  • http://hubpages.com/hub/Stop-Websites-Breaking-In-Different-Web-Browsers Berogra

    Thanks for that post. As a designer/developer that is new to WordPress, it helps to know these things.

  • mathi

    can i setup a second wordpress environment… like wordpress.nu for the normal wordpress-version? i did almost all steps again for with wordpress.nu except for calling “sudo pico /etc/hosts” in terminal and setting up a new host, because the wordpress.no already exists. can you tell me what i’m doing wrong?
    thanks guys

  • http://chrisgilligan.com PG

    Thanks for the tutorials on MAMP Pro… much better than the manual, got me going in seconds after wasting an hour with the MAMP Pro manual trying to get virtual hosts set up.

    One crit: I don’t think you need to do the manual editing of hosts or conf — MAMP Pro automates those for you.

  • http://blog.siosism.com Siosi

    This was a really informative post – thanks a heap!

  • mathi

    don’t mind me asking. however would you do a tutorial on how to transfer a finished website from localhost to a real server? i think there are a lot of people out there, that don’t know how to do that!

  • jason

    lovely tutorial, however is it normal that my mamp pro always asks for the admin password of my mac before quitting?

  • focus5d

    Great tut, but I get a Gateway Timeout error when I use ie6

    Gateway Timeout
    The following error occurred:
    A DNS lookup error occurred because the request timed out during the lookup.

    Anyone know a solution?

  • http://www.honeytechblog.com Honey Singh

    I used xamp and wamp for last few years.
    I think its time to hands on Mamp over the mac.

  • http://www.invisioner.com invisioner

    Hey,

    Very informative article, congrats to the author.

    To those struggling with WPMU, i found out that on MAMP PRO, Snow Leopard install, the only way to finish installing correctly is the following:
    1. Check out the user/password info on MAMP localhost homepage
    2. Make sure you created an empty database and check twice it exists and that you wrote correctly the name.
    3. Most important step: database host=localhost:3306, not just localhost
    4. Make sure you introduce a password
    5. If it gives you error when you click submit, delete wp-config.php and start over.

    That’s all.
    Peace

    • http://www.invisioner.com invisioner

      instead of

      4. Make sure you introduce a password

      read

      4. Make sure you introduce an e-mail

  • Adam

    What if I need to design two wordpress mu sites a time? How do I create another database?

  • Adam

    Let me rephrase that. What if I want to create another installation us mamp pro. For example, an installation of regular wordpress in addition to wordpress mu. Or for that matter two separate installations of wordpresss mu. Any ideas?

    • http://mattwalters.net/ Matt

      You could do this with normal MAMP. I’m not sure why this article thinks you need MAMP Pro. Don’t get me wrong, it is a good article and the steps they suggest all sound good to me, but you could do all of it with normal MAMP and save yourself the cost.

  • http://insurances-loans.com aks

    nice post thanks for given this information.

  • http://www.m21m.com Steve McIntyre

    I set this up this weekend and wanted to say thanks. This works very well. Not sure if anyone uses bbedit, but you can use the command line to edit the hosts file by typing:

    bbedit /etc/hosts

    That command will open the hosts file in bbedit instead of pico (step 3). You can open other files with this command too.

    Hope that helps and thanks again.

  • http://www.sawmac.com/ Dave McFarland

    You don’t need to do steps 2 and 3 if you have MAMP Pro. It adjusts the httpd.conf and /etc/hosts files for you. Likewise, you don’t nee MAMP Pro if you do steps 2 and 3. That’s the manual way to configure MAMP for virtual hosts.

    If you use XAMPP on windows, you can also setup virtual hosts. I’ve got an article on this at: http://www.sawmac.com/xampp/virtualhosts/index.php

    • Don Howard

      Hey Dave,

      That’s an excellent tutorial and I’m glad you posted it here. Do you know what the procedure is for setting up virtual hosts with XAMPP on a Mac?

      Thanks,
      Don

  • http://www.wholesaleinc.net/ koko

    Thanks for sharing~

  • http://connorcrosby.me Connor Crosby

    I have been wondering how to do this, thank you!

  • http://www.michaelroseagain.com Michael Rose

    I’m set up, with MAMP PRO on a Mac. But now I can’t use the automatic upgrade. It’s asking for details, I’ve given local host, wordpress.mu, all sorts of attempts.

    Is the only way to upgrade to do a manual download?

  • DP

    I followed everything that you posted, and I even deleted everything and did the process over again. When I type in sudo pico etc/hosts, my file is no longer there. So I used sudo pico private/etc/hosts, know when I type either into the terminal an empty sheet appears and when I try to re fill in all the information and save the changes, I get a buss error.

    Not to mention that now nothing appears when I type in wordpress.mu, except for the apache page.

    Before I deleted and reinstalled mamp pro and wordpressmu, I was getting “Error establishing a database connection”, which no one here has seemed to find an answer to.

    getting frustrated ; – ((

    • lag47

      Hey DP,

      Did you ever figure out how to get it set up? I am having the same problem as you…. Error establishing a database connection. Please, anyone, help.

      • lag47

        please help!

  • flamman

    I like!!!!!! :D

  • Anes P.A

    Hello Sir,

    I Install WordPress MU as You Directed Here. Installation is Success,
    But When I create a user Blog eg: it’s name is firstone then the
    url is : http://localhost.localdomain/wpmu/firstone/ But when I visit this page I got a 404 page Not Found Error. How it can Avoid? As an Experience I copy all files in /wpmu installation Folder to this /wpmu/firstone folder. Then I got the page, but When I click some
    links like Comment , I got another page Not Found 404 Error.

    Sir , please Give a Work arounf for it …. I know Copy the Content to
    new folder is not a Solution….. I am working in Red Hat Linux Fedora
    Core 8 PC …. ok I am waiting your Reply… Kindly give a Solution as Early as Possible…..
    You can contact me : anes.pa@amskape.com

    With Great Regards
    Anes P.A

  • http://www.mathias.li Mathias M Stav

    Great tutorial! But when I try to install wordpress it won’t actually make the wp-config.php file. Weird! Tell me if you understand my problem and know the solution.

    Keep up the good work Harley!

  • http://www.mathias.li Mathias M Stav

    Haha. Stupid me! I forgot to set up a database :P

  • lag47

    Please help.

    Error establishing a database connection

    I can run a normal wordpress installation using MAMP pro, but when it comes to MU, I just get:

    Error establishing a database connection

    that is with mu 2.9.2 with no modifications. Please help.

    • lag47

      BTW, the VMWARE Fusion part of the tut was totally helpful!

  • http://www.richardsweeney.com Richard Sweeney

    Fantastic tutorial, exactly what I was looking for. Many thanks.

  • http://lifestreamvideo.com lag47

    How do you set up FTP for updating on the localhost?

  • lag47
  • http://www.claytonmiller.com Clayton

    i followed the instructions and installed everything. when i try to do the install i get a 404 saying file not found on this server. when i type in http://localhost:80/MAMP it says its installed correctly. I created a database with the same name as my blog folder so its all related. I dont understand what would be wrong.

  • Error Buddy

    I’m pretty incompetent, but could still set up MAMP PRO, WordPress 3.0 network, on my MAC. So this is the nicest development environment I’ve had yet.

    However, I cannot execute media uploads using the WordPress interface. I set the MAC upload destination directory permissions to R/W for everybody, but still get the WP error message showing FAIL.

  • iain

    Thanks for a great tut Harley. I’m very new to this, but its all gone surprisingly well so far. I have, however, run into a problem: I’m using MAMP, and not MAMP Pro, so I have no option (that I can see) to add a host. When I go to http://wordpress.mu/ I am presented with the standard mac “Your Website” page, even though I have the wordpressMU install setup in sites/wordpress.mu. Any solutions?

  • http://cardeo.ca matt

    I successfully installed wordpress locally using MAMP. My problem is I can’t get any plugins to work. Do you need to do something special for that?

    I tried adding a couple plugins to my plugins folder but when I go the wp admin, they don’t show up under the plugins section.

    any ideas?

    • http://cardeo.ca matt

      I just noticed I have the same problem with themes. When I add a theme, it doesn’t show up in the wp admin.

  • lionel

    hi there, I don’t know if this has been a problem for people, but in the section that edits the virtual host in the httpd.conf file it sets the host to wordpres.mu and not wordpress.mu, I am not certain, but wouldn’t that create a problem?

  • http://www.nextdoormedia.com.au Josh

    Hi all,
    Thanks for the tut. My setup worked great although I couldn’t get any links to work. I was getting a “not found on this server” error.
    My problem was he server was not recognizing my .htaccess file. I couple things that helped.

    Firstly to see your hidden files in finder goto your terminal and type
    defaults write com.apple.Finder AppleShowAllFiles YES

    Secondly for me I had to change Applications/MAMP/conf/apache/httpd.conf and edited the code below:

    Options Indexes FollowSymLinks
    AllowOverride None

    and changed None to All to end up with this:

    Options Indexes FollowSymLinks
    AllowOverride All

    Then restart your server

    Hope this helps.

  • http://www.strx.it Francesco

    I’ve written a similar linux based tutorial, you can find it here
    http://www.strx.it/2010/10/how-to-create-wordpress-blog-step-by-step/

    Thank you

  • http://help-environment.blogspot.com/ Energy Saving & Solutions Tips

    Thanks for this great and wonderful post i appreciate it thanks for sharing.

  • http://www.techtipsdigital.com Sunil Sheoran

    Great post man! Keep it up! You have mentioned quite a few details which “enlightened” me! :)

  • http://www.trade4u.co.nz Amit Sharma

    Thanks heaps for this post! I’ve been trying to get it right for a while and this tut was very useful.

  • http://designcreatedevelop.co.uk Duane Laverick

    Brilliant, been looking for a tut like this for couple days now. took me a while, but got there in end. Thanks :-)

  • Joe

    Followed the tutorial and got to Step 3 fine, no problems. But I can’t seem to edit the hosts fille, I edit like the instructions say, hit ctrl-o then ctrl-x. But when I go back and view the file, no changes have been made and when I go to localhost/ it still says I the root is localhost. What am I doing wrong? Thanks.