A Cloud Instance of WordPress

wordpress cloudUsing most of the same routines as in my previous article, I installed Nginx, MariaDB, PHP and WordPress on a cloud instance of Linode. All the instances are called linodes, coincidentally, except for the smallest one. It’s called a nanode, featuring one CPU and one gigabyte of memory, and that’s the one I selected. I had to make configuration file changes for the database server, so that it wouldn’t try to use more memory than what was available.

I’ll see how long I can use an instance of this size. Upgrading to the next level isn’t difficult. This level costs me a mere $5 a month. The next level is $10 for two gigabytes of memory. The level above that jumps to $20 for two CPUs and four gigabytes of memory. It’s still affordable. Upgrading won’t be necessary unless I get a lot of traffic, which is something I don’t see happening. Until then, I don’t intend to pay for more than what I need.

Cloud Differences

The Nginx server configuration was different from what I used on my laptop computer, obviously. I had to use a basic port 80 configuration until I got my SSL certificate, but this is the configuration I ended up with:

server {
    listen 80            default_server;
    listen [::]:80       default_server;
    server_name          domain.tld www.domain.tld;
    access_log           off;
    error_log            /dev/null;
    return               301 https://domain.tld$request_uri;
}
server {
    listen 443           ssl http2;
    listen [::]:443      ssl http2;
    ssl_certificate      /etc/letsencrypt/live/domain.tld/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/domain.tld/privkey.pem;
    include              /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam          /etc/letsencrypt/ssl-dhparams.pem;
    server_name          www.domain.tld;
    root                 /path/to/wordpress;
    access_log           off;
    error_log            /dev/null;
    return               301 https://domain.tld$request_uri;
}
server {
    listen 443           ssl http2 default_server deferred;
    listen [::]:443      ssl http2 default_server deferred;
    ssl_certificate      /etc/letsencrypt/live/domain.tld/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/domain.tld/privkey.pem;
    include              /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam          /etc/letsencrypt/ssl-dhparams.pem;
    server_name          domain.tld;
    root                 /path/to/wordpress;
    location / {
        try_files        $uri $uri/ /index.php?$args;
        expires          3600s;
        add_header       Cache-Control "public, max-age=3600";
        add_header       Vary Accept-Encoding always;
    }
    location ~* \.php {
        include          snippets/fastcgi-php.conf;
        fastcgi_pass     unix:/run/php/php7.4-fpm.sock;
    }
    location ~* \.(css|eot|gif|jpeg|jpg|js|png|svg|ttf|xml|woff|woff2) {
        add_header       Cache-Control "public, max-age=604800";
        access_log       off;
        log_not_found    off;
    }
}

MariaDB will happily use more than three gigabytes of memory in its default configuration. Since I only had one gigabyte to play with, I had to change a few variables. I had to edit /etc/mysql/mariadb.conf.d/50-server-cnf with these changes:

innodb_buffer_pool_size = 10M
key_buffer_size         = 8M
max_connections         = 30
thread_cache_size       = 8
thread_stack            = 192K

I don’t know where I got it from, but running this calculation in the terminal with MySQL will indicate the minimum innodb_buffer_pool_size. It’s originally set at 128M:

SELECT CONCAT(ROUND(KBS/POWER(1024,
IF(PowerOf1024<0,0,IF(PowerOf1024>3,0,PowerOf1024)))+0.49999),
SUBSTR(' KMG',IF(PowerOf1024<0,0,
IF(PowerOf1024>3,0,PowerOf1024))+1,1)) recommended_innodb_buffer_pool_size
FROM (SELECT SUM(data_length+index_length) KBS FROM information_schema.tables
WHERE engine='InnoDB') A,
(SELECT 2 PowerOf1024) B;

During the tests on my laptop computer, it suggested 5M. I decided to use 10M in case it started to grow. Also, the key_buffer isn’t used with InnoDB tables, but the minimum size regardless is 8M. I’ll probably have to make increases in size over time, and it all depends on how many articles I write. I hope to write a lot once I get going, possibly more than once a day at times.

Because I selected Debian as the host operating system instead of Ubuntu, only the 7.4 version of PHP was available. The differences between 7.4 and 8.1 aren’t worth mentioning in the context of WordPress.

Other Necessary Items

I followed the Certbot instructions for a wildcard Let’s Encrypt SSL certificate. The only thing I didn’t like about it was that I had to install an Ubuntu Snap package to use it. To set it up quickly, I temporarily switched the server configuration to simply this:

server {
    listen 80            default_server;
    listen [::]:80       default_server;
    server_name          domain.tld www.domain.tld;
    root                 /path/to/wordpress;
}

Since I wanted to use a server-side caching solution instead of a WordPress plugin, I set up the Nginx FastCGI Cache, using the instructions at LinuxBabe. It works well, and I got an “A” grade at GTmetrix.

There were a few more things I had to do, but it mostly concerned WordPress plugins. The only thing I’ll really have to deal with is comment spam, but I’m not too worried about it. I’ll be moderating all comments regardless of who posts them. My website is in the cloud now, and I’m allowing comments, so dealing with comment spam comes with the territory.

Image by Werner Moser from Pixabay

Leave a Comment