How to Install phpMyAdmin on Your Server

phpMyAdmin is a web-based database management tool for MySQL and MariaDB. Follow these steps to install it on your server.

Prerequisites

  • A server running Ubuntu/Debian or CentOS/Rocky Linux.
  • MySQL or MariaDB installed.
  • A web server like Apache or Nginx installed.
  • PHP installed.

Step 1: Update Your Server

Update your package list to ensure you install the latest versions:

sudo apt update && sudo apt upgrade -y  # For Ubuntu/Debian  
sudo yum update -y  # For CentOS/Rocky Linux  

Step 2: Install phpMyAdmin

On Ubuntu/Debian

sudo apt install phpmyadmin -y

During installation:

  • Choose Apache when prompted.
  • Select Yes when asked to configure with dbconfig-common.
  • Set a password for the phpMyAdmin user.

On CentOS/Rocky Linux

sudo yum install epel-release -y
sudo yum install phpmyadmin -y

Step 3: Configure Web Server

For Apache

Ensure phpMyAdmin is enabled in Apache:

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
sudo systemctl restart apache2  # For Ubuntu  
sudo systemctl restart httpd  # For CentOS  

Now, phpMyAdmin should be accessible at:

http://your-server-ip/phpmyadmin

For Nginx

Edit your Nginx config:

sudo nano /etc/nginx/sites-available/default

Add this inside the server {} block:

location /phpmyadmin {
    root /usr/share/;
    index index.php;
    location ~ ^/phpmyadmin/(.+\.php)$ {
        try_files $uri =404;
        root /usr/share/;
        fastcgi_pass unix:/run/php/php-fpm.sock; # Adjust for your PHP version
        fastcgi_index index.php;
        include fastcgi.conf;
    }
}

Restart Nginx:

sudo systemctl restart nginx

Now, access phpMyAdmin at:

http://your-server-ip/phpmyadmin

Step 4: Secure phpMyAdmin

  1. Disable root login via phpMyAdmin:
    Edit MySQL config: sudo nano /etc/mysql/my.cnf Add: [mysqld] skip-networking Restart MySQL: sudo systemctl restart mysql
  2. Password Protect phpMyAdmin (Apache Only) sudo nano /etc/apache2/conf-available/phpmyadmin.conf Add: <Directory /usr/share/phpmyadmin> AuthType Basic AuthName "Restricted Access" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user </Directory> Create a password file: sudo htpasswd -c /etc/phpmyadmin/.htpasswd yourusername Restart Apache: sudo systemctl restart apache2

Your phpMyAdmin is now installed and secured. 🚀 Let me know if you need help!

Leave a Comment