phpMyAdmin is a widely-used tool for managing MySQL and MariaDB databases through a web interface. This guide will walk you through the process of installing and securing the latest phpMyAdmin version on Debian 12. Whether you're setting up a local server or using a VPS server, securing phpMyAdmin is crucial to prevent unauthorized access.

Step 1: Update Your System

Before starting the installation, ensure your Debian 12 server is up to date. Run the following commands to update your package list and install any available updates:

sudo apt update && sudo apt upgrade -y

Step 2: Install LAMP Stack

phpMyAdmin requires a LAMP stack (Linux, Apache, MySQL, PHP) to function. If you haven't already installed the LAMP stack, use the following command to install Apache, MySQL, and PHP:

sudo apt install apache2 mysql-server php php-mbstring php-zip php-gd php-json php-curl -y

Start and enable the Apache and MySQL services to run at boot:


sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl start mysql
sudo systemctl enable mysql
        

Step 3: Secure MySQL

Before installing phpMyAdmin, it's important to secure MySQL. Run the following command to start the MySQL security script:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disallow remote root login, and remove the test database. These steps will help secure your MySQL server.

Step 4: Install phpMyAdmin

phpMyAdmin is not included in the default Debian 12 repositories, so you'll need to download the latest version from the official phpMyAdmin website. First, navigate to the web root directory:

cd /var/www/html

Download the latest version of phpMyAdmin using wget:

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 Apache user:

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

Step 5: Configure Apache for phpMyAdmin

Create an Apache configuration file for phpMyAdmin:

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Add the following content to the file:


Alias /phpmyadmin /var/www/html/phpmyadmin


    Options FollowSymLinks
    DirectoryIndex index.php

    
        AddType application/x-httpd-php .php
    

    
        SetHandler application/x-httpd-php
    

    
        DirectoryIndex index.php
    

    
        Require local
        Require ip your_server_ip
    

        

Save and exit the file, then enable the configuration:

sudo a2enconf phpmyadmin

Restart Apache to apply the changes:

sudo systemctl restart apache2

Step 6: Secure phpMyAdmin

To enhance security, limit access to phpMyAdmin by creating a .htaccess file in the phpMyAdmin directory:

sudo nano /var/www/html/phpmyadmin/.htaccess

Add the following content to restrict access:


AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
        

Next, create the .htpasswd file and set up a username and password for accessing phpMyAdmin:

sudo htpasswd -c /etc/phpmyadmin/.htpasswd your_username

Restart Apache to apply the changes:

sudo systemctl restart apache2

Step 7: Enable SSL with Let's Encrypt (Optional)

To further secure phpMyAdmin, you can install a free SSL certificate from Let's Encrypt. First, install Certbot and the Apache plugin:

sudo apt install certbot python3-certbot-apache -y

Request an SSL certificate for your domain:

sudo certbot --apache -d your_domain

Certbot will automatically configure Apache to redirect HTTP traffic to HTTPS and apply the SSL certificate.

Step 8: Access phpMyAdmin

Once the installation is complete, you can access phpMyAdmin by navigating to the following URL in your web browser:

https://your_domain/phpmyadmin

Log in with your MySQL or MariaDB credentials to manage your databases securely.

Using phpMyAdmin on a VPS Server

Running phpMyAdmin on a VPS server allows you to efficiently manage your databases through a web interface. By securing phpMyAdmin with a password and an SSL certificate, you ensure your database management environment remains protected from unauthorized access. This setup is perfect for VPS environments where security is a priority.

Looking for a Reliable VPS Solution?

If you're looking for a reliable VPS server to run phpMyAdmin, consider using WindowsVPS. With WindowsVPS, you get high-performance VPS hosting with full control over your server, ensuring a secure and optimized environment for database management and web hosting.

Cette réponse était-elle pertinente? 0 Utilisateurs l'ont trouvée utile (0 Votes)