Motivation:
You want to move a WordPress instance from one server to another to consolidate your websites to reduce cost.
Solution:
Install and use below Duplicator plugin to achieve your goal.
https://wordpress.org/plugins/duplicator/
User guide: https://snapcreek.com/duplicator/docs/quick-start/
If everything goes well for you then congratulation!
Otherwise, please review below possible problems and corresponding solutions.
Problem 1:
You don’t have a website on the new server.
Solution 1:
1. Create a new virtual host in the /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "/var/www/www.example.com"
</VirtualHost>
2. Set 775 permission for /var/www/www.example.com
3. Restart httpd service
sudo systemctl restart httpd
Problem 2:
You are using Amazon Linux 2 server.
You are logged in as ec2-user.
You use WinSCP to upload files and edit configuration files.
You cannot modify /etc/httpd/conf/httpd.conf and /etc/php.ini.
Solution 2:
1 View permission settings for the file
ls -ld /etc/httpd/conf/httpd.conf
The result indicates that the file owner is root user and root group, not ec2-user.
2. View groups of a user
groups ec2-user
The result indicates that the ec2-user does not belong to root group.
3. Add a user to root group
sudo usermod -a -G root ec2-user
4. Grant Read-Write permission against a file to root group
sudo chmod g+rwx /etc/httpd/conf/httpd.conf
sudo chmod g+rwx /etc/php.ini
5. Logout and login to the server again.
Problem 3:
You are using Amazon Linux 2 server. The ZipArchive feature is missing.
Solution 3:
1. Execute below commands:
sudo amazon-linux-extras install php7.2
sudo yum install php-pear php-devel gcc libzip-devel zlib-devel
sudo pecl install zip-1.13.5 # we must specify a slightly older version due due to compatibility
2. Add “extension=zip.so” to /etc/php.ini
3. Restart the server
sudo reboot
Problem 4:
You don’t have a WordPress database on the new Linux server.
Solution 4:
Execute below MySQL commands:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE `wp_database`;
GRANT ALL PRIVILEGES ON `wp_database`.* TO "username"@"localhost";
FLUSH PRIVILEGES;
Problem 5:
An database error occurs while restoring a website.
Solution 5:
1. Execute below commands to remove the website:
sudo chown -R ec2-user:apache /var/www/example.com
sudo chmod 2775 /var/www/example.com && find /var/www/example.com -type d -exec sudo chmod 2775 {} \;
find /var/www/example.com -type f -exec sudo chmod 0664 {} \;
rm -r /var/www/example.com
2. Upload the Duplicator files again, and restore the website again.
Problem 6:
No write access against /var/www/example.com is available for Duplicator.
Solution 6:
1. Execute below commands:
sudo chown -R ec2-user:apache /var/www/example.com
sudo chmod 2775 /var/www/example.com && find /var/www/example.com -type d -exec sudo chmod 2775 {} \;
find /var/www/example.com -type f -exec sudo chmod 0664 {} \;
2. Run http://example.com/installer.php again.