PhpMyAdmin is a popular web-based tool used to manage MySQL and MariaDB databases. When combined with Nginx and secured using Let's Encrypt SSL, it provides a powerful, secure way to manage your databases. In this guide, we'll walk through the process of installing PhpMyAdmin on Ubuntu 24.04 with Nginx and securing it using a free Let's Encrypt SSL certificate. This setup is ideal for both local servers and VPS servers.

Step 1: Update Your System

Before installing any packages, it's important to ensure your Ubuntu 24.04 server is up to date. Run the following command to update the package list and upgrade any outdated packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx and PHP

Next, install Nginx and PHP, which are required for PhpMyAdmin to function:

sudo apt install nginx php-fpm php-mysql -y

Once the installation is complete, start and enable Nginx:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 3: Install PhpMyAdmin

PhpMyAdmin is not included in the default Ubuntu repositories, so you'll need to download it manually. Begin by navigating to your web directory:

cd /var/www/html

Download the latest version of PhpMyAdmin using the following command:

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz

Extract the downloaded file:

sudo tar xvf phpMyAdmin-latest-all-languages.tar.gz

Rename the extracted directory to "phpmyadmin" for simplicity:

sudo mv phpMyAdmin-*-all-languages phpmyadmin

Change the ownership of the PhpMyAdmin directory to the Nginx user:

sudo chown -R www-data:www-data /var/www/html/phpmyadmin

Step 4: Configure Nginx for PhpMyAdmin

Create a new Nginx server block for PhpMyAdmin:

sudo nano /etc/nginx/sites-available/phpmyadmin.conf

Add the following configuration to the file:


server {
    listen 80;
    server_name your_domain;

    root /var/www/html/phpmyadmin;
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}
        

Save and exit the file. Enable the configuration by creating a symbolic link:

sudo ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/

Test the Nginx configuration for errors:

sudo nginx -t

If the configuration is valid, restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 5: Secure PhpMyAdmin with Let's Encrypt SSL

Next, secure PhpMyAdmin by installing a free SSL certificate from Let's Encrypt. Begin by installing Certbot, the tool used to request and manage SSL certificates:

sudo apt install certbot python3-certbot-nginx -y

Request an SSL certificate for your domain using Certbot:

sudo certbot --nginx -d your_domain

Follow the on-screen instructions to complete the process. Certbot will automatically configure Nginx to use the SSL certificate and redirect HTTP traffic to HTTPS.

Step 6: Verify SSL and PhpMyAdmin Setup

Once the SSL certificate is installed, you can verify the SSL setup by visiting your domain in a web browser using HTTPS:

https://your_domain

You should see the PhpMyAdmin login page. Log in with your MySQL or MariaDB credentials to start managing your databases.

Step 7: Enable Automatic SSL Renewal

Let's Encrypt SSL certificates expire after 90 days. To ensure your certificate is automatically renewed, add a cron job to run the renewal process regularly:

sudo crontab -e

Add the following line to renew the certificate automatically:

0 0 * * * /usr/bin/certbot renew --quiet

Using PhpMyAdmin on a VPS Server

If you're running a VPS server, installing PhpMyAdmin with Nginx and Let's Encrypt SSL ensures that you can securely manage your MySQL databases. By combining the flexibility of Nginx with the security of free SSL from Let's Encrypt, your VPS environment remains protected while providing easy access to your database administration.

Looking for a Reliable VPS Solution?

If you're looking for a secure and reliable VPS server to run PhpMyAdmin and manage your databases, consider using WindowsVPS. With WindowsVPS, you get scalable VPS hosting that ensures your applications run smoothly with full security and performance optimization.

¿Fue útil la respuesta? 0 Los Usuarios han Encontrado Esto Útil (0 Votos)