You’ve just thought of a great new layout for your blog… but making changes to your blog while visitors are accessing it is generally a bad idea, especially if you are running an ad-supported blog. This How-To shows you the list of steps you need to take to get a copy of your production WordPress blog copied down to your local Ubuntu machine. (Should work for any debian linux)
First, we’ll need to make a copy of your current WordPress blog. I’m going to assume you have access to the console at your hosting provider, or they at least have some type of backup provided for you. If you get your backup files a different way you can skip that step.
For a blog, we’ve got both the WordPress installation as well as the database, where the text of all your posts are actually stored. If you’ve uploaded images or files, they will be in your wordpress folder structure, so we really need both.
1) Let’s get a backup of the database first. Connect to the server via SSH and run the following command:
mysqldump -uUSERNAME -pPASSWORD -hSERVER DATABASENAME > dbbackup.bak
Naturally you’ll want to substitute the uppercase text for the correct values on your installation.
2) Make a backup of the file structure:
tar -cf sitebackup.tar SITEROOTDIRECTORY
You’ll want to substitute the uppercase text for the root directory of your site.
3) Copy the files down to your local Ubuntu machine. This can be done via scp, ftp, or however you feel like it. I’ll leave that up to you.
4) Make sure you have apache, php and mysql installed. If you don’t, you can consult the other how-to guides on this site, or just type in the following commands at a terminal prompt:
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get mysql-server
sudo apt-get php5-mysql
sudo /etc/init.d/apache2 restart
5) We need to create a database and import the original database that we backed up. Navigate to the folder that you downloaded the files to and run these commands:
mysqladmin create DATABASENAME
mysql -uroot DATABASENAME < dbbackup.bak
6) Make our local webserver point to the copy of WordPress we got off the production server. First, we’ll want to extract the tar archive that we created. You can do that however you want, but I prefer the command line. There is a utility built into Ubuntu to allow you to do so graphically if that’s the way you like to do it.
tar xvf sitebackup.tar
This will produce a directory structure similar to the one on the server you were on. We’re going to imagine that your site root directory is now in /home/username/wordpress/ for the purposes of this article. If you’ve extracted it elsewhere, then substitute accordingly. We need to add in the alias into apache, so open up the following file:
You’ll want to paste in these lines, and adjust the paths according to your system and the /directory you want the test blog to be available on.
Alias /wordpress /home/username/wordpress
Options Indexes FollowSymLinks
Allow from all
7) If you are using Permalinks, you’ll want to duplicate the same thing locally, and will need to enable mod_rewrite:
ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
8) Now we’ll need to edit the wp-config file to point to the local database. If you’ve been following along, these settings should work for you once you substitute the database name.
// ** MySQL settings ** //
define(‘WP_CACHE’, false); //Added by WP-Cache Manager
define(‘DB_NAME’, ‘DATABASENAME’); // The name of the database
define(‘DB_USER’, ‘root’); // Your MySQL username
define(‘DB_PASSWORD’, ”); // …and password
define(‘DB_HOST’, ‘localhost’); // …and the server MySQL is running on
9) If you are using the using WP-Cache caching module, navigate to your blog root directory and run these commands:
ln -s wp-content/plugins/wp-cache/wp-cache-phase1.php wp-content/advanced-cache.php
chmod -R 777 *
10) One final thing left to do. The data in the database still has the wrong URL for your blog. The easiest way to fix this is by running a SQL statement against the database. Create a new text file named fixsettings.sql, copy the following lines into it, substituting your own IP address for localhost if you want other people to connect to you:
update wp_options set option_value=’http://localhost/wordpress/’ where option_id=1;
update wp_options set option_value=’http://localhost/wordpress/’ where option_id=40;
Now we’ll import that into the database:
mysql -uroot < fixsettings.sql
Note that you should keep that file around, because any time you want to update your local copy with the latest blog posts, all you have to do is import the database backup file, and then re-run this fixsettings.sql file to make it point locally again. Definitely makes things a lot simpler, and you can eventually schedule a cron job to backup your production blog and pull it into your local machine on a schedule.
Now you should be able to navigate to http://localhost/wordpress/wp-admin/ and login with your regular username. You’ve now got a development copy of your blog!
- › How to Generate Unlimited DALL-E AI Images for Free (With Bing)
- › The Best Free Apps for Your Windows PC
- › Adobe Is Testing “Firefly” AI Image Generation
- › DALL-E Image Generation Is Coming to Bing Chat
- › You Can Now Join the Waitlist for Google’s “Bard” AI Chatbot
- › How to Protect Your Images From AI Art Generators