Setting up a LEMP server with Wordpress

Setting up a LEMP server with Wordpress

LEMP stands for Linux, Nginx (read like Engine-X), MySQL and PHP.
You may have heard about LAMP, which uses Apache instead of Nginx.

Getting a server

I would recommend to use GCP to rent VM.
If you would like to host this for free, then you can choose an E2-micro instance somewhere in Iowa (your first 744 hours / month of E2-micro instances are free)
I won’t go into detail with the VM setup, but you will need to setup ssh keys, with the HTTP and HTTPS flags, and choose the OS to be Ubuntu 22.04

Installing nginx

First update the server

1
2
sudo apt update
sudo apt upgrade -y

Then install Nginx

1
sudo apt install nginx -y

Installing MySQL

1
2
sudo apt install mysql-server -y
sudo mysql -u root

At the mysql prompt enter

1
2
3
4
5
CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES on wordpress.* TO '<username>'@'localhost';
FLUSH PRIVILEGES;
QUIT

Installing PHP

1
2
3
4
sudo add-apt-repository universe
sudo apt update
sudo apt install -y php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc
sudo systemctl enable --now php8.1-fpm

Configuring Nginx

Open the /etc/nginx/sites-available/default file with nano (or any other editor)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name <your_domain>;

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}
1
sudo systemctl restart nginx

Installing Wordpress

Download the latest Wordpress

1
2
3
4
5
6
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvf latest.tar.gz -C .
sudo mv wordpress/* .
sudo rm -r latest.tar.gz wordpress
sudo rm index.nginx-debian.html

Configuring Wordpress

1
2
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

And configure the DB_NAME, DB_USER and DB_PASSWORD
Then go to salt and paste the values in the config

And you are done

Licensed under CC BY-NC-SA 4.0