There are a lot of ways to run WordPress. Here is the one I chose, maybe it helps you as well. If you have any questions, don’t hesitate to leave them in the comments. I will try my best to help you out. I am assuming you install this on your own server and have root access, or at least sudo access with your account.

That being said: Let’s jump into it!

Step 1 – Install packages

Before you start installing and configuring WordPress, you need to make sure you have all the tools you need. Use apt to install all the needed packages:

sudo apt install software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update

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

Step 2 – Set up the database

The next step is setting up the database. This should be done rather quickly. All you need to do is login to mysql.

sudo systemctl status mariadb # check if mariadb is up and running
sudo mariadb

If you have set a password for mysql, use the interactive mode instead.

sudo systemctl status mariadb # check if mariadb is up and running
sudo mariadb -u root -p

“Inside” we need to create a database, a user and then grant the needed privileges for the database to the generated user.

mariadb
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost';
QUIT;

You can change the database name, user and password as you like. Make sure to jot them down, you will need them later.

Step 3 – Set up PHP-FPM

For this you will use PHP-FPM to handle everything php, passed on by NGINX. This utilizes a pool, for that we need to create a file in /etc/php/8.2/fpm/pool.d. Replace “8.2” with the version of php that you are using.

php -v # find out which php-version you are using, I will use 8.2 here
sudo vim /etc/php/8.2/fpm/pool.d/example.com.conf
# replace <example.com> with your domain or anything you like

In that file is the configuration for php, if used through the FastCGI Process Manager (FPM). Here is an example configuration. Remember to activate the vim insert mode by typing i, before you paste it in.

/etc/php/8.2/fpm/pool.d/example.com.conf
[examplecom] ; change to a unique name

; replace with the user and group of your php files:
user = example_com
group = example_com

; replace example-com with your domain
listen = /run/php/example-com-fpm.sock

; should be user and group of your web server, probably leave it be:
listen.owner = www-data 
listen.group = www-data

pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18
clear_env = no

php_admin_value[opcache.save_comments] = 1
php_admin_value[opcache.interned_strings_buffer] = 16
php_admin_value[opcache.revalidate_freq] = 60
php_admin_value[opcache.validate_timestamps] = 0

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

; you can use your domain here as well
php_admin_value[error_log] = /var/log/fpm-php.example-com.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 1G

That should do it. Write to the file and exit vim by typing :wq. After that, restart PHP-FPM.

sudo systemctl restart php8.2-fpm

Step 4 – Install WordPress

Change into your web root folder and create a folder for your page. Change path and folder name as needed. If you do not know how to do this, you probably should not have root access, tbh. … 😬

mkdir /var/www/html/example.com
cd /var/www/html/example.com

In that folder, download wordpress and untar it.

wget https://wordpress.org/latest.tar.gz
tar --strip-components=1 -xvzf latest.tar.gz
rm latest.tar.gz

Note that --strip-components=1 strips the first part of the files’ paths, in this case the folder wordpress it would normally extract into.

That should do it for now, next we need to configure your WordPress.

Step 5 – Configure WordPress

We will do this by editing the wp-config.php with our editor of choice, which of course is vim.

cp wp-config-sample.php wp-config.php
vim wp-config.php

We’ll make it a short one, of course you can keep all the comments in there. If you want to put in more stuff, you can find a generator at generatewp.com.

Link for the salt: api.wordpress.org

wp-config.php
<?php
/* MySQL settings */
define( 'DB_NAME',     'wordpress' ); // database from step 2
define( 'DB_USER',     'user' ); // user from step 2
define( 'DB_PASSWORD', 'password' ); // password from step 2
define( 'DB_HOST',     'localhost' );
define( 'DB_CHARSET',  'utf8mb4' );

/* MySQL database table prefix. */
$table_prefix = 'wp_';

/* Authentication Unique Keys and Salts. */
/* head to https://api.wordpress.org/secret-key/1.1/salt/ and copy it here */
define('AUTH_KEY',         'I$RCe|Avd6q<^q~}r@!mwq^ds-f+{po');
define('SECURE_AUTH_KEY',  '3.}i|OH|UEG3Ap|p#bJ+P{P%4N-WP)^');
define('LOGGED_IN_KEY',    '0(a gw|-/d7z3T=yN)fh?WD,sWCjDD%');
define('NONCE_KEY',        'm}(s:T%xu]gwKgwuHcThe_TEY9l7v_?');
define('AUTH_SALT',        'JrRb)}~KaZcL5P?v|)h{m$(:m!wb9EU');
define('SECURE_AUTH_SALT', 'enY94*k/e80(F]]_+Z}4as|B&+KX)b1');
define('LOGGED_IN_SALT',   '=;ir6WRQj,ahn=5$? /h6|~&%0QWg=q');
define('NONCE_SALT',       'c&hjS7e9xe{x*ip=7LoYMO@|t4d`w5B');


/* Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

/* Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Aaaand with that done, all we finally need to do is configure NGINX to do what it’s supposed to do.

Step 6 – Set up nginx

In order to do that, we are going to create a file in the sites-available folder of NGINX.

sudo vim /etc/nginx/sites-available/example.com
/etc/nginx/sites-available/example.com
server {
    listen 80;
    root /var/www/html/example.com; # replace example.com
    index  index.php index.html index.htm;
    server_name  example.com; # replace example.com

    client_max_body_size 500M;

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

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         # replace example-com-fpm with socket from step 3
         fastcgi_pass unix:/var/run/php/example-com-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

Save it with :wq, link the example.com file from /etc/nginx/sites-enabled, test and restart NGINX.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

That’s it. Head to example.com and finish the installation from the web installer. Happy blogging!

Edit: You still need to install a Certificate for the website, but that's not part of this post. If you need any help with that, let me know and I will add a tutorial for Let's Encrypt.

Kommentare

Pseudonym genügt. Die Kommentare laufen auf meinem eigenen Server, mehr dazu im Datenschutz.