Welcome to part two of a two part series of articles that will guide you through the process of installing a fresh copy of WordPress or your public WordPress blog to your local machine. The first part of this series covered the installation and configuration of WampServer. Now it’s time to move on to the hard, technical stuff.
Installing WordPress Fresh:
One thing you must know before we move on is that, by default, your database username is ‘root‘ and the default password is blank. In other words, there is no password assigned to the username of root. This would be extremely insecure if this web server were made available to the public but because it’s assigned to the local address of your machine, you have nothing to worry about.
To begin, left click on the WampServer icon and select PHPMyAdmin. Where the text labeled CREATE NEW DATABASE is located, type in the name of the database that will house your installation of WordPress. For simplicity, I normally call the database wordpress. Then click on the Create button. We now have an empty database that the WP installation files can work with.
Download the latest version of WordPress, then extract the files to your desktop. Open the WordPress folder and look for WP-Config-Sample. Open this file in your preferred text editor. The DB_Name is the name of the database you created for WordPress. The DB_User is root. The DB_Password is blank. These three values are the only ones you’ll have to change. Once those changes are in place, save the file as WP-Config.PHP
If you want to install WordPress into the ROOT directory as you would on a public web server, take all of the files and folders within the WordPress folder and move them into the WWW folder. WWW is the same as Public_HTML and is the folder which houses all of your web documents. If you don’t want to install WordPress into the root directory, create a new directory and place all of the files into that one. Just make sure the files are within the WWW folder, or else they won’t be accessible.
Once that’s finished, point your browser to http://localhost/wp-admin/install.php Follow the directions as they are pretty self explanatory and when your finished, you’ll have a fully functioning, fresh install of WordPress that you can do whatever you want with.
Migrating WordPress From Public To Localhost:
Migrating an existing WordPress install onto your local computer is not as easy as a fresh install. If you haven’t already, make sure you have made the appropriate PHP.ini file changes that were explained in part 1. If you don’t, you will run into numerous errors about the SQL file being too large to import.
In my circumstance, my webhost offers it’s customers Cpanel as a means to control all aspects of my Webhosting account. Cpanel provides me with a way to generate a full backup of my domain. This backup includes all of the hardcoded directories and files attached to my domain as well as any databases I have created. After you create a full backup of your domain through Cpanel (if you have that option) download the backup to your desktop. Once downloaded, open up the file and browse to the Public_HTML directory. Extract this directory’s contents into the WWW folder on your hard drive.
Once thats finished, look inside of the mysql directory within your backup file. This directory contains all of the MySQL databases you have created through your webhosting account. Extract the SQL file that pertains to your WordPress install and place it on the desktop.
Ok, before we move on, lets review where we’re at. We backed up all of the files related to the hosting account and then downloaded that file to the desktop. We then extracted all of the files within the Public_HTML directory into the WWW directory. We then looked inside of the backup file and extracted the SQL file that pertains to the WordPress installation. At this point, the folder structure within the WWW folder on your hard drive should mimic that of what you would see within the Public_HTML folder on your webhost.
Now, left click on the WampServer icon and click on PHPMyAdmin. Click on the link that says IMPORT. Click on the BROWSE button and locate the SQL file you extracted to your desktop that pertains to your WordPress installation. After you locate and double click on the file, click on the GO button. It might take a little while, but the import process should be successful. If you receive an error that states the SQL file was too large, please re-visit part 1 and make sure the changes were saved to your PHP.ini file. Also, I wanted to share that if you have the SezWho comment rating plugin installed, you may receive errors that are related to the plugins database tables. If this is the case, you will need to open the SQL file in a text editor and remove all of the lines that pertain to those tables which are usually prefixed with sz_ and then try to import the SQL file again.
If the import was successful, pat yourself on the back because were almost through with this process.
If you do not want to do the next step through the database you can instead, add these constants to your WP-Config file and they will perform the same function as the database edits.
define('WP_HOME', 'localhost' );
In PHPMyAdmin, the database you imported will now be selectable in the drop menu that is located near the top left portion of the webpage. Click on the drop down arrow and select the database you just imported. Near the top center of the page, there will be a series of tabs. Click on the SEARCH tab. In the search box, type in the full URL to which your public WordPress install refers to. In my case, I typed in http://www.jeffro2pt0.com This will search the entire database for entries of that domain. The search results should find entries related to that domain within the table WP-OPTIONS. Click on the Browse link to dig into this particular table.
You only need to concern yourself with the top two entries, SiteURL and HOME. Click on the Pencil icon for SiteURL which is just to the left of the X icon. This will open up the editing page. In the large text box on the bottom, change the URL to http://localhost then click on the GO button. Now do the same thing for HOME. After you change HOME, you can exit out of PHPMyAdmin.
If you have never opened the .htaccess file to hard code redirection attributes, you can skip the next step and you are essentially finished.
The last thing to do is to edit the .htaccess file and remove any hard coded redirection attributes. If you don’t do this, each time you try to load your blog on your local machine, it will automatically redirect to your public blog or which ever URL you configured in your .htaccess file.
If you’ve managed to read this far, congratulations. After all of that, you should be able to access and browse your blog on your local machine exactly how you would in a public domain. This guide is by no means a cure for all. This was my detailed approach as to how I migrated my public install to a local install. Some of the actions I performed may not have been necessary, nor required, but this is the way I did it and it worked!
If you have a correction or a different way of doing things, by all means leave a comment. I will edit this article as corrections come in so the most accurate information is presented.
Also, now that you have the ability to dig around the ins and outs of your blog through the database, you’ll be able to see some things that you might not of known about before. Stay tuned for another article which highlights a VERY important issue pertaining to plugin developers that needs to be discussed. Perhaps we’ll be able to come up with a solution.