Geek Friday: Testing Your WordPress Backup and Create a Local Test Site Using XAMPP and BitNami
I recently posted an article on “Review: Backup WordPress Site With XCloner“, which is a nice tool that can be used to backup your WordPress site. You have to remember that with a WordPress site you have to backup not just the files but also the database. In some ways, the database is more important than the files, although you really need both to run. However, the database is what actually contains your user table, your posts and your pages.
However, once you have it backed up and downloaded, then what? I mean, you did download it, right? Otherwise, is it really a backup? How do you know it works? Well, what I used to do was have a test website that I put things like this on just to test out whether or not the tools were working. And, it isn’t the worst thing you can do with the backups, either. It also gave me an opportunity to play around with proposed changes (to the site, that is, not the backup!).
Still, how often is that needed? Is it worth paying out more money in order to have a test site? Even if you are a professional developer, you won’t necessarily want to do any work on a live site, and having duplicate content on the web for too long of a time can hurt whatever site you are working on.
Unless you are severely restrained by the hardware or software on your computer, there isn’t much of a reason to not have the ability to view your WordPress site on your own computer.
“But, I don’t know how to set up a WordPress site on my computer,” you might be saying. Neither did I until recently.
More important, there needs to be a method for doing so, regardless of whether or not you are running Windows, Mac OS X or Ubuntu. It needs to cost effective, and I’m sure there are a lot of solutions out there that would cost an arm and a leg. It needs to be at least somewhat easy. While it doesn’t necessarily need to hold your hand, it should give you enough basics to at least be able to check out your site.
Fortunately, such an animal actually exists! It’s put out by Apache Friends, and the package name is XAMPP. Perhaps, you have heard of it referred to as LAMP, an acronym for Linux, Apache, MySQL and PHP. Sometimes, it was called LAMPP for Perl and/or Python added. The ‘L’ was changed to ‘X’ to indicate cross-platform compatibility.
I should add here that you can do this without the XAMPP package, but you would have to download these items separately and set them up yourself. It is important to remember that, while they are often used together, they are independently developed applications.
The following are from my various memories and notes from instaling it on Ubuntu 13.04, but I believe in general should apply to all except in the smallest of details.
I pretty much followed the series of steps given on the ManageWP blog in the article “How to Create a Local WordPress Website in Windows with Xampp“, or more precisely I should say I followed the first three steps. I pretty much ran through the install of XAMPP, and it automatically started the services needed for an initial web server. I then created a target database specifically for WP. I prefer to use the same name as the real one to reduce confusion, but that is my preference. However, it should be related to the name of your blog to keep yourself sane, and that goes double if you have more than one site.
As an additional note, the default of XAMPP sets it all up without passwords. I did try to put a password just on the one database, but I couldn’t get that to work. At any rate, I recommend shutting down the XAMPP services when not in use, anyhow.
However, when I got to step 4, I was surprised they wanted me to download directly from WP, when BitNami for XAMPP makes ready-made packages of WP, Joomla! and Drupal to make setup easy. Just point the WP installation of your local website to the database you created in the last step when you get to the point of restoring your backup locally.
Now, you will need to create the directory for your wordpress site. Again, select a name related to the name of your blog for sanity’s sake.
When BitNami installs WordPress, it probably put WP under /opt/lampp/apps/wordpress/htdocs (substitute “/opt/lampp” with “C:\xampp” if in Windows; OS X is really a form of Unix, so “/opt/lampp” should apply there as it does in Ubuntu). You do not want to put it there, however, so don’t get confused.
Instead, there should be an “htdocs” directory also right under the lampp or xampp directory. So create a directory under /opt/lampp/htdocs to put your blog. Remember, if you have more than one blog, then it will be confusing if you don’t give the directory a meaningful name. So, as an example, for this blog, I could create a directory “johndscomputers” by going to a command line and typing “sudo mkdir /opt/lampp/htdocs/johndscomputers” then pressing [Enter].
Now, copy in your backup files from XCloner. Of course, if you used a different backup program, you’ll need to follow the directions for that program. You should copy in TAR.php, XCloner.php and of course the .tar file that XCloner created. Then, in the address bar, address the subdirectory of “localhost”, which is an alias for your particular machine, followed by the XCloner.php file. In my example, I would type “http://localhost/johndscomputers/XCloner.php”. After putting in the address, press the [Enter] key, and you should get a screen like the following:
About half of the defaults should suffice. You will need to specify user name (normally root) and the database name. Be sure to put in the database you created for this particular WP installation. When all looks well, click on Start install.
After the files extract, you should get the “Files successfully copied” message. Be sure to check for errors. Then, click on the smaller (!) text to continue the database import. In many cases, this import will take significantly longer than the file extraction. It should finish with “The sql import is finished!”
If you receive errors during the file extraction, you might want to try using an FTP utility like the excellent Filezilla in order to download the tar file manually to see if it is getting corrupted during the download process. Unfortunately, this is a common occurrence with file downloads through a web browser, but nevertheless it shouldn’t occur.
If you have permalinks set on, you might only be able to navigate your home and admin pages. First of all, remove the .htaccess file or at least be sure it has read-write access. Go into the wp-admin page, go to Settings | Permalinks, copy your current settings, change to Default, click on Save Changes, set them back using the settings you copied and click on Save Changes again.
You should now have a working copy of your WordPress site on your local machine. Enjoy!