WordPress with NGINX, PHP-FPM and MariaDB (for MySQL) on Ubuntu 22.04

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:

Shell

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.

Shell

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

Shell

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

SQL
mariadb

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.

Shell

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.

ini
/etc/php/8.2/fpm/pool.d/example.com.conf

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

Shell

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. … 😬

Shell

In that folder, download wordpress and untar it.

Shell

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.

Shell

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

PHP
wp-config.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.

Shell
NGINX
/etc/nginx/sites-available/example.com

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

Shell

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.

Leave a Reply

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