Introduction

PhpMyAdmin is a popular web-based tool for managing MySQL and MariaDB databases. In this guide, we will walk you through the process of installing PhpMyAdmin, setting up Nginx as a web server, and securing your setup with a free SSL certificate from Let’s Encrypt on your Windows VPS.

Step 1: Install Prerequisites

Before installing PhpMyAdmin and Nginx, ensure that your system has the following components:

  • PHP: Install PHP and the necessary extensions.
  • MySQL or MariaDB: PhpMyAdmin requires a MySQL/MariaDB database server to function.
  • WinNginx: Nginx web server for Windows (or use an appropriate version for Windows).
  • Let’s Encrypt: To secure your server with an SSL certificate, we will use the Let’s Encrypt client Certbot.

Install these components if you haven’t already, using the respective guides for each.

Step 2: Install PhpMyAdmin

  1. Go to the official PhpMyAdmin download page at here.
  2. Download the latest stable version of PhpMyAdmin.
  3. Extract the PhpMyAdmin archive into your Nginx web server’s root directory (e.g., C:\nginx\html\phpmyadmin).
  4. Rename the extracted folder to phpmyadmin (if it is not already named that).

Step 3: Configure Nginx for PhpMyAdmin

Now, configure Nginx to serve PhpMyAdmin:

    1. Navigate to the Nginx configuration directory (e.g., C:\nginx\conf\nginx.conf).
    2. Open the nginx.conf file in a text editor and add a server block to serve PhpMyAdmin. Below is a sample configuration:
server {
    listen 80;
    server_name yourdomain.com;
    root C:/nginx/html;

    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ =404;
    }

    location ~ ^/phpmyadmin/(.*\.php)$ {
        root C:/nginx/html/phpmyadmin;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
    1. Save the file and restart Nginx for the changes to take effect:
nginx -s reload

Step 4: Install and Configure SSL with Let’s Encrypt

To secure your PhpMyAdmin installation with an SSL certificate, use Let’s Encrypt with Certbot. Follow these steps:

    1. Install Certbot by following the instructions at the Certbot website.
    2. Once installed, open a command prompt and run the following command to obtain an SSL certificate:
certbot certonly --standalone -d yourdomain.com
  1. Make sure to replace yourdomain.com with your actual domain or VPS IP address.
  2. After successful certificate issuance, you’ll have the SSL certificate files in the default directory (usually C:\Certbot\live\yourdomain.com).

Step 5: Configure Nginx to Use SSL

Now, update the Nginx configuration to use the SSL certificate:

    1. Open your nginx.conf file again.
    2. Modify the server block to listen on port 443 for HTTPS and configure SSL:
server {
    listen 443 ssl;
    server_name yourdomain.com;

    ssl_certificate C:/Certbot/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key C:/Certbot/live/yourdomain.com/privkey.pem;

    root C:/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ ^/phpmyadmin/(.*\.php)$ {
        root C:/nginx/html/phpmyadmin;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
    1. Save the configuration file and restart Nginx:
nginx -s reload

Step 6: Access PhpMyAdmin

Once you have completed all the steps, you can access PhpMyAdmin by navigating to https://yourdomain.com/phpmyadmin in your web browser. Login using your MySQL or MariaDB credentials.

Step 7: Set Up Auto-Renewal for SSL Certificates

Let’s Encrypt certificates expire every 90 days. To automatically renew the SSL certificate, you can set up a scheduled task in Windows:

    1. Open Task Scheduler and create a new task.
    2. Set the trigger to run every 60 days.
    3. Set the action to run Certbot with the renewal command:
certbot renew --quiet
  1. Ensure that the task runs with administrative privileges.

Conclusion

You have successfully installed PhpMyAdmin with Nginx and secured it with a free SSL certificate from Let’s Encrypt on your Windows VPS. This setup allows you to manage your databases securely over HTTPS. For further customization or advanced configurations, refer to the official documentation for PhpMyAdmin, Nginx, and Let’s Encrypt.

© 2024. For more Windows VPS solutions, visit NetCloud24.