Introduction
phpMyAdmin is a free application for managing a MySQL server.
Installing phpMyAdmin allows management of MySQL databases through a user-friendly interface, instead of entering commands into the terminal.
This guide will help you install phpMyAdmin on Ubuntu 18.04, with additional security features.
Prerequisites
- A server running Ubuntu 18.04
- A fully installed LAMP stack (Linux, Apache, MySQL, PHP)
- Ubuntu user account with sudo privileges
This guide assumes you’re installing to a local system. If you need to set up encryption or security certificates for configuring a remote server, please refer to this guide on open SSL.
Note: If you’re connecting to a remote server, there’s a security risk in running phpMyAdmin over plain HTTP. A plain HTTP connection is unencrypted and can be intercepted. Also, since phpMyAdmin is a popular application, it’s a common vector for attack.
Installing phpMyAdmin on Ubuntu
Step 1: Add and Update Software Repositories
Some Ubuntu 18.04 installations are not configured with the software repositories for phpMyAdmin.
To add them, open a terminal window and enter the following command:
sudo add-apt-repository universe
The system should ask for your password – enter it, then make sure it completes successfully. Once completed, refresh the software lists by entering the following:
sudo apt-get update && sudo apt-get upgrade
Allow the process to finish.
Step 2: Install phpMyAdmin
To install phpMyAdmin, enter the command:
sudo apt-get install phpmyadmin
The system should ask for confirmation – press Y then enter, and the system should download and install the phpMyAdmin software package.
Step 3: Configure phpMyAdmin on Ubuntu
Shortly after you start the installation, the installer will prompt you to choose which web server should be automatically configured.
Select apache2 (use spacebar to choose), press Tab to navigate to <ok> and hit Enter.
Next, the installer will note that you have to have a database installed and configured before you can use phpMyAdmin. Select <Yes> and hit Enter.
Note: If you’re an advanced user, you can manually configure the database, but doing so is outside the scope of this guide. Find more information on dbconfig-common
on Debian's official site.
Shortly after, the installer will ask you to provide a password. The installer creates a default user named “phpMyAdmin” and the password you type here will work as an administrator password for this user.
Type a strong password and hit Enter, then confirm the password and hit Enter again.
Leaving the password field blank will cause the system to generate a random password.
Step 4: Enable the mbstring Extension
Mbstring is an extension for PHP. It helps email and .pdf files to work correctly, but it’s not enabled by default.
Enter the following in your terminal to enable mbstring:
sudo phpenmod mbstring
Press Enter and allow the process to finish.
Restart the Apache service to refresh the changes by entering the following in a terminal:
sudo systemctl restart apache2
Step 5: Create a New MySQL Administrator Account
By default, MySQL 5.7 and later in Ubuntu, authenticate a root user using auth_socket. This compares the socket username against the name specified in the MySQL user table and is a tightly-secured authentication method. However, this can make it difficult to use phpMyAdmin.
It is possible to change the authentication type, but it’s simpler to create a new administrator account for MySQL.
Log in to the MySQL server as follows:
sudo mysql
This should change the terminal prompt to show mysql>, indicating that you’re logged into the MySQL shell.
Enter the following commands, replacing UserName with a username of your choice, and PassWord with a strong password of your choice:
CREATE USER 'UserName'@'localhost' IDENTIFIED BY 'PassWord';
GRANT ALL PRIVILEGES ON *.* TO 'padmin'@'localhost' WITH GRANT OPTION;
Once the operation completes, exit the MySQL shell by entering:
exit
Step 6: Test phpMyAdmin
Open up a browser window and enter your server’s IP address or domain name, followed by /phpMyAdmin:
192.168.0.1/phpMyAdmin
www.domain.com/phpMyAdmin
The browser should display a screen welcoming you to phpMyAdmin, with a login field. Enter the username and password you created. The browser should load the phpMyAdmin dashboard.
Secure phpMyAdmin
Being easy to use – and free – makes phpMyAdmin a target for hackers. Follow these steps to use Apache’s built-in features to restrict access and secure phpMyAdmin directories.
Enable .htaccess
In a terminal window, enter the following command to edit the phpMyAdmin.conf file:
sudo nano /etc/apache2/conf-available/phpMyAdmin.conf
In the editor, scroll down to the section labeled <Directory /usr/share/phpMyAdmin>
. You should see the following two lines:
Options FollowSymLinks
DirectoryIndex index.php
Just below these entries, add the following text:
AllowOverride All
Save the file and exit. Then apply the changes by restarting Apache with the following terminal command:
sudo systemctl restart apache2
Create .htaccess File
The .htaccess file allows a more detailed configuration of the Apache web server. Enter the following in the terminal:
sudo nano /usr/share/phpMyAdmin/.htaccess
This will create a new file and open it in a text editor.
In the text editor, enter the following lines:
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpMyAdmin/.htpasswd
Require valid-user
Save the file and close.
These commands configure .htaccess to use basic authentication, to secure restricted files only to valid users, and where to find a list of valid users.
Note: For additional configuration options refer to this detailed guide on configuring .htaccess on Apache.
Setup .htaccess Users
This step creates a username and password to access the phpMyAdmin directory. This will force anyone trying to access the phpMyAdmin directory to enter a username and password.
In the terminal window, enter the following:
sudo htpasswd -c /etc/phpMyAdmin/.htpasswd UserName
Replace UserName with the actual username you want to use to access the phpMyAdmin directory. The system will prompt you to enter and confirm a password.
If you need to add additional users, use the same command without the –c
switch, as follows:
sudo htpasswd /etc/phpMyAdmin/.htpasswd SecondUser
Test the Login
Go back to your browser window, and open
IP_address/phpMyAdmin
.
The system should prompt you with a pop-up that asks for credentials, saying “Restricted files.” Enter the username and password you created earlier.
You should now see the phpMyAdmin login screen. Enter your credentials, and the system should display the phpMyAdmin user interface.
Conclusion
Great job, you now know how to install phpMyAdmin on Ubuntu.
You should now be able to manage your MySQL database from the phpMyAdmin tool. This includes managing users, creating databases, and much more.
PhpMyAdmin replaces the command-line interface used in this guide with a more intuitive utility to simplify database management tasks.
Next you should also read
How to Install and Secure phpMyAdmin on Debian 9
April 15, 2020
This guide is for users who are running a Debian 9 server with Apache, MySQL, and PHP. The phpMyAdmin…
How to List All Users in a MySQL Database
November 18, 2019
This simple tutorial analyses the commands used to list all user accounts in MySQL. Learn about additional…
How To Create New MySQL User and Grant Privileges
September 18, 2019
MySQL is a database application for Linux. It’s part of the LAMP (Linux, Apache, MySQL, PHP) stack that…
How to Enable & Set Up .htaccess File on Apache
April 9, 2019
The .htaccess file in Apache is a tool that allows configurations at the directory and subdirectory level.…
How to Install the LAMP Stack on Ubuntu 18.04
March 6, 2019
A LAMP stack is a set of open source software used for web application development. For a web application to…
How to Install phpMyAdmin on CentOS 7
October 22, 2018
This guide is for users who have already configured a CentOS server and installed the Apache HTTP services,…
Author
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.