Super Fast PHP WordPress Plugin development with VVV

This is just a quick shoutout to the virtualization app which is helping me a lot with my LED-WEBSITE-INDICATOR plugin development.

Check out https://github.com/Varying-Vagrant-Vagrants/VVV

The VVV project uses VirtualBox in the background to automatically set up a WordPress development environment, including two working WordPress sites to play with. The whole thing is done for you, all I had to do was copy my plugin to the shared folder and every change was visible on the working local site.

If you are getting into PHP and WordPress, check out the project, I won’t say any more about it, just try it already!

DigitalOcean: Migrating WordPress Websites from Ubuntu Server 16.04 to 20.04

As you probably know (see the banner above) I am a happy user of DigitalOcean for many years now – I host multiple websites on a single server without any hassle. They don’t get that much traffic – 1000 or so hits a month for this one for example – so I’m happy sticking with the $5 per month offering for now.

Ubuntu 16.04 is reaching end of life!

It’s time for an upgrade! According to the DigitalOcean documentation it is not recommended to upgrade in-place (do-release-upgreade in the terminal)… I tried and stuff broke, so that is good advice. Luckily I have backups enabled for an extra $1 per month only, so restoring the server was a one-click affair. Now I have a new droplet and need to migrate ALL of my sites to it one by one.

Migration Notes:

  1. I followed this excellent tutorial: https://medium.com/@christoph.schmidl/how-to-manually-backup-wordpress-daa43e37a9bd to backup the mysql database and wordpress folder (/var/www/mysite) – but used wget on the new server to fetch the archives directly.
  2. I had to revoke the letsencrypt https certification – https://maximef.com/2020/10/21/how-to-delete-certbot-certificate-by-domain-name-lets-encrypt/ – don’t forget to remove old files left behind
  3. In the DigitalOcean dashboard, point the url to the new droplet
  4. Create new virtual host files and enable in apache (a2enmod sitename.com) – to learn more about using apache virtualhost files to host multiple sites on one server see: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04 – it’s the same for 20.04
  5. I had an issue with the WordPress database but found out that all that’s needed is to match the wordpress wp-config.php information to the mysql database and user info. This tutorial was helpful (if a bit out of date, the procedure for creating a user has changed…) https://www.vultr.com/docs/troubleshooting-wordpress-database-errors
  6. Create new LetsEncrypt https cert – see #2 link, using certbot.
  7. And everything works (hopefully)

Tweaking the server:

I had some issues with the Ubuntu Server being a bit slow sometimes – think I used the one click WordPress install. It seems that there are ways to optimize this – here is a great link to some ideas about this:

  1. Add swap: https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04
  2. More settings for swap: https://bitlaunch.io/blog/how-to-create-and-adjust-swap-space-in-ubuntu-20-04/

Now my server is running smoothly, it’s time to migrate this blog. Or have I done it already? I doubt you would notice!

How To Fix the dreaded “Error Establishing A Database Connection” In WordPress

This is just a quick post to note what worked for me. I found loads of tutorials online but none of them had the full story.

Essentially I had to change my database password. Here is what I did:

Assuming you have ssh access to your DigitalOcean Ubuntu droplet:

Fictional Database Name: wordpressDB

Fictional WordPress User Name: wpUser

Fictional Password: 12345

Open your wordpress wp-config.php (usually located at /var/www/html) and change the password, and make a note of the database name and user.

nano /var/www/html/wp-config.php

define( 'DB_PASSWORD', '12345' );

Now change the mySql database details:

mysql -u root -p

use wordpressDB;

UPDATE wp_users SET user_pass = MD5('12345') WHERE ID=1 LIMIT 1;

grant all on wordpressDB.* to 'wpUser'@'localhost' identified by '12345';

flush privileges;

exit;

Conclusion

Anyway that’s what worked for me, hope it helps someone at some point (probably me, in the future). Generally WordPress is pretty stable, this is the first time I encountered this problem.