Setup WordPress in Debian 12 with Nginx, CGI cache, Redis Cache, Wp login Security and install SSL

siddhant sugan dodrai
By -

WordPress is one of the most widely used CMS (Content Management System) tools for creating and running websites. It’s a free, open-source PHP-based platform that can be used to create and manage websites. It can be used in conjunction with a MySQL database or a MariaDB database to manage your website.

Setup WordPress in Debian 12 with Nginx, CGI cache, Redis Cache, Wp login Security and install SSL

WordPress is known for its easy-to-use interface and a vast selection of themes, plug-ins, and customizations. It is accessible to users of all levels of technical knowledge.

Let’s take a look at how to set up WordPress in Debian 12 with Nginx, CGI cache, Redis Cache, Wp login Security .

Setup WordPress in Debian 12 with Nginx, CGI cache, Redis Cache, Wp login Security 

Step 1: Update Operating System

Make sure all your Debian 12 packages are up-to-date by updating your operating system.
# Update Your Debian Vps
apt update && apt upgrade
Also, install necessary packages:
# Install Necessary packages
apt install nano wget unzip

Step 2: Install Nginx web server on Debian 12

Run the following command to install Nginx:
Start Nginx Configure Nginx on startup:
Enter the following commands to run Nginx:
# Install Nginx in Debian 
apt install nginx
# After Nginx installed Run and enable Nginx 
systemctl start nginx

systemctl enable nginx
Verify the status of the Nginx service using systemctl status command:
# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: enabled)
     Active: active (running)
       Docs: man:nginx(8)
    Process: 674 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 873 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 875 (nginx)
      Tasks: 2 (limit: 2273)
     Memory: 4.5M
        CPU: 402ms
     CGroup: /system.slice/nginx.service
             ├─875 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             └─876 "nginx: worker process"

Step 3: Install PHP and PHP extensions for WordPress

You can install PHP and other supporting packages using the following command:

# Install PHP and Other Supporting packages 
apt install php php-curl php-fpm php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip
Verify which PHP Version you install by this Command
# Verify PHP version 

# Output 
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

After installing the PHP you have to edit the phpini 

# nano /etc/php/8.2/fpm/php.ini
Change the flowing setting as per your requirement
max_execution_time = 300
memory_limit = 512M
post_max_size = 128M
upload_max_filesize = 128M
To implement the changes, restart the php-fpm service:

systemctl restart php8.2-fpm

Step 4: Install MariaDB Database Server

Now you have to install mariadb MySQL on your virtual private server, for this you will run the command given below on your terminal.
apt install mariadb-server mariadb-client
Start the database server daemon, and also enable it to start automatically at the next boot with the following commands:

# systemctl start mariadb
# systemctl enable mariadb
Verify the status of the MariaDB service using systemctl status command
# systemctl status mariadb
● mariadb.service - MariaDB 10.11.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
     Active: active (running)
       Docs: man:mariadbd(8)
   Main PID: 959 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 12 (limit: 2273)
     Memory: 256.5M
        CPU: 6.621s
     CGroup: /system.slice/mariadb.service
             └─959 /usr/sbin/mariadbd
Once the database server is installed, run the following command to secure your MariaDB server:

# mysql_secure_installation
Then, you’ll be presented with a series of configuration questions, to which you’ll need to provide Y answers.

Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y

Restart the database server for the changes to take effect.

# systemctl restart mariadb

Step 5: Create a New Database for WordPress

To do this, log in to your MariaDB server using the following command:
# mysql -u root -p
Run the following commands to create a new database and user:
MariaDB [(none)]> CREATE DATABASE wordpress_db;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'password';
MariaDB [(none)]> EXIT
Note: Make sure to replace 'password' with a strong password of your choice.

Step 6. Install Redis 

With caching, data in slow-loading databases can reach sub-second performance. This helps businesses respond to real-time application demand.

However, not all caching can support mission-critical applications, and many fail to meet their performance goals.

That’s where Redis Enterprise comes in. Redis Enterprise is built to cache at scale. With enterprise-level functionality, critical applications run fast and reliably, while Redis Enterprise integrations simplify caching and save you time and money.

To install Redis Run the flowing Command in Your Terminal
# sudo apt install redis 
Now you have to install redis PHP Extension so that your redis cache can be reduced properly.  To install the extension you will run the below command on your terminal.
# sudo apt install php-redis
Don't forget to install the plugin to use redis Cache on your WordPress.  We will do this after we install WordPress on our virtual private server.

Step 7: Download WordPress

It is now obvious that you will be installing WordPress on your VPS. But first, we need to do a few things on our VPS so that our WordPress will run smoothly.
Navigate to /etc/nginx/conf.d directory and run the following command to create a configuration file for your installation:
# nano /etc/nginx/conf.d/wordpress.conf
Now Copy the below code in this File:
    server {

    server_name  your-domain www.your-domain;
    root   /var/www/html/wordpress;
    index  index.php;

    access_log /var/log/nginx/;
    error_log /var/log/nginx/;

    client_max_body_size 100M;

    location / {
     try_files $uri $uri/ /index.php?$args;

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
         include fastcgi_params;
         fastcgi_intercept_errors on;

        fastcgi_cache my_cache2;
        fastcgi_cache_key "$scheme$request_method$host$request_uri";                 fastcgi_cache_valid 200 302 1h; # Cache 200 and 302 responses for 1 >        fastcgi_cache_valid 301 1d;     # Cache 301 responses for 1 day
        fastcgi_cache_min_uses 1;                                                    fastcgi_cache_use_stale updating error timeout invalid_header http_5>
   location ^~ /wp-login.php {                                                   auth_basic "Restricted Access";
    auth_basic_user_file /etc/nginx/.htpasswd;

    # Other WordPress-related configurations

Note : Change your-domain Name

Configure FastCGI Cache:
Create a common configuration file in /etc/nginx/nginx-wp-common.conf:

# nano /etc/nginx/nginx-wp-common.conf
Copy the below code in this file
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=CACHEZONE:10m max_size=10g inactive=60m;

fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
Create an htpasswd File for secure Your wp-login page: Use the htpasswd command to generate a password file. Replace your_username with your desired username.
sudo htpasswd -c /etc/nginx/.htpasswd your_username

You will be prompted to enter and confirm the password.
Now you have to restart all the services like Nginx web server, Mariadb mysql, PHP services and redis services. Run following command given below.

sudo service nginx restart
sudo service php8.2-fpm restart
sudo service mysql restart
sudo service redis-server restart

Now install the wordPress core file into your virtual private server. Run the given below command one by one in your terminal. We will now download the latest version of WordPress from the WordPress Official site.
Use the following command to download WordPress:

# wget

Extract file into the folder /var/www/html/ with the following command,

# unzip -d /var/www/html/
Next, navigate to the /var/www/html/wordpress/ directory:

# cd /var/www/html/wordpress
WordPress comes with a configuration sample file. Make a copy of this file:
# cp wp-config-sample.php wp-config.php
Next, edit the WordPress configuration file and define your database settings:
# nano wp-config.php
Change the following lines that match your database settings, Database , User name and password, Which we Created in Step 5.
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress_db' );

/** MySQL database username */
define( 'DB_USER', 'wordpress_user' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
Save the file when you are finished.

Change the permission of the website directory:
# chown -R www-data:www-data /var/www/html/wordpress/

Step 8. Final Settings install Nginx Certbot for issue Let's encrypt SSL Certificate for Your Domain 

To secure your WordPress website's domain, you need to install an SSL certificate.  Before proceeding, make sure that your domain name points to the IP address of your virtual private server.  If you have not pointed your virtual private server with an IP address, make sure to point the domain with your virtual private server's IP address before proceeding with this step.  To install the SSL certificate on our Virtual Private Server we will install Nginx Certbot on the VPS and issue the SSL certificate.  For this, type the command given below on your terminal.

# sudo apt install python3-acme python3-certbot python3-mock python3-openssl python3-pkg-resources python3-pyparsing python3-zope.interface
This Command install the dependencies for the python3-certbot-nginx package, which include the python3-acme, python3-certbot, python3-mock, python3-openssl, python3-pkg-resources, python3-pyparsing, and python3-zope.interface packages. Now install Nginx Certbot.
sudo apt install python3-certbot-nginx
To let in HTTPS traffic, allow the Nginx Full profile and delete the redundant Nginx HTTP profile allowance:

sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
Check Status

sudo ufw status
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx Full ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx Full (v6) ALLOW Anywhere (v6)
Last Step issue SSL Certificate for Your Domain
sudo certbot --nginx -d your_domain -d www.your_domain

Access WordPress Web Installer

Open your browser type your domain e.g You will be redirected to the language selection screen:
WordPress web installation page

Select your language and click on the Continue button.
WordPress installation page

Provide the requested information and click on the Install WordPress button.  Once the installation has been finished.  You should see the following screen:
WordPress sucessful install

Click on the Log in button.  You should see the WordPress login screen:
WordPress login Page

Enter your administrator user, password and click on the Log In button.  You will get the dashboard in the following screen:
WordPress dashboard


In this tutorial, we have shown you how to install WordPress on VPS. We have also talked about Redis Cache, Fast Cgi cache, Wp- Login Page Security and how to Install SSL Certificate.

If you want to use Redis Object Cache, then don't forget to install Redis Object cache Plugin on your WordPress.

More Tutorial:

Post a Comment


Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!