How To Install And Secure Phpmyadmin On Ubuntu 16.04
Introduction
While many users need the functionality of a database management system similar MySQL, they may non feel comfortable interacting with the system solely from the MySQL prompt.
phpMyAdmin was created so that users tin interact with MySQL through a web interface. In this guide, we'll discuss how to install and secure phpMyAdmin and then that you tin can safely use it to manage your databases from an Ubuntu 16.04 system.
Prerequisites
Before you become started with this guide, you lot need to take some basic steps completed.
First, we'll assume that you are using a not-root user with sudo privileges, as described in steps one-iv in the initial server setup of Ubuntu 16.04.
We're also going to presume that yous've completed a LAMP (Linux, Apache, MySQL, and PHP) installation on your Ubuntu 16.04 server. If this is not completed even so, you tin follow this guide on installing a LAMP stack on Ubuntu 16.04.
Finally, in that location are important security considerations when using software like phpMyAdmin, since it:
- Communicates straight with your MySQL installation
- Handles authentication using MySQL credentials
- Executes and returns results for arbitrary SQL queries
For these reasons, and because it is a widely-deployed PHP application which is frequently targeted for attack, you should never run phpMyAdmin on remote systems over a manifestly HTTP connection. If y'all do not have an existing domain configured with an SSL/TLS certificate, you can follow this guide on securing Apache with Let'south Encrypt on Ubuntu 16.04.
Once you are finished with these steps, you lot're ready to get started with this guide.
Pace One — Install phpMyAdmin
To get started, we will install phpMyAdmin from the default Ubuntu repositories.
Nosotros can do this by updating our local bundle index and then using the apt
packaging system to pull downward the files and install them on our organization:
- sudo apt-go update
- sudo apt-become install phpmyadmin php-mbstring php-gettext
This will ask you lot a few questions in guild to configure your installation correctly.
Warning: When the first prompt appears, apache2 is highlighted, but not selected. If you do non striking Space to select Apache, the installer will not movement the necessary files during installation. Striking Space, Tab, and then Enter to select Apache.
- For the server pick, choose apache2.
- Select yes when asked whether to use
dbconfig-mutual
to set up the database - You will be prompted for your database administrator's password
- Y'all will then be asked to choose and confirm a countersign for the
phpMyAdmin
application itself
The installation process actually adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/
directory, where it is automatically read.
The only affair we demand to practise is explicitly enable the PHP mcrypt
and mbstring
extensions, which nosotros can do past typing:
- sudo phpenmod mcrypt
- sudo phpenmod mbstring
Later, you'll need to restart Apache for your changes to be recognized:
- sudo systemctl restart apache2
You tin can now admission the web interface by visiting your server's domain name or public IP address followed by /phpmyadmin
:
https://domain_name_or_IP/phpmyadmin
You can at present log into the interface using the root
username and the authoritative password you lot 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
Nosotros were able to get our phpMyAdmin interface up and running fairly hands. Even so, we are not done yet. Because of its ubiquity, phpMyAdmin is a popular target for attackers. We should have extra steps to forbid unauthorized access.
Ane of the easiest way of doing this is to identify a gateway in front of the entire application. We can do this using Apache'southward built-in .htaccess
hallmark and authority functionalities.
Configure Apache to Allow .htaccess Overrides
Start, 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 together an AllowOverride All
directive within the <Directory /usr/share/phpmyadmin>
section of the configuration file, like this:
/etc/apache2/conf-available/phpmyadmin.conf
<Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php AllowOverride All . . .
When you have added this line, relieve and close the file.
To implement the changes y'all made, restart Apache:
- sudo systemctl restart apache2
Create an .htaccess File
Now that we have enabled .htaccess
employ for our application, we need to create ane to really implement some security.
In social club for this to be successful, the file must be created inside the awarding 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:
/usr/share/phpmyadmin/.htaccess
AuthType Basic AuthName "Restricted Files" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user
Let'south go over what each of these lines mean:
-
AuthType Bones
: This line specifies the hallmark type that we are implementing. This type will implement password authentication using a countersign file. -
AuthName
: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won't proceeds whatsoever information about what is beingness protected. -
AuthUserFile
: This sets the location of the password file that will be used for authentication. This should be exterior of the directories that are being served. We will create this file shortly. -
Require valid-user
: This specifies that but authenticated users should exist given access to this resources. This is what really stops unauthorized users from entering.
When yous are finished, save and close the file.
Create the .htpasswd file for Authentication
The location that we selected for our password file was "/etc/phpmyadmin/.htpasswd
". We tin at present create this file and pass it an initial user with the htpasswd
utility:
- sudo htpasswd -c /etc/phpmyadmin/.htpasswd username
You will be prompted to select and confirm a countersign for the user you are creating. Afterwards, the file is created with the hashed countersign that you entered.
If yous desire to enter an boosted user, you need to practise and so without the -c
flag, similar this:
- sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser
At present, when you access your phpMyAdmin subdirectory, you will be prompted for the additional business relationship proper name and password that you just configured:
https://domain_name_or_IP/phpmyadmin
After entering the Apache authentication, yous'll be taken to the regular phpMyAdmin hallmark page to enter your other credentials. This volition add together an additional layer of security since phpMyAdmin has suffered from vulnerabilities in the by.
Conclusion
You lot should now have phpMyAdmin configured and set to utilize on your Ubuntu sixteen.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.
Source: https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-16-04
Posted by: mercersheill.blogspot.com
0 Response to "How To Install And Secure Phpmyadmin On Ubuntu 16.04"
Post a Comment