WordPress powers over 43% of all websites on the internet. While shared hosting is suitable for beginner websites, deploying WordPress on a dedicated Aveshost Linux Virtual Private Server (VPS) gives you full root access, dedicated CPU and NVMe SSD resources, isolated database performance, and the ability to customize your server stack for blazing-fast page loads and high traffic volumes.

The LEMP stack (Linux, Engine-X / Nginx, MariaDB/MySQL, and PHP) is the industry standard for high-performance WordPress hosting, offering significantly better concurrent user handling and memory efficiency than traditional Apache servers.

In this comprehensive, step-by-step tutorial, you will learn how to deploy and configure a production-ready WordPress site on a Linux VPS across Ubuntu, Debian, AlmaLinux, Rocky Linux, RHEL, and CentOS using Nginx, MariaDB, PHP 8.2/8.3, Let’s Encrypt SSL, and enterprise security configurations.


Prerequisites


Step 1: Install Nginx Web Server

Update your system package index and install Nginx:

On Ubuntu & Debian:

sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx

On AlmaLinux, Rocky Linux, RHEL & CentOS:

sudo dnf upgrade -y
sudo dnf install -y nginx
sudo systemctl enable --now nginx

Step 2: Install and Secure MariaDB Database Server

MariaDB is a high-performance, drop-in replacement for MySQL:

1. Install MariaDB:

# On Ubuntu / Debian:
sudo apt install -y mariadb-server mariadb-client
sudo systemctl enable --now mariadb

# On AlmaLinux / Rocky Linux / RHEL:
sudo dnf install -y mariadb-server mariadb
sudo systemctl enable --now mariadb

2. Secure Database Installation:

sudo mysql_secure_installation

(Set a strong root password, remove anonymous users, disallow remote root login, and remove the test database).

3. Create WordPress Database & User:

Log in to the MariaDB root shell:

sudo mariadb

Execute the following SQL queries (replace StrongDBPassword123! with a strong password):

CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'StrongDBPassword123!';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3: Install PHP 8.2 / 8.3 and Required Extensions

WordPress requires PHP-FPM and specific PHP modules for image processing, database communication, and cryptographic hashing:

On Ubuntu & Debian:

sudo apt install -y php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-bcmath php-imagick
sudo systemctl enable --now php*-fpm

On AlmaLinux, Rocky Linux, RHEL & CentOS:

# Enable Remi Repository for latest PHP
sudo dnf install -y epel-release
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.2 -y

# Install PHP and extensions
sudo dnf install -y php-fpm php-mysqlnd php-curl php-gd php-mbstring php-xml php-soap php-intl php-zip php-bcmath php-pecl-imagick
sudo systemctl enable --now php-fpm

Step 4: Download and Extract WordPress

  1. Download the latest official WordPress release to your web root:
    cd /tmp
    curl -O https://wordpress.org/latest.tar.gz
    sudo mkdir -p /var/www/wordpress
    sudo tar -xzvf latest.tar.gz -C /var/www/
  2. Set optimal file ownership and permissions:
    # On Ubuntu / Debian:
    sudo chown -R www-data:www-data /var/www/wordpress
    sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
    sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
    
    # On AlmaLinux / Rocky Linux / RHEL:
    sudo chown -R nginx:nginx /var/www/wordpress
    sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
    sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;

Step 5: Configure WordPress Settings (wp-config.php)

  1. Copy the sample configuration file:
    sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
    sudo nano /var/www/wordpress/wp-config.php
  2. Update the database credentials:
    define( 'DB_NAME', 'wordpress_db' );
    define( 'DB_USER', 'wordpress_user' );
    define( 'DB_PASSWORD', 'StrongDBPassword123!' );
    define( 'DB_HOST', 'localhost' );
    define( 'DB_CHARSET', 'utf8mb4' );
    define( 'DB_COLLATE', '' );
  3. Generate unique secret security keys by visiting WordPress Salt Generator and replacing the AUTH_KEY, SECURE_AUTH_KEY, etc., lines.
  4. Save and exit (CTRL + O, ENTER, CTRL + X).

Step 6: Configure Nginx Server Block for WordPress

Create a high-performance Nginx configuration with rewrite rules and asset caching:

  1. Create the configuration file:
    sudo nano /etc/nginx/conf.d/wordpress.conf
  2. Paste the production configuration (replace domain.com with your domain name):
    server {
        listen 80;
        server_name domain.com www.domain.com;
        root /var/www/wordpress;
        index index.php index.html index.htm;
    
        client_max_body_size 64M;
    
        # Gzip Compression
        gzip on;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    
        # WordPress Permalinks
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        # Pass PHP scripts to FastCGI
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
            # For Ubuntu / Debian (adjust PHP version socket if necessary):
            fastcgi_pass unix:/run/php/php-fpm.sock;
    
            # For AlmaLinux / Rocky Linux (uncomment below and comment unix socket):
            # fastcgi_pass 127.0.0.1:9000;
        }
    
        # Cache static assets
        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
            expires 365d;
            access_log off;
            log_not_found off;
        }
    
        # Block access to sensitive files and scripts
        location = /xmlrpc.php {
            deny all;
            access_log off;
            log_not_found off;
        }
        location ~ /\.ht {
            deny all;
        }
        location = /wp-config.php {
            deny all;
        }
    }

SELinux Permissions (For AlmaLinux / Rocky Linux / RHEL):

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
sudo chcon -R -t httpd_sys_rw_content_t /var/www/wordpress/wp-content

Test and Reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Step 7: Install Free Let's Encrypt SSL Certificate

Secure your WordPress installation and enable HTTPS automatically:

# Ubuntu / Debian:
sudo apt install -y certbot python3-certbot-nginx

# AlmaLinux / Rocky Linux:
sudo dnf install -y certbot python3-certbot-nginx

# Issue and configure SSL
sudo certbot --nginx -d domain.com -d www.domain.com

Step 8: Complete WordPress Web Installation

  1. Open your web browser and navigate to https://domain.com.
  2. Select your preferred language and click Continue.
  3. Enter your Site Title, Admin Username, a strong Password, and your Admin Email.
  4. Click Install WordPress.
  5. Log in to your newly deployed WordPress administrative dashboard at https://domain.com/wp-admin.

Frequently Asked Questions & Troubleshooting

Q: Why do I get an "Error establishing a database connection"?
A: Double-check that MariaDB is running (sudo systemctl status mariadb) and verify that the database name, username, and password in /var/www/wordpress/wp-config.php match the MariaDB user you created in Step 2.

Q: Why am I asked for FTP credentials when installing plugins or themes?
A: This happens when the web server user does not have write permissions to wp-content. Run sudo chown -R www-data:www-data /var/www/wordpress (or sudo chown -R nginx:nginx /var/www/wordpress on RHEL-based systems).


Need Further Assistance?

If you need assistance configuring your LEMP stack, setting up Redis caching, or optimizing WordPress on your Aveshost Linux VPS, our cloud support engineering team is available 24/7. Feel free to submit a support ticket through your client area for expert assistance.

Ha estat útil la resposta? 0 Els usuaris han Trobat Això Útil (0 Vots)