top of page

🛠️ How to Install phpMyAdmin on Ubuntu

  • Foto del escritor: PixelHost
    PixelHost
  • 14 ago 2024
  • 4 Min. de lectura

PhpMyAdmin is a free, open-source graphical user interface (GUI) tool for managing MySQL databases on shared hosting plans and Virtual Private Servers (VPS). While not technically necessary, phpMyAdmin is easier to use than the command-line interface for managing databases.

If you host your website on a VPS, you’ll need to install phpMyAdmin on the server manually. This article will guide you through installing phpMyAdmin on Ubuntu 18.04 and 20.04 servers.

✅ Prerequisites for phpMyAdmin

Before you begin, you’ll need to install the LAMP stack (Linux, Apache, MySQL, PHP) on your server. Additionally, the MySQL database should be running.

You will also need to use an SSH client to connect to the server. We have a tutorial on how to connect PuTTY to the server if you’re having trouble with it.


🔄 How to Install phpMyAdmin on Ubuntu

Installing phpMyAdmin on Ubuntu involves five steps. In addition to the installation, you’ll need to grant permissions, create a separate user, and secure phpMyAdmin.


1️⃣ Install the phpMyAdmin Package:

Ubuntu 18.04:

Run the following command to install the phpMyAdmin package and the necessary PHP extensions:

bash
sudo apt-get install -y phpmyadmin php-mbstring php-gettext

During the installation process, you will need to select a web server to configure phpMyAdmin. Select Apache by pressing the spacebar. An asterisk will appear next to apache2, indicating that you have selected it. Press Enter to continue.

Now, configure the database. Select Yes.

Then, set a MySQL application password for phpMyAdmin. Make sure to use a strong, unique password. Verify it when prompted, and the installation will complete.

Ubuntu 20.04:

The steps are quite similar, but you’ll need to run this command instead:

bash
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

As with Ubuntu 18.04, select Apache2 and configure the database by setting a strong password for phpMyAdmin.

Finally, enable the PHP Mbstring extension with this command:

bash
sudo phpenmod mbstring

Restart the Apache service with this command:

bash
sudo systemctl restart apache2

2️⃣ Configure the User and Grant Permissions:

The default phpMyAdmin account has minimal options available. You’ll need to grant some permissions to phpMyAdmin to make it a practical solution for creating and managing MySQL databases.

To manage MySQL users, log in to the MySQL command line as the root user with this command:

bash
sudo mysql -u root -p

You will need to enter the MySQL root password before accessing the command line. Once you’ve accessed the MySQL root account, grant permissions to phpMyAdmin by running these commands one by one:

bash
GRANT ALL PRIVILEGES ON . TO 'phpmyadmin'@'localhost'; FLUSH PRIVILEGES; EXIT

3️⃣ Access phpMyAdmin from a Browser:

When the installation process is complete, open your browser and go to http://your-server-ip-address/phpmyadmin. Replace your-server-ip-address with the server’s IP address. If you’re using a PixelHost VPS, you’ll find the IP address in the server management panel.

The phpMyAdmin login page will look like this:


Due to security issues, Ubuntu 18.04 and Ubuntu 20.04 do not support logging in as root. Instead, log in with the phpMyAdmin username and the MySQL password you set during Step 1. After that, you will access the phpMyAdmin web interface.


4️⃣ Create a Separate phpMyAdmin User (Optional):

If you do not want to use or work with the default phpMyAdmin user account for security reasons, create a new dedicated MySQL user with full privileges.

You’ll need to access the MySQL command-line interface as the root user to create a dedicated user. Use this command to do so:

bash
sudo mysql -u root -p

Enter the MySQL root password when prompted. Then, enter the following commands to create a new user:

bash
CREATE USER 'username' IDENTIFIED by 'password'; GRANT ALL PRIVILEGES ON . TO 'username'@'localhost'; FLUSH PRIVILEGES; EXIT

Replace username and password with your desired MySQL credentials. Remember to use a strong password to secure the account.

Restart the Apache server if you encounter issues when logging in. Here’s the command to do so:

bash
sudo systemctl restart apache2

We recommend checking the Status tab in the phpMyAdmin control panel. It shows the number of connections to the MySQL database server, the current running queries, and how long the server has been operating.


5️⃣ Secure phpMyAdmin (Optional):

phpMyAdmin is vulnerable to cyberattacks, so you should implement measures like an additional authentication method to improve its security. Enable an extra login layer in front of the application using Apache's built-in authentication and authorization features.

To do this, enable the override of the .htaccess file by modifying the phpMyAdmin Apache configuration file. Here’s the command to open and edit the file using the Nano text editor:

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

Now, add a line AllowOverride All in the <Directory /usr/share/phpmyadmin> section.

It should look like this:

apache
<Directory /usr/share/phpmyadmin> Options SymLinksIfOwnerMatch DirectoryIndex index.php AllowOverride All </Directory>

Save and exit the file by pressing CTRL+X. Then, press Y and Enter when prompted. Restart the Apache web server to implement the changes with this command:

bash
sudo systemctl restart apache2

The next step is to create a .htaccess file in the phpMyAdmin application directory with the following command:

bash
sudo nano /usr/share/phpmyadmin/.htaccess

The Nano text editor will open, allowing you to edit the .htaccess file. Enter the following text:

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

Save and exit the file. Since .htaccess specifies that the password file is /etc/phpmyadmin/.htpasswd, we’ll need to use the same path.

Use this command to create the password file and pass it using the htpasswd utility:

bash
sudo htpasswd -c /etc/phpmyadmin/.htpasswd USERNAME

Replace USERNAME with the actual username. You’ll also need to enter and confirm a password. Once done, the file will be created, and the password will be encrypted.

You can create an additional username using the same command but excluding the -c option:

bash
sudo htpasswd /etc/phpmyadmin/.htpasswd ADDITIONAL_USERNAME

Restart Apache to implement the changes:

bash
sudo systemctl restart apache2

When accessing phpMyAdmin, a new username and password authentication dialog will appear. Verify it by visiting http://your-server-ip-address/phpmyadmin. The login dialog should look like this:

Enter the username and password you just created. After logging in, you’ll find the phpMyAdmin login page. Enter the phpMyAdmin user credentials to access the phpMyAdmin web interface.


🎯 Conclusion

phpMyAdmin helps you manage MySQL databases and perform table maintenance. The process of installing the application on Ubuntu 18.04 and Ubuntu 20.04 is similar but uses some different commands during the initial steps.

Don’t forget to implement security measures in phpMyAdmin by using strong passwords and an additional authentication method.

You should now be able to manage databases with ease from phpMyAdmin. Leave a comment if you have any questions.


Best Regards,


João @PixelHost.


 
 
 

Comments


bottom of page