Wp Backup Migrate
Basic Backup or Migration Protocols for WordPress Sites
A protocol for backing up and/or migrating a Wordpress site.
Future
- Integrate Install Needs section into ansible for ubuntu 16.04 systems.
Backup
Components
This is the same pattern for any modern web application framework.
- MySQL Database
- Project Directory
Backing up the MySQL Database
-
Get the following from the
wp-config.pyp
:- Database Name
- Username
- Password
-
`mysqldump {Database Name} > ~/backups/mywpsite.bkp.yyyymmdd.sql -u {Username} -p
- Enter password at the prompt
Backing up the Project Directory
tar -czvf ~/backups/myproject.bkp.yyyymmdd.tar.gz /my/project/root/directory/
Migration
Do these in order.
-
Back up the site and copy the
tar.gz
and thesql
files to the new location -
Rebuilding the project
- Unzip the
tar.gz
file into/var/www/websites
- The full path should be
/var/www/websites/www.example.com/www/{wordpress root}
- The full path should be
- Change the permissions of this path:
chown -R www-data:www-data {path}
- If you wish to traverse symlinks, use
-H
flag.
- If you wish to traverse symlinks, use
- Make a symlink at
/var/www/www.example.com
to/var/www/websites/www.example.com
- Saves tons of work later if you need to redirect to another location
- Unzip the
-
Set up the MySQL user, database, password on the new location
- Login to MySQL as the root user:
$ mysql -u root -p
- enter password at prompt
create database {Database Name};
create user '{User}'@'localhost' IDENTIFIED BY '{Password}'
- Does the next step create the user automatically if you don't do this?
grant usage on {database}.* to '{User}'@'localhost' identified by '{Password}';
- view your changes:
mysql> select user, host, password from mysql.user;
mysql> FLUSH PRIVILEGES;
thenmysql> quit;
- Ensure the
wp-config.php
has the same Database Name, Username, Password - Move the
sql
file to the wordpress root directory $ wp-cli.phar db import mywpsite.bkp.yyyymmdd.sql
- wp db import
- You need wp-cli.phar on your path if it is not already
- Alternatively put a copy in local directory or specify
/path/to/wp-cli.phar
- If your WordPress site URL has changed
- Update the database with wp-cli
wp-cli
is usually aliased towp
wp-cli.phar option update home 'http://www.example.com'
wp-cli.phar option update siteurl 'http://www.example.com'
- If you have urls in your posts, pages, etc.
wp-cli.phar search-replace 'example.dev' 'example.com' --skip-columns=guid
- Update the database with wp-cli
- Login to MySQL as the root user:
-
Configure and restart apache2
- Use a template!
- Generally I just copy another site that follows the same pattern
- Then search and replace your new website name
- Store in
/etc/apache2/sites-available/{mywebsitename}.conf
- Make sure your apache logs exist in
{projectdirectory}/logs/
- For more info, check the path in your apache config file
access.log
,error.log
a2ensite {mywebsitename}
thenapache2 restart
- Use a template!
-
If you have errors, fix this configuration as you fix the error.
- WP Codex - Changing The Site URL
WordPress Requirements
WordPress requires a great many packages and configuration settings. Here are some packages that were installed manually on a Ubuntu 14.04 server in the past.
apt-get install postfix
- This is important so WordPress can send mail (doesn't need a real outbound address)
- This needs configured more completely to try to evade spam filters
- DigitalOcean WordPress Email Reference
- FUTURE: There are alternatives like going through a gmail acount with wp-smtp plugin
- FUTURE: WordPress Contact Form 7 Spam Reference - Apparently there are some nice tricks to avoid being treated as spam?
- Set up apache2 Virtual Hosts
- Set up mysql root user
- Set up php5 modules for apache2
- Set up mod-rewrite for apache2
- More...
- Fix the php upload file sizes
- Directory/File permission fixers (files vs dirs, see snips) for annoying hosts.
- Other snips from my snips git repo