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 .
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 VPS(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
- Go to the official PhpMyAdmin download page at here.
- Download the latest stable version of PhpMyAdmin.
- Extract the PhpMyAdmin archive into your Nginx web server’s root directory (e.g.,
C:\nginx\html\phpmyadmin). - 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:
- Navigate to the Nginx configuration directory (e.g.,
C:\nginx\conf\nginx.conf). - Open the
nginx.conffile 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;
}
}
- 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:
- Install Certbot by following the instructions at the Certbot website.
- Once installed, open a command prompt and run the following command to obtain an SSL certificate:
certbot certonly --standalone -d yourdomain.com
- Make sure to replace
yourdomain.comwith your actual domain or VPS IP address. - 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:
- Open your
nginx.conffile again. - 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;
}
}
- 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:
- Open Task Scheduler and create a new task.
- Set the trigger to run every 60 days.
- Set the action to run Certbot with the renewal command:
certbot renew --quiet
- 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 . 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.