How to Install WordPress on Hetzner Cloud

Hetzner WordPress tutorial

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

This tutorial will walk you through the steps of installing a WordPress website on Hetzner Cloud that runs on an Ubuntu LEMP (Linux, Nginx, MariaDB, and PHP) server. Additionally, you will learn how to connect a domain name and install an auto-renewing SSL certificate.

Prerequisites:

  1. Domain name
  2. Hetzner Cloud account

Notes:

  1. Replace netwits.io with the name of your domain name in this tutorial
  2. A complete video tutorial is available at the end of this tutorial

1. Hetzner Cloud Setup

Assuming that you already have an account, you can access Hetzner Cloud at console.hetzner.cloud. Create a new project, and add a server with sufficient resources for your website.

After clicking on the Create & Buy Now button, your server will be ready to use within seconds. In addition to accessing your server via SSH directly, you can also access your server via the Cloud Console as indicated in the screenshot below.

Hetzner Cloud console access

2. Connect Your Domain Name

No matter where you bought your domain name from, you can connect it to your Hetzner Cloud server in one of two ways:

  1. Hetzner DNS Console: Add Hetzner nameservers to your domain registrar
  2. DNS A Records: Create DNS A records with your domain registrar that point to your Hetzner server’s IP address

For guidance with the latter, please see timestamp 5:40 in this Hetzner tutorial video.

3. Update System and Install LEMP Packages

Execute the following to update Ubuntu server.

apt update
apt upgrade

Use the apt package manager to install PHP, MariaDB, and the Nginx web server.

apt install nginx mariadb-server php-fpm php-mysql

4. Install WordPress

After logging in to your server as described above, execute the following commands to install WordPress on Ubuntu.

cd /var/www
wget https://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rm latest.tar.gz
chown -R www-data:www-data wordpress
find wordpress/ -type d -exec chmod 755 {} \;
find wordpress/ -type f -exec chmod 644 {} \;

5. Setup the Database

Secure your MariaDB installation by adding a password and disabling other features. When prompted, answer Y.

mysql_secure_installation

Access the MariaDB console with the password that you just created.

mysql -u root -p

Within the MariaDB console, create a database for WordPress. Please choose your own database name, user name, and a password.

create database example_db default character set utf8 collate utf8_unicode_ci;
create user 'example_user'@'localhost' identified by 'example_pw';
grant all privileges on example_db.* TO 'example_user'@'localhost';
flush privileges;
exit

6. Configure Nginx Web Server

Navigate to the directory which contains configuration files for the Nginx web server, and create a new configuration file with the text editor of your choice. In this example, the text editor is vim.

cd /etc/nginx/sites-available/
vim wordpress.conf

Use this configuration as a template for your website. Please change the server_name and make sure that the php-handler socket exists (you may have a different version of PHP installed).

upstream php-handler {
        server unix:/var/run/php/php7.4-fpm.sock;
}
server {
        listen 80;
        server_name netwits.io www.netwits.io;
        root /var/www/wordpress;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass php-handler;
        }
}

Make a symbolic link to tell Nginx about your website, and apply the changes by restarting the web server.

ln -s /etc/nginx/sites-available/wordpress.conf /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx

7. Finish WordPress Install

Assuming that DNS propagation has finished, you can now access your website via your domain name in a web browser. You will be prompted to finish the WordPress installation, part of which is entering the database name, user, and password that you created earlier.

WordPress database setup

Upon completion of the installation, you can access your WordPress administrator dashboard at http://netwits.io/wp-admin/

8. Install PHP Packages Required by WordPress

From your WordPress administrator dashboard, navigate to Tools > Site Health > Status and you may see a critical issue that says “One or more required modules are missing”.

To fix this, go back to your server’s console window and install these packages.

apt install php-curl php-dom php-mbstring php-imagick php-zip php-gd

9. Install an SSL Certificate for HTTPS

Secure your website with an SSL certificate from Let’s Encrypt. To do this, execute the following commands.

apt install snapd
snap install core; snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
certbot --nginx

Finally back in your WordPress administrator dashboard, go to Settings > General and change the WordPress Address and Site Address to start with https.

Here is a complete video tutorial that will walk you through the steps to setup a WordPress website on Hetzner cloud.

YouTube video

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony from Tony Teaches Tech headshot

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

Leave a Reply

Your email address will not be published. Required fields are marked *