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

Cisco Rev up to Recert

Cisco really came in to save the day here with certifications expiring in August. Normally you have to pay for a subscription to Cisco U to get access to Continuing Education credits to recertify Cisco certifications. End of June they announced this program that’s good thru August 31 where it’s free to get up to 56 credits by completing three courses.

I only needed 32 credits to recertify my CCNA so I completed the Cisco Secure Network Analytics and Cisco Secure Cloud Analytics course… plus the Network Automation course which covered Python, APIs, Ansible, DevOps, Git. I actually learned a lot and it helped me improve my understanding of infrastructure automation. Took about 8 days of 4-8 hour sessions.

This gives me much more time to prepare for my CCNP instead of the rapidly approaching expiration date of Aug 23, 2023 for my CCNA. Now my CCNA is good until 2026 and I really should start my CCNP after I get a couple of AWS and Azure SA certs this season.

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.