Install phpMyAdmin on Ubuntu

phpMyadmin is open-source web application that provides graphical interface for MySql or MariaDB database. Many users don't use direct MySQL command prompt and only use graphical interface. So with phpMyAdmin, you can run, get all MySQL query in graphical interface.

Prerequisites

You need to have non-root user account logged in with sudo privileges to set up on your server. You also have LAMP installed in your server or else Install LAMP.

This tutorial will show you how to install phpMyAdmin in Ubuntu step by step.

Step 1: Update package repository

Open the terminal either by using the CTRL+ALT+T keyboard shortcut or search Terminal from menu. Now run following command in terminal.

sudo apt-get update

Step 2: Install phpMyAdmin

After update package repository, run bellow command, it will start installing phpMyAdmin.

sudo apt install phpmyadmin php-mbstring php-gettext

During installation, it will ask for configuration as bellow images. Press TAB button for navigation, and hit SPACE button on apache2, it will select apache2 as web server for phpMyAdmin. Again press TAB and go to <ok> button and press ENTER.

After that new screen will display as bellow picture. It will ask whether to use dbconfig-common to set up the database. Press ENTER on <Yes> option.

Now it will ask to enter MySQL root password and confirmation. Enter password and It will create phpmyadmin database with required configuration and privileges.

Step 3. Configure phpMyAdmin

First edit bellow file by running command with nano editor.

sudo nano /etc/apache2/apache2.conf

Then add the bellow lines at the bottom of the file:

Include /etc/phpmyadmin/apache.conf

Save the file by pressing CTRL+X and SHIFT+Y. Restart the apache2 server.

sudo service apache2 restart

Now go to your-website.com/phpmyadmin or ip-address/phpmyadmin url or in case local server, go to localhost/phpmyadmin and you can see bellow screen:

Enter root user and password and hit enter, you will see bellow screen:

Step 3. Secure phpMyAdmin

phpMyAdmin lets you access your website database, so it is important to provide more security to access phpMyAdmin. Follow these steps to secure phpMyAdmin. Edit bellow file by running command with nano editor.

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

Find the bellow lines in <Directory> tags and add the AllowOverride ALL directive in that.

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

</Directory>

Now create new .htaccess File with command.

sudo nano /usr/share/phpmyadmin/.htaccess

Put the bellow lines.

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

Save the file by pressing CTRL+X and SHIFT+Y. Restart the apache2 server.

sudo systemctl restart apache2

Now create new user

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

It will ask enter password and confirm password. If you want to create new user, run the command without -c flag like this

sudo htpasswd /etc/phpmyadmin/.htpasswd newusername

Now whenever you try to access your phpMyAdmin, new it will prompt for username and password:

Conclusion

So now you have successfully installed phpMyAdmin on your Ubuntu server. Now you can perform all SQL query with graphical interface.

If you have any questions or comments about this article, feel free to write in bellow comment section.

Tags: