Moved to my own server!

I’ve created a small Digital Ocean Droplet using their pre-built WordPress application image and now that DNS has fully propagated my blog is up and running.

I’ve moved from a hosting provider, who’ve been very good over the years but I want to consolidate my services to save some money. I also enjoy the challenge and control I have running my own servers, though it’s more risky as they’re directly connected to the Internet.

Firstly I used my provider’s CPanel to backup the web data to my desktop and then used phpMyAdmin to export the database and again save it to my desktop.

After some trial and error I finally got it working as I wasn’t exactly aware how WordPress and MySQL interacted the initial attempt to get it working just failed. Plus, after correctly importing the database I had connection failures.

As it was a bit of a messy process below are the steps I believe I needed to do in order to get it working:

  • Used WinSCP to copy the web data into /var/www
  • Used WinSCP to copy the .sql backup file to /root
  • Remove the default WordPress database:
DROP DATABASE wordpress;
  • Note down the database name, database user and password from the /var/www/wp-config.php file:
    • define(‘DB_NAME’, ‘<database_name>‘);
    • define(‘DB_USER’, ‘<database_user>‘);d
    • define(‘DB_PASSWORD’, ‘<database_password>‘);
  • Create a new database and MySQL user using the above information, giving said user all privileges (hope that’s not a massive security hole?):
CREATE DATABASE <database_name>;
CREATE USER '<database_user>'@'localhost' IDENTIFIED BY '<database_password>';
GRANT ALL PRIVILEGES ON * . * TO '<database_user>'@'localhost';
  • To be sure I restarted MySQL services.
  • I then imported the MySQL backup file into the newly created by empty database:
mysql -u <database_user> -p <database_name> < <path to sql file>
  • For some reason the original WordPress .htaccess file didn’t copy over so I had to add the following between the WordPress sections into /var/www/.htaccess file, I didn’t notice it was broken until I started writing this entry!:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
  • I then restarted both the apache2 and mysql services
  • One good out of the box configuration from Digital Ocean is the use of Apache’s basic authentication security on the wp-admin directory on top of WordPress’ authentication:
<DirectoryMatch ^.*/wp-admin/>
  AuthType Basic
  AuthName "Restricted Area"
  AuthUserFile /etc/apache2/.htpasswd
  Require valid-user
  • To make sure I can restore the website if problems occur I’ve created a simple cron.daily script which archives the relevant data areas which I’ll then rsync back to my FreeNAS box:
/usr/bin/mysqldump -u <database_user> -p<database_password> <database_name> > /var/backups/<database_name>_backup.sql
tar -cpzf /var/backups/wordpress_backup.tar.gz /var/www

All is working apart from being able to update my plugins which is what I’ll investigate next.

UPDATE: I got my plugin update issue resolved. For some reason the ownership of the directories and files within the /wp-content/plugins/ directory were wrong. Running:

chown -R www-data:www-data /var/www/wp-content/plugins/*

Fixed the issue!

Leave a Reply

Your email address will not be published.