Last week I was browsing the internet for the best WordPress setup and came across three kinds of setup LAMP (Linux, Apache, MySql and Php), LEMP (Linux, Nginx, MySql and Php) and WordPress with OpenLitespeed.
Being an IT guy I know that Nginx and OpenLitespeed are the fastest. So, I shortlisted WordPress with OpenLitespeed and LEMP setups. I thought to first try both and then finalize the one I will stick to.
Although, i will also share a tutorial on how to install WordPress with OpenLitespeed on Rocky Linux or on Ubuntu soon.
WordPress with OpenLitespeed
I quickly purchased a VPS from OVHCloud and tried setting up WordPress with OpenLitespeed. It worked well and I found out that QUIC and WordPress LiteSpeed cache plugin works together to provide the best performance WordPress setup. When I scanned my website on PageSpeed I was getting a score of 97 and 98 on Mobile and Desktop which was freaking awesome. But the worst part for me was QUIC credits. If the credits are over, you either have to pay for more credits or end up having a normal performing website.
WordPress with LEMP
Then I thought to try LEMP setup. I quickly reinstalled Rocky Linux 10 on my VPS and started configuring LEMP setup. As the setup completed, I was surprised that without doing much of the tuning, I managed to get PageSpeed score of 98 and 99 for Mobile and Desktop and the best part is that I don’t have to pay a single penny other than hosting to keep my WordPress setup highly stable and blazing fast.
So for me, LEMP stands as the best WordPress setup and here is the complete tutorial that you can follow to install yourself
Table of Contents
Prerequisites
- Point your DNS to your server’s IP
- A VPS with Rocky Linux 10 Installed
- A sudo user
Step 1 – Installing nano editor
Before we begin lets first install nano editor which will help us in editing the configuration file
sudo dnf update -y
sudo dnf install nano -y
Step 2 – Install Nginx
Now let’s install Nginx on our server and start its services. To install Nginx and start its services, run the given below commands one by one
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
With this Nginx has been installed and started. Let’s proceed to the third step
Step 3 – Install and configure Firewall
The third step is to install and configure firewall so that our server allows the incoming traffic from http and https ports.
sudo dnf install firewalld -y
Now that the firewall is installed, lets start and enable it
sudo systemctl start firewalld
sudo systemctl enable firewalld
Lets add rules to allow incoming traffic from http and https ports.
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --add-service=https --permanent
sudo firewall-cmd --reload
With this our firewall is installed and configured. Now lets proceed to fourth step
Step 4 – Install and Configure MariaDB
Fourth step is to install and configure MariaDB which will be the database for WordPress
sudo dnf install mariadb-server -y
Start and Enable MariaDB services
sudo systemctl start mariadb
sudo systemctl enable mariadb
Lets first secure our database, then we will go ahead with creating database
sudo mysql_secure_installation
Enter current password for root (enter for none): (Just hit enter key)
Switch to unix_socket authentication [Y/n]: (Press N and hit enter key)
Change the root password? [Y/n]: (Press Y and hit enter key)
Enter New Password:
Confirm New Password:
Note:- Make sure to enter a strong and memorable password here
Remove anonymous users? [Y/n]: (Press Y and hit enter key)
Disallow root login remotely? [Y/n]: (Press Y and hit enter key)
Remove test database and access? [Y/n]: (Press Y and hit enter key)
Reload privilege tables now? [Y/n]: (Press Y and hit enter key)
Now to create database lets first login to mysql
sudo mysql -u root -p
Now execute the scripts below to setup complete database. Make sure to go through the “Note” I have added below before running the scripts.
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
Note:- Make sure to change the given below as per your need
“wordpress” – This is the name of your WordPress database. You can change it as per your wish
“wordpressuser” – This is the user name of your database user who will have access to your database. You can change it as per your wish
“password” – This is database’s password. Change it to something stronger
With this we have setup our database. Now lets proceed to step five
Step 5 – Install PHP 8.5
At the time of publishing this post, PHP 8.5 was the latest release and so I have installed the same. Execute the commands below one by one to install PHP 8.5 on your server
sudo dnf install epel-release -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-10.rpm -y
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.5 -y
sudo dnf install php-fpm php-curl php-gd php-imagick php-intl php-mbstring php-xml php-zip php-mysqli php-mysqlnd php-bcmath -y
By default PHP use apache as user and group, since we are using nginx lets configure PHP to use nginx user and group.
sudo nano /etc/php-fpm.d/www.conf
scroll down a bit and you will find
user = apache
group = apache
change both parameters to
user = nginx
group = nginx
press ctrl+x, y, hit enter
Now lets restart php-fpm service for the changes to effect
sudo systemctl restart php-fpm
With this, PHP 8.5 has been installed on your server. Let’s proceed to sixth step
Step 6 – Configuring Nginx
Now the next step is to configure Nginx configuration file. For that we will create a new .conf file with our domain name
sudo nano /etc/nginx/conf.d/your_domain.conf
Note:- Make sure to change “your_domain” to your real domain name
Now copy and paste the given below to your_domain.conf file
server {
listen 80;
listen [::]:80;
server_name your_domain.com www.your_domain.com;
root /var/www/html/your_domain;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Note:- Make sure to change “your_domain” to your real domain name
Now lets compile and test whether nginx configuration is correct
sudo nginx -t
Now lets restart nginx
sudo systemctl restart nginx
With this our Nginx configuration is completed.
Step 7 – Downloading and Configuring WordPress
Next step is to download the latest WordPress from official source to our /tmp folder and configure it
cd /tmp
sudo curl -LO https://wordpress.org/latest.tar.gz
sudo tar xzvf latest.tar.gz -C /var/www/html/
cd /var/www/html/
sudo mv wordpress/ your_domain
cd your_domain
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Fill the database details as per step 4 in the given below fields
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');
...
define('FS_METHOD', 'direct');
Press ctrl+x, y and hit enter to save.
Let’s assign correct permission to our WordPress folder
sudo chown -R nginx:nginx /var/www/html/your_domain
Step 8 – Disabling SELinux
To allow the WordPress and other plugins to work properly, we will have to disable SELinux. Open the SELinux configuration file and make the following changes
sudo nano /etc/selinux/config
Scroll down and find
SELINUX=permissive
change the parameter to
SELINUX=disabled
Press ctrl+x,y, and hit enter key.
Step 9 – Configuring SSL
The final step is to configure SSL. I have used LetsEncrypt SSL which is free and offers good amount of encryption. Lets first install certbot which will configure SSL and also renews it automatically.
sudo dnf install certbot python3-certbot-nginx -y
Now lets get our certificate
sudo certbot --nginx -d your_domain.com -d www.your_domain.com
Note: Make sure to change your_domain with your real domain
It will ask for your email address, enter it and press enter key
Then press “Y” and hit enter in both the prompts, one is to accept the terms and conditions and other is to join LetsEncrypt’s email subscription.
Restart your VPS
sudo reboot
Now on any browser, open “https://your_domain.com” and finalize the setup.
Note: Make sure to change your_domain with your real domain
Conclusion
Following the steps above will install WordPress with Nginx, PHP 8.5 on Rocky Linux 10. Feel free to comment any issues or queries in the comment box below.
Leave a Reply