In this tutorial, we are going to see How to Install PHPMyAdmin on Ubuntu 16.04 server.
MySQL is essential for all of the dynamic websites to run. There are many Database management systems available on the web.
MySQL is the best open source platform for Handling the database. It is widely used because of it’s functionality, simplicity and flexibility.
MySQL is not easy for all. Many of them are struggling to handle the MySQL through the prompt. People would like to use the web interface always. it will make the application more usable and intractable. Here comes the PHPMyAdmin.
In this article we are going to show you how to install phpmyadmin on ubuntu 16.04
What is PHPMyAdmin?
PHPMyadmin is the visualized application which works with MySQL to provide the user interface for handling the database.
You can create, manipulate and maintain the database visually simply using the mouse.
There is no commands involved in that action.
Requirements for Install PHP My Admin on Ubuntu 16.04
- First, you need to have your ubuntu server configured according to this ubuntu server setup guide.
- You should have installed the LAMP stack in your system already. Follow this install lamp stack on ubuntu article to complete the lamp installation.
- PHPMyAdmin directly communicate the MySQL. If you have hosted your MySQL on a remote server, then you are strongly recommended to encrypt the connection between the servers.
- As because PHPMyAdmin directly handling the credentials, you cannot leave the connection unencrypted. MySQL is widely used by web developers. it is one of the major reason for being targeted by hackers all around the world. So, be careful about it.
Install PHP MyAdmin on Ubuntu
The beauty of the Ubuntu is it’s repositories. There are plenty applications are there in repository. All you have to do is just execute one command to install them.
PHPMyAdmin is also available in Ubuntu repository.
First, let us update the package index using the below command.
$ sudo apt-get update
Next use apt packaging system to download PHPMyAdmin to the server.
$ sudo apt-get install phpmyadmin php-mbstring php-gettext
You will be prompted to answer few questions regarding the installation. just go through them to finish the process.
When prompt highlights apache 2, hit space, tab and then enter to select apache.
To configure phpmyadmin ubuntu, Choose Yes for
dbconfig-common. It will setup the database.
Now, you have to enter the database administrator password.
After that, you have to set a password for PHPMyAdmin and confirm it.
When you install the PHPMyAdmin, it will add a configuration file in Apache directory.
Once you are done with the above tasks, now, it’s time to activate two plugins mcrypt and mbstring.
$ sudo phpenmod mcrypt $ sudo phpenmod mbstring
Just, execute the above command. it will finish the activation task.
In order for the apache to work with the PHPMyAdmin, restart the Apache.
$ sudo systemctl restart apache2
Now, PHPMyAdmin is ready to work. You can open PHPMyAdmin by visiting the public IP address of your server on your browser.
To Login to the PHPMyAdmin, use root as user name and enter the password which you have created when installing MySQL.
Once you done with the above instructions for install phpmyadmin on ubuntu 16.04 server, follow below instructions for securing the PHP MyAdmin.
Securing the PHP MyAdmin To Restrict Unauthorized Access
As we have discussed earlier, PHPMyAdmin is widely used by many developers for it’s ease of use. So, you have to take an extra step to protect your PHPMyAdmin.
Since it’s widely used, the attacks on the application is also high. Here, we can prevent the attacks simply using the apache .htaccess authentication.
We will put a gateway infront of the application.
Our next tasks is edit the Apache configuration file to allow .htaccess file overrides.
We have to open the Apache configuration file for PHP using the nano editor. Here is the command for that.
$ sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Inside the file, look for <Directory /usr/share/phpmyadmin> section and add the below line.
<Directory /usr/share/phpmyadmin> Options FollowSymLinks DirectoryIndex index.php AllowOverride All . . .
Once you added the lines, save and close the file.
Now, Restart the apache to make the changes to work.
$ sudo systemctl restart apache2
In the above steps, we have enabled the usage of .htaccess for PHPMyAdmin application.
We have to create a .htaccess file inside the application directory inorder to secure the application.
To create the file, use below command.
$ sudo nano /usr/share/phpmyadmin/.htaccess
Enter the below lines inside the file.
AuthType Basic AuthName "Restricted Files" AuthUserFile /etc/phpmyadmin/.htpasswd Require valid-user
Then save and close the file.
The above lines works as the small function which will prompt for information when some one trying to access the PHPMySQL.
Many people have question about how to open phpmyadmin in ubuntu. For local users, you can use your browser to loginto phpmyadmin.
let us see the meaning of each line.
AuthType Basic: This line represents the authentication type which we are going to use. We will do password protection with a simple password file.
AuthName: This line specifies the message which will be used in the dialogue box when some trying to access PHPMyAdmin.
AuthUserFile: This line points the location of the password file which we are going to use in for authentication. This file should be placed out of the files which we will serve.
Require valid-user: This line tells only authorized user has to be allowed and others has to be restricted.
Here is the command to create the .htpasswd file at /etc/phpmyadmin/.htpasswd.
We have to create the file using htpasswd utility.
$ sudo htpasswd -c /etc/phpmyadmin/.htpasswd username
After that, you will be asked to enter and confirm a password for the user. Your password will be stored.
If you want to add more user, use the below command. It is same as above, but, we will just don’t use -c here.
$ sudo htpasswd /etc/phpmyadmin/.htpasswd user2
Now, if you go to the PHPMyAdmin in your server through browser, you will be asked to enter the password. A pop window will appear asking for user name and password.
Once you enter the user name and password, you will be allowed access the normal PHPMyAdmin page where you can enter the login credentials to access it.
Uninstall PHPMyadmin Ubuntu
If you want to uninstall PHP My Admin on ubuntu, use this below command.
$ sudo apt-get remove phpmyadmin
Securing PHPMyAdmin is important after the installation. Having one more layer for the protection is the best way to avoid the attacks. There have been many attacks on the application from the beginning.
Take precaution. if you have any issues in executing this install phpymadmin on ubuntu 16.04 article, then leave comment here.