How to Install phpMyAdmin on an Ubuntu Server

phpMyAdmin is a popular web-based tool for managing MySQL databases, offering a user-friendly interface that simplifies database administration tasks. In this article, we will walk you through the process of installing phpMyAdmin on an Ubuntu server.

Prerequisites

Before you begin, ensure you have the following:

  • An Ubuntu server (16.04 or later)
  • A non-root user with sudo privileges
  • MySQL or MariaDB installed on your server

Step 1: Update Your Package Index

First, update your package index to ensure you have access to the latest package versions:

sudo apt update

Step 2: Install phpMyAdmin

You can install phpMyAdmin using the following command:

sudo apt install phpmyadmin

During the installation, you will be prompted to select the web server that should be automatically configured to run phpMyAdmin. Select apache2 by pressing the Space bar and then hit Enter.

Step 3: Configure phpMyAdmin

Next, you will be asked whether to use dbconfig-common to set up the database. Choose Yes, and you will need to provide your MySQL credentials.

You will also need to create a password for the phpMyAdmin application when prompted. Ensure you remember this password, as you will need it to log in later.

Step 4: Configure Apache to Serve phpMyAdmin

After the installation, you may need to enable the phpMyAdmin configuration file for Apache. Use the following command:

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

If you want to secure your phpMyAdmin installation, consider adding the following lines to the configuration file, right before the closing </Directory> tag:

<Directory /usr/share/phpmyadmin>
   Options FollowSymLinks
   DirectoryIndex index.php
   AllowOverride All
   Require all granted
</Directory>

Step 5: Restart Apache

For the changes to take effect, restart the Apache web server:

sudo systemctl restart apache2

Step 6: Access phpMyAdmin

Now, you can access phpMyAdmin by navigating to http://your_server_ip/phpmyadmin in your web browser. Log in using the MySQL credentials you provided during installation.

Step 7: Secure Your phpMyAdmin Installation (Optional)

For added security, consider restricting access to the phpMyAdmin interface. You can do this by creating a new Apache configuration file. Use the following command:

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

Add the following lines, replacing YOUR_USERNAME with your desired username:

<Directory /usr/share/phpmyadmin>
   AuthType Basic
   AuthName "Restricted Access"
   AuthUserFile /etc/phpmyadmin/.htpasswd
   Require valid-user
</Directory>

Create a password file and add a user:

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

Finally, restart Apache again:

sudo systemctl restart apache2

You have successfully installed phpMyAdmin on your Ubuntu server. With this powerful tool, managing your MySQL databases has never been easier. Always remember to keep your server and phpMyAdmin installation updated to protect against security vulnerabilities.

By following the steps outlined in this guide, you can enjoy the full benefits of phpMyAdmin, making database management simpler and more efficient.