Detailed tutorial on installing phpMyAdmin on Ubuntu 18.04

Detailed tutorial on installing phpMyAdmin on Ubuntu 18.04

We will install phpMyAdmin to work with Apache on Ubuntu 18.04.

Before installing phpMyAdmin you need to have installed the LAMP stack and provided the web page.

If it is not installed, you can refer to the installation of Apache, MySQL, PHP on Ubuntu 18.04 to install it first.

1. Install phpMyAdmin

Let's start by updating the package lists and installing phpMyAdmin on Ubuntu 18.04. Below we have two commands separated by &&. The first command will update the package lists to ensure you get the latest version of phpMyAdmin and its dependencies. The second command will download and install phpMyAdmin. When asked to continue, press y and hit enter.

$ sudo apt update && sudo apt install phpmyadmin

Depending on your setup, the order of the following screens in the phpMyAdmin package configuration may differ.

If you are prompted to select a web server, press the SPACE key to place an asterisk [*] next to apache2, then press the TAB key to highlight OK and press ENTER. This should look like the following:

After entering, it is as follows:

Select Yes and press ENTER to install and configure the database.

The MySQL application password is only used internally by phpMyAdmin to communicate with MySQL. You can leave this blank and a password will be automatically generated. Press Enter to continue.

2. Testing phpMyAdmin

You should now be able to access the phpMyAdmin web interface by visiting your server’s domain name or public IP address and /phpMyAdmin. For example: http://example.com/phpmyadmin or http://192.168.1.10 phpmyadmin
If you don't have a domain name yet or don't know your IP, you can find it out with the following command:

$ sudo service apache2 status 

When you first install MySQL, you need to set up a root user and password. However, remote login may be disabled for the root user.
If you get an error "Access denied for user 'root'@'localhost'", you should continue to Step 3 to create a superuser for phpMyAdmin.

3. Create MySQL User

If you are unable to log in as the root user above, you can now create a superuser account for phpMyAdmin.
In the terminal, log in to MySQL as the root user. You may have created a root password when you first installed MySQL.
Or the password is blank, in which case you can press ENTER when prompted for the password.

$ sudo mysql -p -u root 

Now add a new MySQL user with a username of your choice. In this example, we will call it pmauser (php my admin user).
Make sure to replace password_here with your own password (make up your own password).
The % symbol tells MySQL to allow this user to log in from anywhere remotely. If you want to increase security, you can use an IP address instead.

CREATE USER 'pmauser'@'%' IDENTIFIED BY 'password_here'; 

The password I set here is 123456. This is a weak password (it is easy to guess), and it is not recommended for everyone to use this password.

Now, we will grant superuser privileges to the new user pmauser.

GRANT ALL PRIVILEGES ON *.* TO 'pmauser'@'%' WITH GRANT OPTION;

Now exit MySQL.

exit

You should now be able to access phpMyAdmin using this new user account.
If you would like to set up some additional security for phpMyAdmin, continue to the next step.

4. Obfuscate phpMyAdmin URL

Bots and attackers are constantly scanning web servers looking for the default phpMyAdmin login page, so it is recommended that you change the URL to something else.
In this example, we will change it from example.com/phpmyadmin to example.com/pmahidden.
Open Apache's phpMyAdmin configuration file using the vi text editor. (If you are not used to vi, the visual text editor gedit is recommended)

$ sudo ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

Change the Alias ​​from /phpmyadmin to /pmahidden - you can change it to anything you want.

Save and exit vi.
Now you must reload the Apache service for the changes to take effect.

$ sudo vi /etc/apache2/conf-available/phpmyadmin.conf

You should now be able to access phpMyAdmin at example.com/pmahidden

5. Protect with .htpasswd

We can further protect the phpMyAdmin login page using .htpasswd. This adds another line of defense against bots and hackers.

5.1 Allow .htaccess overrides

To set up .htpasswd, we must first change the phpMyadmin Apache configuration file to allow .htaccess to override it.
Use vi to open the configuration file phpmyadmin.conf

$ sudo vi /etc/apache2/conf-available/phpmyadmin.conf

Add AllowOverride All below DirectoryIndex index.php as shown below:

Save and exit vi
Now reload the Apache service.

$ sudo service apache2 reload

5.2 Setting .htpasswd

We will use the gedit text editor to create a new .htaccess file in the phpMyAdmin installation directory.

$ sudo gedit /usr/share/phpmyadmin/.htaccess

Paste the following content into your .htaccess file.

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

Click the Save button to save, and click the Close button to exit.
Now, we can use the htpasswd tool to generate the .htpasswd file.

In this example, we created a new user called pmauser (php my admin user), although you can change it to anything you want.

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

You will be asked to enter a new password twice (Generate a Password).
Once that is done, you can now access phpMyAdmin in your browser and you should now be prompted for your login details.

Reference: Installing phpMyAdmin for Apache on Ubuntu 18.04

Summarize

The above is a detailed tutorial on how to install phpMyAdmin on Ubuntu 18.04. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Ubuntu View and modify mysql login name and password, install phpmyadmin
  • Detailed configuration of phpMyAdmin database management tool installation in Ubuntu 17.10
  • Analyze the configuration of Apache+PHP+PHPmyadmin+MYsql in Alibaba Cloud Ubuntu 12.04 environment

<<:  Detailed analysis of the difference between Ref and Reactive in Vue3.0

>>:  mysql 8.0.15 winx64 decompression version graphic installation tutorial

Recommend

Using MySQL in Windows: Implementing Automatic Scheduled Backups

1. Write a backup script rem auther:www.yumi-info...

How to fix abnormal startup of mysql5.7.21

A colleague reported that a MySQL instance could ...

Detailed steps to install python3.7 on CentOS6.5

1. Download Python 3 wget https://www.python.org/...

Windows Server 2008 R2 Multi-User Remote Desktop Connection Licensing

At work, we often need remote servers and often e...

Detailed steps for setting up a nexus server

1. The significance of building nexus service As ...

What you need to know about creating MySQL indexes

Table of contents Preface: 1. Create index method...

JavaScript destructuring assignment detailed explanation

Table of contents concept Array Destructuring Dec...

Implementation steps of mysql master-slave replication

Table of contents mysql master-slave replication ...

Solution to the paging error problem of MySQL one-to-many association query

The query data in the xml price inquiry contains ...

What is MIME TYPE? MIME-Types type collection

What is MIME TYPE? 1. First, we need to understand...

How to split data in MySQL table and database

Table of contents 1. Vertical (longitudinal) slic...