I move WordPress from Ubuntu Server 21.04 to 23.04 with several easy steps. Here are the quick guideline on how to migrate WordPress safely without breaking
First, Backup all necessary data
Open your terminal and start with your home path ~/
sudo mysqldump -u root -p yourdb > db.sql
Second, Compress etc, home and any folder needed
sudo zip -r /etc etc.zip
sudo zip -r /home/ubuntu
Transfer the file to the new server. If you need to use pem-key and using either windows or linux, use SCP to transfer pem-key from local computer to old-server. This is needed so you can transfer file from old to new server
scp -i .\your-key.pem -r .\your-key.pem ubuntu@your-ec2-server-ip:/home/ubuntu
Now your key pem is exists in home path in old server. Its time to transfer the whole zip files backup to the new server home path
scp -i your-key.pem *.zip ubuntu@your-new-server-EC2:/home/ubuntu/
Once its done, you just need to extract the folder and replace whatever needed configuration and databases to the new server.
If you encountered by permission denied (13) on NGINX,
/php/php8.0-fpm.sock:", host: "www. com"
2023/04/23 16:31:33 [crit] 17224#17224: *28 stat() "/home/ubuntu/" failed (13: Permission denied), client: 22.214.171.124, server: .com, request: "GET / HTTP/1.1", host: "www. .com"
2023/04/23 16:31:33 [crit] 17224#17224: *28 stat() "/home/ubuntu/" failed (13: Permission denied), client: 126.96.36.199, server: .com, request: "GET / HTTP/1.1", host: "www..com"
2023/04/23 16:31:33 [error] 17224#17224: *28 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 182.25352.107, server: .com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.0-fpm.sock:", host: "www..com"
the quickfix solution
sudo gpasswd -a www-data ubuntu
chmod o+x YOUR-WEBSITE-FOLDER
sudo service php8.1-fpm restart
sudo service nginx restart
Done! Now you can smoothly migrate WordPress from the old ubuntu server to the new ubuntu server without problem. The last step is to change the IP-address in NS. If you are using AWS Route 53, just change the IP address in the record and you are ready to go!