Install phpMyAdmin on Ubuntu 18.04

We will install phpMyAdmin with Apache to work together on Ubuntu18.04.
Before installing phpMyAdmin need to have installed the LAMP stack and provides a web page.

If you do not you can refer to on Ubuntu 18.04 installed Apache, MySQL, PHP to be installed.

1. Install phpMyAdmin

Let's start from the updated list of packages and install phpMyAdmin on Ubuntu 18.04. Here we have two commands with && separated. The first command will update the list of packages to make sure you get the latest version of phpMyAdmin and dependencies. The second command will download and install phpMyAdmin. When asked to continue, y and press Enter .

$ sudo apt update && sudo apt install phpmyadmin

Depending on your settings, in the following order phpMyAdmin package configuration screens may vary.

If you are prompted to select the web server, press the SPACE key to put an asterisk next to the apache2 [*], and then press the TAB key to highlight OK and press the ENTER key as shown below:

Enter the following:

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

MySQL applications only within phpMyAdmin password used for communicating with MySQL. You can leave this blank , the password will be automatically generated. Press the Enter key to continue.

2. Test phpMyAdmin

You should now be able to access phpMyAdmin web interface through the domain name or IP address of the public to access the server and / phpMyAdmin. For example: http: //example.com/phpmyadmin or http://192.168.1.10 phpmyadmin
if you do not have a domain name or do not know your IP, you can find the following command:

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

When you first install MySQL, you need to set the root user and password. However, users may disable remote root login.
If you get an error 'user' root '@' localhost 'access denied ", you should proceed to Step 3, creating a super-user phpMyAdmin.

3. Create MySQL user

If you can not be above the root user logged in, you can now create a super user account for phpMyAdmin.
In the terminal, log in as root MySQL. You may have created the first time you install a MySQL root password,
or the password is blank, in which case, you can enter the password when prompted press the ENTER .

$ sudo mysql -p -u root

Now with a user name that you choose to add a new MySQL user. In this example, we will call pmauser (PHP User My ADMIN) .
Be sure to password_here with your own password (make yourself a password).
% Symbol tells MySQL to allow the user to log in from anywhere remotely. If you want to increase security, you can use an IP address instead of it.

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

I am here to set the password is 123456. This is a weak password (it is easy to guess), I do not recommend that you use this password.

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

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

Now exit MySQL.

exit

You should now be able to use this new user account access to phpMyAdmin.
If you want to set up some extra security for phpMyAdmin, proceed to the next step.

4. blur phpMyAdmin URL

Robots and attackers constantly scan the web server, phpMyAdmin to find the default login page, we recommend that you change the URL to something else.
In this example, we'll put it from example.com/phpmyadmin change example.com/pmahidden .
Using the vi text editor to open the Apache configuration file phpMyAdmin. (If not used vi , recommended the visual text editor gedit )

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

The Alias ​​(alias) changed from / phpmyadmin is / pmahidden - you can change it to anything you want.

Save and exit vi .
Must now reload the Apache service for the change to take effect.

$ sudo service apache2 reload

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

5. protection .htpasswd

.Htpasswd we can use to further protect the phpMyAdmin login page. This in turn adds a line of defense against hackers and robots.

5.1 allow. Htaccess coverage

To set .htpasswd, we must first change phpMyadmin Apache configuration file to allow .htaccess override.
Open the configuration file using the vi phpmyadmin.conf

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

Add AllowOverride All DirectoryIndex index.php below in the following figure:

Save and exit vi
Now reload Apache service.

$ sudo service apache2 reload

5.2 Setting .htpasswd

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

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

Paste the following to the .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 htpasswd tool to generate .htpasswd file.

In this example, we created a directory named pmauser (php my admin user) for new users, 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 (to generate a password).
Once done, you can now have access to phpMyAdmin in your browser, you should now be prompted to enter your login details.

参考:Installing phpMyAdmin for Apache on Ubuntu 18.04

Guess you like

Origin www.cnblogs.com/freedom-try/p/11872856.html