How to Install PhpMyAdmin
Introduction
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 from an Ubuntu 16.04 system.Prerequisites
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 16.04. We’re also going to assume that you’ve completed a LAMP (Linux, Apache, MySQL, and PHP) installation on your Ubuntu 16.04 server. If this is not completed yet, you can follow this guide on installing a LAMP stack on Ubuntu 16.04. Finally, there are important security considerations when using software like phpMyAdmin, since it:- Communicates directly with your MySQL installation
- Handles authentication using MySQL credentials
- Executes and returns results for arbitrary SQL queries
Step One €” Install phpMyAdmin
To get started, we will 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 php-mbstring php-gettext
- For the server selection, choose apache2.
- Select yes when asked whether to use dbconfig-common to set up the database
- You will be prompted for your database administrator’s password
- You will then be asked to choose and confirm a password for the phpMyAdmin application itself
- sudo phpenmod mcrypt
- sudo phpenmod mbstring
- sudo systemctl restart apache2
https://domain_name_or_IP/phpmyadmin
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:Step Two €” Secure your phpMyAdmin Instance
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 should take extra steps to prevent unauthorized access.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.
Configure Apache to Allow .htaccess Overrides
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
<Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php AllowOverride All . . .
When you have added this line, save and close the file. To implement the changes you made, restart Apache:- sudo systemctl restart apache2
Create an .htaccess File
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
AuthType BasicAuthName “Restricted Files”AuthUserFile /etc/phpmyadmin/.htpasswdRequire valid-user
Let’s go over what each of these lines mean:- AuthType Basic: This line specifies the authentication type that we are implementing. This type will implement password authentication using a password file.
- AuthName: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won’t gain any information about what is being protected.
- AuthUserFile: This sets the location of the password file that will be used for authentication. This should be outside of the directories that are being served. We will create this file shortly.
- Require valid-user: This specifies that only authenticated users should be given access to this resource. This is what actually stops unauthorized users from entering.
Create the .htpasswd file for Authentication
The location that we selected for our password file was “/etc/phpmyadmin/.htpasswd”. We can now create this file and pass it an initial user with the htpasswd utility:- sudo htpasswd -c /etc/phpmyadmin/.htpasswd username
- sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser
Comments
Post a Comment