Digity Republic

Tech News, Reviews, Deals, and How-To's

Installing phpMyAdmin for Apache and securing it in Ubuntu 20.04

Installing phpMyAdmin

image of Installing phpMyAdmin

Installing phpMyAdmin: In this tutorial, we’ll set up Ubuntu Server 20.04 with phpMyAdmin installed and secured so it can function with Apache.

Installing phpMyAdmin: Prerequisites


In the beginning, According to the instructions in Ubuntu 20.04 Initial Server Setup, you should use a non-root account with sudo capabilities.

Before continuing with this method, you should also have your LAMP stack for Ubuntu 20.04 installed and ready-to-serve web pages.

Installing phpMyAdmin: 1. Activate phpMyAdmin

Here, Let’s start by installing phpMyAdmin on Ubuntu 20.04 and updating the package lists.

Firstly, Below are two instructions that are spaced apart by &&. To guarantee that you receive the most recent version and dependents for phpMyAdmin, the first command will update the package lists. A few other additions that are suggested for usefulness and performance are also included.

sudo apt update && sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl

If you are prompted to continue, hit y and ENTER.

1.1. choose apache2

If you are asking to select a web server, type apache2, and press SPACE to highlight it with a star [*]. Then, type OK and press ENTER.

Installing phpMyAdmin

1.2. Set up the database

To install and set up the database, choose Yes and hit ENTER.

1.3. Application Password

Furthermore, It is not advised that you use the MySQL application password to log into phpMyAdmin since it utilizes phpMyAdmin to connect with MySQL internally. If you leave this empty, an automatic password generator will create one for you.

To continue, key in ENTER.

Installing phpMyAdmin

Then restart Apache and activate the “mbstring” PHP extension.

sudo phpenmod mbstring
sudo service apache2 reload

Installing phpMyAdmin: 2. Examine phpMyAdmin.

Secondly, By going to your server’s domain name or public IP address followed by /PHPMyAdmin, for example, http://example.com/phpmyadmin or http://192.168.1.10/phpmyadmin, you should now be able to view the phpMyAdmin web interface.

If you don’t yet have a domain name or are unsure about your IP address, use the following to find out:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
Installing phpMyAdmin

phpMyAdmin and the root account for MySQL

The error “Access forbidden for user ‘root’@’localhost'” may appear if you attempt to access phpMyAdmin using the MySQL root account in MySQL versions 5.7 and above. Make a separate superuser account exclusively for phpMyAdmin instead. Can’t log into phpMyAdmin with root if you wish to force MySQL to enable root login

Installing phpMyAdmin: 3. Make a MySQL Superuser.

Thirdly, Use the root account to access MySQL in the terminal. You shouldn’t need to input your root password when using sudo to log in.

sudo mysql

If this method of logging in is giving you trouble, use the command listed below to force a password prompt. When you initially installed MySQL, you could have set a root password, or it might be empty. See Reset MySQL Root Password if you’ve lost your MySQL root password.

sudo mysql -u root -p

Add a new MySQL superuser with the username of your choosing after logging in. We’re going to call it pmauser in this case. Replace the password here below with a strong password you create by clicking here.

CREATE USER 'pmauser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password_here';

Now give our new user pmauser superuser rights.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'localhost' WITH GRANT OPTION;

Close MySQL.

mysql> exit

Using this new user account, you ought to be able to access phpMyAdmin at this point.

You should follow the instructions below to add some extra protection to phpMyAdmin.

Installing phpMyAdmin: 4. A mysterious phpMyAdmin URL

Fourthly, It advises that you alter the URL since bots are constantly searching web servers for the standard phpMyAdmin login page.

We’re going to alter it in this example from example.com/phpmyadmin to example.com/pmahidden.

Use the nano text editor to access the phpMyAdmin configuration file for Apache.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Replace /PHPMyAdmin with /pmahidden in the Alias field. You may modify this to whatever name you choose.

/etc/apache2/conf-available/phpmyadmin.conf
# phpMyAdmin default Apache configuration

Alias /pmahidden /usr/share/phpmyadmin

(Press CTRL + X, Y, and ENTER to save and leave.)

For modifications to take effect, you must now reload the Apache service.

sudo service apache2 reload

At example.com/pmahidden, you should now be able to access phpMyAdmin.

Installing phpMyAdmin: 5. Protect with .htpasswd

Fifthly, With. htpasswd, we may better secure the phpMyAdmin login page. This adds an additional layer of protection against attacks and bots.

5.1 Allow.htaccess Overrides

To enable.htaccess Overrides, we must first modify the phpMyadmin Apache configuration file before configuring.htpasswd.

Launch the nano text editor and select the config file.

sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Also Under DirectoryIndex index.php, add AllowOverride All.

/etc/apache2/conf-available/phpmyadmin.conf
<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php
    AllowOverride All

(Press CTRL + X, Y, and ENTER to save and leave.)

Then Restart the Apache service right now.

sudo service apache2 reload

5.2. Set up .htpasswd

Moreover, Using the nano text editor, we’ll make a new.htaccess file in the phpMyAdmin installation directory.

sudo nano /usr/share/phpmyadmin/.htaccess

Now Add the next by pasting. (If using PuTTY on Windows, press the right mouse button to paste.)

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /etc/phpmyadmin/.htpasswd
Require valid-user

(Press CTRL + X, Y, and ENTER to save and leave.)

So, The htpasswd utility may now use to create the.htpasswd file.

Although you may modify this, in this example we are establishing a new account with the name pma

user (Php my admin user).

sudo htpasswd -c /etc/phpmyadmin/.htpasswd pmauser

Now You will prompt again for a new password (Click here to generate a strong password).

Then, It’s all over; you’re done. Now that you have visited phpMyAdmin in your browser, you ought to request your login information.

Frequently Asked Questions:

Is phpMyAdmin required for Apache?

Since the whole phpMyAdmin user interface is browser-based, you’ll need a web server (like Apache, Nginx, or IIS) to put the program’s files onto.

unable to access Ubuntu’s phpMyAdmin?

It sounds like PHP is not installed or set properly on your computer. according to the manual you mentioned “You need to have LAMP installed on your server before using phpMyAdmin. The guide for setting up the Linux, Apache, MySQL, and PHP stack may find here if you don’t already have it on your server.”

How do I start Apache with phpMyAdmin?

To use phpMyAdmin after installation, go to your browser, You ought to can log in with any MySQL users you are creating. If no users configuring, log in as admin with no password. then decide on Apache 2 as the web server you want to set up.

Editor’s choice: Installing and setting up Postfix in Ubuntu 20.04

Installing LEMP (Linux, Nginx, MySQL, and PHP) on Ubuntu 20.04

Do You Need More Help?

Visit our forum, describe your question briefly and get answers