This article explains how you set up a copy of a WordPress site on your computer. This can be very useful if you need to find out what will happen if you do an upgrade, for testing out and playing with plug ins, and for developing WordPress themes.
This article is aimed at PC owners. I use both PC and Mac, and this time I had to do this task on my PC. The principles can also be applied to a Mac, and I have already written a group of articles for Mac which will be linked to from this article that achieve the same results.
We’ll be going through the following steps:
- Installing PHP, MySQL and Apache on a PC to form the ‘local host’
- Copying the WordPress install over from your remote host
- Copying the database
Here we go…
Installing PHP, MySQL and Apache
Go to my tutorial on setting up PHP, MySQL and Apache on a Mac.
There are many packages available that allow a one click installation of PHP, MySQL and Apache on a PC. I looked at a few and settled for WAMP, as its kept up to date, is relatively lightweight and easy to use.
- Start by downloading WAMP.
- Run through the installation, accepting the defaults.
- You should now see a new icon in your taskbar – that’s WAMP! If you don’t see it, just start the software by clicking on the icon, or locating it in your programs.
- Start your webserver by left clicking on the icon in the taskbar, and selecting Start All Services. Nothing will happen – the services run behind the scenes.
- Open a browser and go to http://localhost/, if you see the WampServer homepage then you’re ready to start setting up wordpress.
Copying the WordPress install over from your remote host
Next you are going to download WordPress from your remote host and set it up as a local site.
- Using your preferred FTP client (I use the excellent free filezilla) download all the files in and including the folder associated with your WordPress install. If your WordPress is in a folder called ‘wordpress’, you need to download the whole folder.
- Place the downloaded folder into the WAMP folder www. This is where all files to be run on the webserver need to be placed. This can be found by clicking the WAMP icon and selecting the ‘www’ directory option. Its also in C:/wamp/www
- Once the downloads are complete, go to http://localhost/the_name_of_your_wordpress_folder, you should see a database error. If you do, its all worked! If you see a server error, its likely to be your .htaccess file – try removing it temporarily.
Copying the database
Now you need to get all the tables associated with WordPress out of the remote server, and onto the local server. You’ll probably need to use PHP MyAdmin, which most hosts include by default. If this isn’t available and your using a version of WordPress which is later than 2.0.3 you can try the wordpress db backup plugin.
- Log in to PhpMyAdmin
- Select the database containing your WordPress tables, note down its name
- Select the Export Option
- Select all the tables related to this WordPress installation
- Ensure you download as SQL, check the Data box, so all data is downloaded – complete and extended inserts. Check the box so you save as file and select no compression (it sometimes goes wrong).
Next you need to import this data into phpMyAdmin on your local WAMP server.
- Start PhpMyAdmin by clicking on the WAMP icon and selecting the option phpMyAdmin
- On the homepage there is an option called ‘Create New Database’, enter the name of the database from your remote server and click create.
- Click on your newly created database in the left hand column.
- Click import and browse to your downloaded file
- Click ‘go’ and all the data should be imported
- If you have problems with the size of your datafile, there are other methods – send me a mail, or add a comment and I’ll go into them. At the moment I’m trying to keep this document as simple as I can.
Next you need to set up the same username and password on this local database as is used on your remote database. You will have used these to log in to phpMyAdmin on your remote server, they are also in your wp_config file.
- Go to the homepage of the local phpMyAdmin and select ‘Privileges’
- Click the add a new user option
- Under username enter the username from the remote host, under host select localhost, under password and re-type enter the password from the remote host. Under privileges check all. Click go.
A note on user permissions – I had some issues with the host type – basically, in the wp-config file you need to check the DB_HOST entry. If the host is ‘localhost’ the user in the local mySQL should be set to host – localhost. If the host is ‘127.0.0.1’ the user should be set to host – any.
Finally, you need to change a couple of fields inside the wordpress database to ensure the correct web address is used.
- Go to the local phpMyAdmin
- Select the database containing wordpress
- Select the table wp_options
- Select browse
- Locate the option ‘siteurl’ and edit it so the option_value becomes http://localhost/local_folder_name
- Locate the option ‘home’ and edit it so the option_value becomes http://localhost/local_folder_name (this might be on the second page of database fields).
And you should now be done check http://localhost/local_folder_name.
Keep an eye out for many more WordPress tutorials over the coming weeks. I’m currently freelancing and am working on a bunch of WordPress sites for various people, as well as working on some open source themes, premium themes and plug-ins. Email me if you need any assistance – kirby [dot] mark [at] gmail [dot] com.