How to Install phpMyAdmin on a Linux Server

phpMyAdmin is a popular, web-based application that allows system administrators and developers to manage MySQL and MariaDB databases with ease. To install phpMyAdmin, it provides a simple graphical interface for database management, eliminating the need for command-line interaction.

In this guide, we’ll walk you through installing phpMyAdmin on your Linux server step by step.

Why Use phpMyAdmin on Your Linux Server?

phpMyAdmin on a Linux Server

phpMyAdmin offers numerous benefits for managing databases, especially when compared to command-line tools. Its intuitive interface makes tasks like creating and modifying databases, running SQL queries, and backing up data simple.

Additionally, phpMyAdmin’s flexibility with MySQL and MariaDB databases makes it an essential tool for web administrators, developers, and anyone looking for easy database management.

By using phpMyAdmin, you can manage your databases from any device with a web browser, which is particularly useful for remote database administration. Whether you are working on a single server or multiple servers, phpMyAdmin makes it easier to handle complex database tasks.

Prerequisites

Before proceeding with the phpMyAdmin installation, ensure that:

  • LAMP or LEMP stack is installed: This means your server should have Linux, Apache/Nginx, MySQL/MariaDB, and PHP installed.
  • Root or sudo privileges: You need administrative access to install packages and configure the server.
  • Internet connection: An active internet connection is required to download phpMyAdmin and its dependencies.

Install phpMyAdmin on a Linux Server

To install phpMyAdmin on a Linux server, follow the process of downloading, configuring, and securing the application. This web-based tool simplifies the management of MySQL and MariaDB databases. By setting up phpMyAdmin, you gain an intuitive interface for performing database operations without relying solely on command-line tools, enhancing both usability and efficiency.

Update Your Package List

Before installing phpMyAdmin, it’s a good idea to update your package repositories to make sure you’re getting the latest versions of all the necessary packages.

  • For Ubuntu/Debian-based systems:
sudo apt update
  • For CentOS/RHEL-based systems:
sudo yum update

This ensures your package list is up-to-date and pulls in the latest versions of software and dependencies.

Install phpMyAdmin

Now, let’s proceed with installing phpMyAdmin. Depending on your Linux distribution, you’ll use different commands.

  • For Ubuntu/Debian-based systems:
sudo apt install phpmyadmin
  • For CentOS/RHEL-based systems:
sudo yum install phpMyAdmin

This command will install phpMyAdmin along with the necessary PHP dependencies required for it to run.

Configure Apache or Nginx to Serve phpMyAdmin

Once phpMyAdmin is installed, you need to configure your web server (Apache or Nginx) to serve phpMyAdmin. Here’s how to do it:

For Apache:

sudo phpenmod mbstring
  • Ensure that the Apache config includes phpMyAdmin by checking if the phpMyAdmin configuration file exists:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
  • Then, enable the configuration:
sudo a2enconf phpmyadmin
  • Restart Apache to apply the changes:
sudo systemctl restart apache2

For Nginx:

  • Create a new Nginx server block for phpMyAdmin, typically in /etc/nginx/sites-available/.
  • Add the following configuration to your server block:
server {
    listen 80;
    server_name your_domain_or_IP;
    root /usr/share/phpmyadmin;
    index index.php;

    location /phpmyadmin {
        root /usr/share;
        index index.php;
        try_files $uri $uri/ =404;
    }
}
  • Create a symbolic link to enable the site configuration:
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/
  • Finally, restart Nginx:
sudo systemctl restart nginx

Secure phpMyAdmin

To increase security, consider securing phpMyAdmin with additional layers such as basic authentication and SSL encryption.

Enable Basic Authentication:

  • Edit the Apache or Nginx configuration for phpMyAdmin.
  • Add the following to enable password protection:
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
  • Create a .htpasswd file:
sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

Use SSL:

  • Install an SSL certificate for your server (using Let’s Encrypt or any certificate provider).
  • Modify your Nginx or Apache configuration to force HTTPS for accessing phpMyAdmin.

Access phpMyAdmin in Your Browser

After configuring your web server, you can access phpMyAdmin through your browser by visiting:

http://your_domain_or_IP/phpmyadmin

Log in with your MySQL or MariaDB credentials, and you will be able to manage your databases from the web interface.

Verify phpMyAdmin Installation

To verify that phpMyAdmin is properly installed and working:

  • Open your web browser and navigate to:
http://your_domain_or_IP/phpmyadmin
  • You should see the phpMyAdmin login page.
  • Log in with your database credentials to confirm that everything is functioning correctly.

Conclusion

phpMyAdmin is a powerful and user-friendly tool for managing MySQL and MariaDB databases on a Linux server. Following this guide, you should have successfully installed phpMyAdmin and configured it to be accessible securely from your web browser. By integrating additional security layers like SSL and basic authentication, you can ensure that your phpMyAdmin interface remains protected from unauthorized access.

Leave A Comment