While many users need the functionality of a database management system like MySQL, they may not feel comfortable interacting with the system solely from the MySQL prompt.
phpMyAdmin was created so that users can interact with MySQL through a web interface. In this guide, we’ll discuss how to install and secure phpMyAdmin so that you can safely use it to manage your databases on Ubuntu 14.04.
Note: phpMyAdmin can be installed automatically on your Droplet by adding this script to its User Data when launching it. Check out this tutorial to learn more about Droplet User Data.
Before you get started with this guide, you need to have some basic steps completed.
First, we’ll assume that you are using a non-root user with sudo privileges, as described in steps 1-4 in the initial server setup of Ubuntu 14.04.
We’re also going to assume that you’ve completed a LAMP (Linux, Apache, MySQL, and PHP) installation on your Ubuntu 14.04 server. If this is not completed yet, you can follow this guide on installing a LAMP stack on Ubuntu 14.04.
Once you are finished with these steps, you’re ready to get started with this guide.
To get started, we can simply install phpMyAdmin from the default Ubuntu repositories.
We can do this by updating our local package index and then using the apt
packaging system to pull down the files and install them on our system:
sudo apt-get update
sudo apt-get install phpmyadmin
This will ask you a few questions in order to configure your installation correctly.
Warning
When the first prompt appears, apache2 is highlighted, but not selected. If you do not hit “SPACE” to select Apache, the installer will not move the necessary files during installation. Hit “SPACE”, “TAB”, and then “ENTER” to select Apache.
dbconfig-common
to set up the databasephpMyAdmin
application itselfThe installation process actually adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/
directory, where it is automatically read.
The only thing we need to do is explicitly enable the php5-mcrypt
extension, which we can do by typing:
sudo php5enmod mcrypt
Afterwards, you’ll need to restart Apache for your changes to be recognized:
sudo service apache2 restart
You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin
:
<pre> http://<span class=“highlight”>domain_name_or_IP</span>/phpmyadmin </pre>
You can now log into the interface using the root
username and the administrative password you set up during the MySQL installation.
When you log in, you’ll see the user interface, which will look something like this:
We were able to get our phpMyAdmin interface up and running fairly easily. However, we are not done yet. Because of its ubiquity, phpMyAdmin is a popular target for attackers. We need to secure the application to help prevent unauthorized use.
One of the easiest way of doing this is to place a gateway in front of the entire application. We can do this using Apache’s built-in .htaccess
authentication and authorization functionalities.
First, we need to enable the use of .htaccess
file overrides by editing our Apache configuration file.
We will edit the linked file that has been placed in our Apache configuration directory:
sudo nano /etc/apache2/conf-available/phpmyadmin.conf
We need to add an AllowOverride All
directive within the <Directory /usr/share/phpmyadmin>
section of the configuration file, like this:
<pre> <Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php <span class=“highlight”>AllowOverride All</span> . . . </pre>
When you have added this line, save and close the file.
To implement the changes you made, restart Apache:
sudo service apache2 restart
Now that we have enabled .htaccess
use for our application, we need to create one to actually implement some security.
In order for this to be successful, the file must be created within the application directory. We can create the necessary file and open it in our text editor with root privileges by typing:
sudo nano /usr/share/phpmyadmin/.htaccess
Within this file, we need to enter the following information:
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user
Let’s go over what each of these lines mean:
When you are finished, save and close the file.
Now that we have specified a location for our password file through the use of the AuthUserFile
directive within our .htaccess
file, we need to create this file.
We actually need an additional package to complete this process. We can install it from our default repositories:
sudo apt-get install apache2-utils
Afterward, we will have the htpasswd
utility available.
The location that we selected for the password file was “/etc/phpmyadmin/.htpasswd
”. Let’s create this file and pass it an initial user by typing:
<pre> sudo htpasswd -c /etc/phpmyadmin/.htpasswd <span class=“highlight”>username</span> </pre>
You will be prompted to select and confirm a password for the user you are creating. Afterwards, the file is created with the hashed password that you entered.
If you want to enter an additional user, you need to do so without the -c
flag, like this:
<pre> sudo htpasswd /etc/phpmyadmin/.htpasswd <span class=“highlight”>additionaluser</span> </pre>
Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured:
<pre> http://<span class=“highlight”>domain_name_or_IP</span>/phpmyadmin </pre>
After entering the Apache authentication, you’ll be taken to the regular phpMyAdmin authentication page to enter your other credentials. This will add an additional layer of security since phpMyAdmin has suffered from vulnerabilities in the past.
You should now have phpMyAdmin configured and ready to use on your Ubuntu 14.04 server. Using this interface, you can easily create databases, users, tables, etc., and perform the usual operations like deleting and modifying structures and data.
To learn how to further secure your interactions with the server by encrypting your communication with SSL, check out our article on setting up SSL certificates with phpMyAdmin.
<div class=“author”>By Justin Ellingwood</div>
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Got an 404 error when I access http://domain_name_or_IP/phpmyadmin
Solution: manually copy over the the PHPMyAdmin Apache conf file over to the conf-available directory:
sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
Then enabled the Apache conf file using a2enconf:
sudo a2enconf phpmyadmin
The .conf file for me wasn’t put in the right place either. You need to manually copy it over like this:
sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.conf
@yalunren: To change the url, edit the phpmyadmin.conf file:
<pre> sudo nano /etc/apache2/conf-available/phpmyadmin.conf </pre>
File the “Alias” line and change the first part to the url you want. For instance, change:
<pre> Alias /phpmyadmin /usr/share/phpmyadmin </pre>
to
<pre> Alias /somethingelse /usr/share/phpmyadmin </pre>
Then restart Apache:
<pre> sudo service apache2 restart </pre>
Now, phpmyadmin is available at http://your.ip.address/somethingelse
Thanks for the tutorial. Very helpful. Just have one question. How to I change the phpmyadmin default http directory? I mean I don’t want to use http://ip/phpmyadmin as visiting link because it’s too easy to guess.
Thanks!
Please ignore the above Q. I’ve managed to solve it.
Now when I go to
the file is empty.
Is it normal?
I get a 404 not found error You can create a link:
sudo ln -s /usr/share/phpmyadmin /var/www/html
@nubletss: Delete the current user:
and then re-add it with a new password:
@luisdiazvenero: Can you pastebin the contents of
/etc/apache2/conf-available/phpmyadmin.conf
?Thanks for the heads up everyone.
The problems that you are describing indicate that you never actually selected “Apache” for your web server during the phpMyAdmin installation processes. Although that option is highlighted by the installer, you need to hit “SPACE” to check the box and select that option.
This is the part of the configuration that lets phpMyAdmin know that you wish to move the files into the Apache configuration hierarchy.
I have updated the guide to make this a bit more clear. Please let us know if you have any additional problems.
Please please please 🤗😭😩😫😠😡
The digital ocean team is requesting that you update this page. According to the information given here, we tried to create PHP My Admin Panel on my digitalocean console but But I have had 10 - 20 problems, whose solution has not been explained here. We request you that Upload a screen recording video, It explains how PHP My Admin Panel creates. With the help of which we will be able to create step by step PHP My Admin Panel.
Mainly include the following problems on Windows 10 Desktop Computer.
That’s why we deleted the Maid admin panel.
We once again installed the php admin panel.
This time our website URL did not open nareshmeena.com/phpMyAdmin .
Many times " the file is empty" this message comes.
So we have installed the PHP My Admin panel several times and even deleted it, we still can not make the PHP MY Admin panel.
🤗 Some time ago we had installed a plugin on our wp website. After installing which we were unable to login to our site. The website is completely closed. That’s why we tried to remove plugin through the PHP My Admin Panel.
More than a million people visit our website every day. Please help us.