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

About the problem of offline installation of Docker package on CentOS 8.4

The virtual machine used is CentOS 8.4, which sim...

VSCode configuration Git method steps

Git is integrated in vscode, and many operations ...

Some suggestions for improving Nginx performance

If your web application runs on only one machine,...

Analysis of Linux kernel scheduler source code initialization

Table of contents 1. Introduction 2. Basic Concep...

How to use docker+devpi to build local pypi source

Some time ago, I needed to use pip downloads freq...

Implementation of MySQL scheduled database backup (full database backup)

Table of contents 1. MySQL data backup 1.1, mysql...

How to create LVM for XFS file system in Ubuntu

Preface lvm (Logical Volume Manager) logical volu...

Vue implements file upload and download functions

This article example shares the specific code of ...

Beginners learn some HTML tags (2)

Related article: Beginners learn some HTML tags (1...

Detailed explanation of Javascript basics

Table of contents variable Data Types Extension P...

Summary and practice of javascript prototype chain diagram

Table of contents Prototype chain We can implemen...

MYSQL uses Union to merge the data of two tables and display them

Using the UNION Operator union : Used to connect ...

The specific use and difference between attribute and property in Vue

Table of contents As attribute and property value...