5 min read

Installing Webserver Nginx and Setting Up WordPress with MariaDB 11 (LEMP Stack)

Learn how to install and configure a high-performance LEMP stack (Linux, Nginx, MariaDB 11, PHP 8.1) for WordPress. Step-by-step guide for sysadmins to deploy secure and optimized WordPress hosting.

As a System Administrator, I know that choosing the right web hosting stack is the foundation of a high-performing and scalable website. While Apache is common, the speed and efficiency of Nginx for serving static content and handling concurrent connections is unparalleled.

When paired with the robust MariaDB 11 database and PHP-FPM, you have a powerful platform known as the LEMP stack (Linux, Nginx, MariaDB, PHP) — perfect for dynamic applications like WordPress.

This hands-on guide will walk you through setting up a professional-grade WordPress server for your domain wordpress.masdzub.com, using MariaDB 11 and PHP 8.1 for optimal performance and stability.

Whether you’re a budding system administrator or an experienced developer, this guide provides clear, actionable steps to build your LEMP stack with confidence.


I. Server Preparation and Installing Nginx Webserver

Before diving into the core setup, make sure your Linux system is updated and ready. This guide assumes a Debian-based distribution (like Ubuntu Server), commonly used in production environments.

1. Updating the System and Installing Prerequisites

Start fresh by updating all system packages:

Terminal window
sudo apt update
sudo apt upgrade -y

2. Installing Nginx (Engine X)

Nginx is the backbone of this setup. Its asynchronous, event-driven architecture ensures high performance under heavy loads.

Terminal window
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx

Firewall Configuration (UFW)

If you’re using UFW (Uncomplicated Firewall), allow HTTP and HTTPS traffic:

Terminal window
sudo ufw allow 'Nginx Full'
sudo ufw enable

Now, test Nginx by visiting your server’s public IP — you should see the default Nginx welcome page.


II. Installing and Securing MariaDB 11 Database

MariaDB is a powerful, community-driven alternative to MySQL, optimized for performance and reliability — ideal for WordPress databases.

1. Adding the MariaDB 11 Repository

By default, Debian/Ubuntu may ship with older MariaDB versions (e.g., 10.6). To install MariaDB 11, add the official repository:

Terminal window
sudo apt install software-properties-common dirmngr apt-transport-https -y
sudo curl -o /etc/apt/trusted.gpg.d/mariadb_release_signing_key.asc 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el,s390x] https://ftp.mariadb.org/repo/11.1/debian bullseye main'
sudo apt update
sudo apt install mariadb-server -y

2. Securing the MariaDB Installation

Lock down your new MariaDB instance for production use:

Terminal window
sudo mysql_secure_installation

Respond “Y” to all prompts to set the root password, remove anonymous users, and disallow remote root login.

3. Creating the WordPress Database and User

Log in to MariaDB:

Terminal window
sudo mysql

Then create a dedicated database and user (replace YOUR_SECURE_PASSWORD with a strong password):

CREATE DATABASE masdzub_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'masdzub_user'@'localhost' IDENTIFIED BY 'YOUR_SECURE_PASSWORD';
GRANT ALL PRIVILEGES ON masdzub_db.* TO 'masdzub_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

III. Installing and Configuring PHP 8.1 with PHP-FPM

WordPress runs on PHP, so you’ll need PHP-FPM (FastCGI Process Manager) to handle dynamic requests efficiently.

1. Installing PHP 8.1 and Required Extensions

Terminal window
sudo apt install php8.1-fpm php8.1-mysql php8.1-curl php8.1-gd php8.1-mbstring php8.1-xml php8.1-xmlrpc php8.1-soap php8.1-intl php8.1-zip -y

2. Tuning PHP-FPM

Edit the PHP-FPM configuration file:

Terminal window
sudo nano /etc/php/8.1/fpm/php.ini

Find and set:

cgi.fix_pathinfo=0

This prevents Nginx from executing incorrect PHP files, improving security.

Restart PHP-FPM:

Terminal window
sudo systemctl restart php8.1-fpm

PHP-FPM Optimization Tips

Increase limits for better WordPress performance:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M

IV. Nginx Server Block Configuration for WordPress

Now, configure Nginx to handle your WordPress domain.

1. Creating the Document Root

Terminal window
sudo mkdir -p /var/www/wordpress.masdzub.com/public_html
sudo chown -R www-data:www-data /var/www/wordpress.masdzub.com/
sudo chmod -R 755 /var/www/wordpress.masdzub.com/

2. Creating the Nginx Server Block

Terminal window
sudo nano /etc/nginx/sites-available/wordpress.masdzub.com.conf

Paste the configuration below:

server {
listen 80;
server_name wordpress.masdzub.com www.wordpress.masdzub.com;
root /var/www/wordpress.masdzub.com/public_html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ /\. {
deny all;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* /(?:wp-config|readme|license)\.php {
deny all;
}
}

Enable the site and test the configuration:

Terminal window
sudo ln -s /etc/nginx/sites-available/wordpress.masdzub.com.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

V. Installing and Configuring WordPress

1. Downloading and Extracting WordPress

Terminal window
cd /var/www/wordpress.masdzub.com/public_html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz

2. Configuring wp-config.php

Terminal window
sudo mv wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update your database credentials:

define( 'DB_NAME', 'masdzub_db' );
define( 'DB_USER', 'masdzub_user' );
define( 'DB_PASSWORD', 'YOUR_SECURE_PASSWORD' );

Add your unique security keys from: 👉 https://api.wordpress.org/secret-key/1.1/salt/

3. Completing the Installation

Visit http://wordpress.masdzub.com and follow the WordPress installation wizard to configure your site name, admin credentials, and email.


VI. Best Practices and Sysadmin Insights

AreaActionable AdviceSysadmin Insight
SecurityUse a unique database user per site. Install an SSL certificate with Let’s Encrypt.Limits attack surface and improves HTTPS reliability.
PerformanceEnable Nginx FastCGI caching and use a CDN.Reduces server load and speeds up content delivery.
MaintenanceSchedule automated backups and updates.Critical for uptime and disaster recovery.

Common Issues and Troubleshooting (FAQ)

Q: Why do I see a 404 error when visiting WordPress posts? A: Ensure your try_files directive is set correctly in Nginx and reload the service using sudo systemctl reload nginx.

Q: Why is my site slow after setup? A: Check the PHP-FPM log (/var/log/php8.1-fpm.log) and increase memory limits if needed. Consider enabling caching.


Conclusion: Mastering High-Performance WordPress Hosting

Congratulations! 🎉 You’ve successfully built a high-performance LEMP stack with Nginx, MariaDB 11, and PHP 8.1 — the ideal environment for secure and scalable WordPress hosting.

By following Nginx server block best practices and PHP-FPM optimization, your site wordpress.masdzub.com is now ready to handle real-world traffic with speed and reliability.


Found this article helpful? Share it