WordPress on Ubuntu 22.04 LTS
Learn how to set up the leading CMS platform WordPress on the latest Ubuntu 20.04 LTS with LEMP stack.
UPDATE: 12/10/23: Updated instructions for 22.04
UPDATE: 21/05/20: added notes about to obtaining SSL using certbot
In this article, We will go through the initial setup process for Installing WordPress, a popular publication and content management system. The process is very straightforward, We will use what's essentially called LEMP Stack which consists of Linux (Ubuntu 22.04 in this case) + NGINX (a High Performance web server and reverse proxy) + MySQL (we will use MariaDB) + PHP (The processor for the language that WordPress is written in)
To get everything in order, we will need a VPS. I recommend Hetzner but this tutorial should work on any VPS as long as you follow the steps correctly.
First, You'll need to ssh into Your VPS server. You can use Terminal app on Windows 10/11 or a ssh client like Putty. If you're running a flavour of linux on your PC then you can also use terminal to accomplish this. If you don't have SSH key set up then your VPS provider will send you an email containing a Username, Password and IP address of your VPS. You'll need to enter those as following: ssh <user>@<IP>
When the system prompts, type in (or copy-paste) the password for the user (in our case, we got root user. Once you enter the password, You'll be greeted with a screen like below and You'll perform the first-steps (i.e. updating the system to latest)
Upon entering the update & upgrade command, the system will print some lines in console, once again, upon completion of update you'll get root@server:~#
Step 1: Install all the Packages
The above one-liner will install all the required items (php, nginx, mariadb) on your ubuntu 22.04 server. Now, let's configure everything.
Step 2: Configuration
First, configure NGINX
This will Open the default configuration file in nano. Add the below server block at the end of the file.
Next, Set up mariadb-server:
After entering the above command, the system will ask you a few questions, Make sure to read them and answer them correctly. Generally, it is safe to set up a super strong password and then answer rest of the questions as Y
(or just hit enter ↵
)
Now that we've done nginx & mysql, our server is ready for installation of WordPress. However, there are a few optional steps that You'd want to do:
- If You want to tweak php settings (execution time etc.) Edit the file
/etc/php/8.2/fpm/php.ini
using nano. Once You're done, make sure You restart php usingsudo service php-fpm restart
- You'd also want SSL, If You don't already have a SSL certificate, Use certbot for a free, automatic and simple SSL certificate. follow this tutorial.
- You'd also want to secure Your server through firewall. Ubuntu comes with UFW preinstalled, To configure UFW, read our other article.
Now that We've done most of it, Let's do the honor of installing WordPress (Finally!)
The above commands will download wordpress archive from wordpress.org, decompress them and move files to /var/www/html
then set correct ownership for the files.
At this point, everything is done. You can visit Your domain e.g. http://example.com
(if You got SSL, use HTTPS) and proceed with the WordPress instructions. It'll ask You to enter your database details so copy them from the notes You've taken. Then it'll ask some details about site. Once that's done, it'll take you to the page to log in to your WordPress admin. That's all.