Some years ago, I got an offer for managed wordpress that I could not refuse: unlimited instances, disk space, traffic, databases, etc. I was fairly happy until I wanted to share a MySQL database outside the service provider’s private network. Well, I couldn’t, because I didn’t have access rights to configure the firewall. So I ordered the cheapest SSD VPS by contabo as an alternative. I chose PHP-FPM for security reasons, e.g., containing script execution to a single user.
NOTE: WP provides guidance on how to migrate a WP instance. Here, following assumptions are made:
- A single WP site is being migrated
- Domain name stays the same
SSHaccess to server is given
Prepare new server
For a debian 10, that I’m using, at least the following packages need to be installed:
apt install \ php7.3-fpm \ php7.3-mysql \ nginx \ mariadb-common
Backing up old instance
Although there’s an official WP guide on how to backup data, I wanted to have it automated and uncomplicated.
The result was a single bash script
Now you can backup as follows:
# Log on to your server # copy wp-script.sh over mkdir backup && cd backup ./PATH/TO/wp-script.sh PATH/TO/WP-DIR
Log on to your new server and
scp the backup data from previous step over into the home directory of created user:
scp -r OLD_SERVER:/PATH/TO/backup /home/example_com
To quickly restore DB and WP files as well as configuring NGINX and PHP-FPM,
wp-restore.sh can be used:
Restoring is as easy as:
./PATH/TO/wp-restore.sh example.com PATH/TO/BACKUP
This script changes the system as follows:
- A system user corresponding to given domain name is generated, e.g.,
- Compressed WP files are extracted to a directory under home directory of the newly created user, e.g.,
- A new SQL user is added and is filled with the previously created dump
- A PHP-FPM configuration file is generated and activated
- A new NGINX block is generated and activated
You’re not done before you get some fresh new certificates for your wordpress instance.
Go ahead and install
certbot and run the following:
certbot --nginx\ -d example.com -d www.example.com\ --server 'https://api.buypass.com/acme/directory'
This would fetch a new certificate from buypass, a european alternative to Let’s Encrypt, and automatically configure your nginx block.