Local backup of wordpress files and mysql db, using tar and mysqldump

Wrote a quick script to make a copy of files + db

#!/bin/bash

cd /srv/www/wordpress
tar -zcvf ~/backup-$(date +"%Y%m%d").tar.gz *
cd
ls backup-*
sudo mysqldump -u root --password="<insert password>" wordpress > ./mysql-$(date +"%Y%m%d").backup
ls mysql-*

Certbot / SSL / LetsEncrypt

The WordPress healthcheck was complaining about REST API and curl error 7. I narrowed it down to a SSL problem based on the error msgs complaining about no response on port 443. Weird as I didn’t have this problem yesterday.

Despite setting up my DNS with cloudflare and having traffic proxied under their SSL tunnel, it is not a true SSL connection. I figured this out when I “curl https://localhost” or “curl https://adrianng.com” and it said connection refused. (The cloudflare proxy only encrypts the traffic between the client’s browser and cloudflare’s server. The traffic between cloudflare and my web server was still unencrypted.)

I ended up using cerbot / letsencrypt to install a SSL certificate on this web server:
sudo snap install core; sudo snap refresh core
sudo snap install –classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot –apache

This successfully setup a certificate on the server and the site was SSL enabled. “curl https://adrianng.com” proved this as now I get a proper response. However on the web browser, I was getting too many redirects.

To fix this, I went into my cloudflare dashboard, SSL/TLS and found this screen:

Changing it from Flexible to Full (or even Full strict) made it work again.

Site is slow after a while – Adding a swap file

Continuing from the previous post about migrating this site to an Azure VM… I noticed the the site’s performance was horrendous on the free B1s VM size 1CPU 1GB.

I increased the VM size to B1MS 1CPU 2GB which takes me out of the free tier but so far it seems to work. But in the interest of going back to free tier, I’m going to want to go back to the 1GB VM size. I’ll need to look into this some more.

So it turns out the Azure Ubuntu VM by default doesn’t have a swap file. This appears to be the reason why the VM bogs down and runs out of memory. I checked the site this morning and it wasn’t responsive at all. Azure portal showed it had 35Mb of RAM free.

So I just created a swap file and rebooted. Let’s see if this works. So far so good.

Create 2GB file in root directory called swapfile:
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress

Give only system permission:
sudo chmod 600 /swapfile

Make it a swap file:
sudo mkswap /swapfile

Turn on swap file:
sudo swapon /swapfile

Make persistent by editing /etc/fstab and adding swapfile entry:
sudo nano /etc/fstab
“/swapfile none swap 0 0”

Reboot:
sudo reboot

Site Migrated from Arvixe VPS to Azure VM

Just migrated this blog from a cPanel VPS provider to my own Azure VM running on Ubuntu/Apache/MySQL. If you’re seeing this, then the migration worked!

Followed these instructions to install apache, wordpress, and mysql. https://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview

Followed the Site Health and updated chmod 444 for .htaccess and wp-config.php from 666 and 644 respectively.

Originally tried migrating the content using Migrate Guru Plugin since it seemed easier, but it failed.

Finally migrated the content using All in One WP Migration Plugin.

Upon completion I deactivated the All in One WP Migration Plugin and immediate lost access to admin panel. Had to add some lines of code to the wp-config.php file above the require once call

if (isset($_SERVER[‘HTTP_X_FORWARDED_PROTO’]) && $_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’) $_SERVER[‘HTTPS’] = ‘on’;

Surprisingly the performance has been horrendous on a B1s so I just upgraded to B1ms. I suspect there’s some mysql tuning that needs to take place to prevent it from hogging over 50% of system memory. Will leave it at 2GB ram for now and come back to this later.

Upgraded to PHP 7.4

WordPress had been complaining about the outdated PHP 5.x on my WordPress site for quite some time. Admittedly, I should have looked into it but for some reason I thought it was something I had to ask my hosting provider to do.

Writing this now I looked through my emails and it turns out I did ask them… back in 2021. At that time they advised me 7.4 isn’t available on their shared servers.

In any case, I happened to look into it tonight and found in my cPanel MultiPHP Manager. Upon clicking in there, it was just a matter of selecting my site and selecting PHP7.3 or PHP7.4 and clicking apply.