Get the original files
- On the original server open the Duplicator plugin
- Create a new package and change the file name to the current date
- Download both files -
installer.phpand thearchive.zip
Prepare the new server
-
Get the current
phpandmysqlversionsphp -v # PHP 7.4.30 mysql --version # mysql Ver 8.0.19 -
Install PHP
# Add PHP repository sudo add-apt-repository ppa:ondrej/php sudo apt update # Install PHP 7.4 and required extensions sudo apt install php7.4 php7.4-cli php7.4-common php7.4-curl php7.4-mbstring php7.4-mysql php7.4-xml php7.4-zip php7.4-fpm libapache2-mod-php7.4 # Verify installation php -v -
Install MySQL
# Add MySQL repository sudo apt install software-properties-common sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29 sudo add-apt-repository 'deb http://repo.mysql.com/apt/ubuntu focal mysql-8.0' sudo apt update # Install MySQL 8.0 sudo apt install mysql-server # Verify installation mysql --version -
Install apache2
sudo apt install apache2 sudo systemctl status apache2 -
Install other utilities
sudo apt install unzip sudo apt install certbot python3-certbot-apache
Upload files and configure Apache2
-
Upload the
archive.zipto this location (this might take a while):scp /Users/marko/Downloads/archive.zip root@<new_domain>:/root -
Create the new website directory:
sudo mkdir -p /var/www/<new_domain> -
Unzip the files
sudo unzip /root/archive.zip -d /var/www/<new_domain> -
Upload the installer file to the new directory
scp /Users/marko/Downloads/installer.php root@<new_domain>:/var/www/<new_domain> -
Change the ownership and permissions of the files:
sudo chown -R www-data:www-data /var/www/<new_domain> sudo find /var/www/<new_domain> -type d -exec chmod 755 {} \; sudo find /var/www/<new_domain> -type f -exec chmod 644 {} \; -
Go to the original server and copy the contents of
/etc/apache2/sites-available/<old_domain> - Connect to the new server and create a file
/etc/apache2/sites-available/<new_domain>and copy the contents of the file from the old server into it# Enable the site sudo a2ensite <new_domain>.conf # Enable required modules sudo a2enmod rewrite sudo a2enmod headers # Test the configuration sudo apache2ctl configtest # Restart Apache sudo systemctl restart apache2
Create the database
sudo mysql -u root-
Run the following commands and replace where necessary:
# Create the database CREATE DATABASE <DB_NAME>; # Create the user CREATE USER '<DB_USER>'@'localhost' IDENTIFIED BY '<DB_PASSWORD>'; # Grant privileges to the user GRANT ALL PRIVILEGES ON <DB_NAME>.* TO '<DB_USER>'@'localhost'; # Apply the changes FLUSH PRIVILEGES; # Exit MySQL EXIT;
Install the website from the archive
- Open
<new_domain>/installer.phpin your browser and run the installer by clicking Validate and then Next - Go to Settings > Permalinks and save (to refresh permalink structure)
- Clear the browser cache and test that everything works like before
- Remove duplicator installation files in the Duplicator settings
Optional: migrating domains
If you want to rename a WP server's domain do the following steps:
-
Install
wp-clicurl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # verify the file php wp-cli.phar --info # make it executable chmod +x wp-cli.phar # move it to a Directory in Your PATH sudo mv wp-cli.phar /usr/local/bin/wp # test the installation wp --info -
Change database entries using the
wpcommandsudo -u www-data wp --path=/var/www/<new_domain> search-replace 'http://<old_domain>' 'https://<new_domain>' --all-tables -
Update
wp-config.php:define('WP_HOME', 'https://<new_domain>'); define('WP_SITEURL', 'https://<new_domain>'); -
Rename folder in
/var/www/<old_domain>to/var/www/<new_domain> -
Update the
apache2configmv /etc/apache2/sites-enabled/<old_domain>.conf /etc/apache2/sites-enabled/<new_domain>.conf -
Update the domain inside of the config
sudo nano <new_domain>.conf -
Clear caches & reload apache
sudo -u www-data wp cache flush sudo systemctl reload apache2
Enable https on the server
-
Install Certbot with the following commands:
sudo apt update sudo apt install python3-pip python3-dev python3-setuptools python3-venv python3 -m venv /opt/certbot source /opt/certbot/bin/activate pip install --upgrade pip pip install certbot certbot-apache sudo ln -s /opt/certbot/bin/certbot /usr/local/bin/certbot # verify install certbot --version -
Change the DNS record for the new domain to point to the new server
-
Run the following command to create https certificates using certbot:
sudo certbot --apache -d <new_domain> -d www.<new_domain> -
Run this command to check if automatic certificate renewal works:
sudo certbot renew --dry-run
Testing if everything works
- Open
tail -f /var/log/apache2/<new_domain>.access.logon the new server - Open the website in your browser and check if the access log updates
Troubleshooting
Assets are loading over HTTP instead of HTTPS
- Check the
wp-config.phpfile and validate that the domain containshttpsand not justhttp! - Install the Better Search Replace plugin and replace all
http://<old_domain>withhttps://<new_domain>