mysql8.0으로 업데이트 하고phpmyadmin이 안될때

An earlier version of this tutorial was written by Brennan Bearnes.

Introduction

While many users need the functionality of a database management system like MySQL, they may not feel comfortable interacting with the system solely from the MySQL prompt.

phpMyAdmin was created so that users can interact with MySQL through a web interface. In this guide, we’ll discuss how to install and secure phpMyAdmin so that you can safely use it to manage your databases on an Ubuntu 18.04 system.

Prerequisites

Before you get started with this guide, you need to have some basic steps completed.

First, we’ll assume that your server has a non-root user with sudo privileges, as well as a firewall configured with ufw, as described in the initial server setup guide for Ubuntu 18.04.

We’re also going to assume that you’ve completed a LAMP (Linux, Apache, MySQL, and PHP) installation on your Ubuntu 18.04 server. If this is not completed yet, you can follow this guide on installing a LAMP stack on Ubuntu 18.04.

Finally, there are important security considerations when using software like phpMyAdmin, since it:

  • Communicates directly with your MySQL installation
  • Handles authentication using MySQL credentials
  • Executes and returns results for arbitrary SQL queries

For these reasons, and because it is a widely-deployed PHP application which is frequently targeted for attack, you should never run phpMyAdmin on remote systems over a plain HTTP connection. If you do not have an existing domain configured with an SSL/TLS certificate, you can follow this guide on securing Apache with Let’s Encrypt on Ubuntu 18.04. This will require you to register a domain name, create DNS records for your server, and set up an Apache Virtual Host.

Once you are finished with these steps, you’re ready to get started with this guide.

Step 1 — Installing phpMyAdmin

To get started, we will install phpMyAdmin from the default Ubuntu repositories.

This is done by updating your server’s package index and then using the apt packaging system to pull down the files and install them on your system:

  • sudo apt update
  • sudo apt install phpmyadmin php-mbstring php-gettext

This will ask you a few questions in order to configure your installation correctly.

Warning: When the prompt appears, “apache2” is highlighted, but not selected. If you do not hit SPACE to select Apache, the installer will not move the necessary files during installation. Hit SPACE, TAB, and then ENTER to select Apache.

  • For the server selection, choose apache2
  • Select Yes when asked whether to use dbconfig-common to set up the database
  • You will then be asked to choose and confirm a MySQL application password for phpMyAdmin

The installation process adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/ directory, where it is read automatically. The only thing you need to do is explicitly enable the mbstring PHP extension, which you can do by typing:

  • sudo phpenmod mbstring

Afterwards, restart Apache for your changes to be recognized:

  • sudo systemctl restart apache2

phpMyAdmin is now installed and configured. However, before you can log in and begin interacting with your MySQL databases, you will need to ensure that your MySQL users have the privileges required for interacting with the program.

Step 2 — Adjusting User Authentication and Privileges

When you installed phpMyAdmin onto your server, it automatically created a database user called phpmyadmin which performs certain underlying processes for the program. Rather than logging in as this user with the administrative password you set during installation, it’s recommended that you log in as either your root MySQL user or as a user dedicated to managing databases through the phpMyAdmin interface.

Configuring Password Access for the MySQL Root Account

In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program — like phpMyAdmin — to access the user.

루트 MySQL 사용자로 phpMyAdmin에 로그인하려면 auth_socket에서 mysql_native_password로 인증 방법을 전환해야합니다. 이렇게하려면 터미널에서 MySQL 프롬프트를 엽니 다.

  • sudo mysql

Next, check which authentication method each of your MySQL user accounts use with the following command:

  • SELECT user,authentication_string,plugin,host FROM mysql.user;
Output

이 예에서 루트 사용자는 실제로 auth_socket 플러그인을 사용하여 인증한다는 것을 알 수 있습니다. 암호로 인증하도록 root 계정을 구성하려면 다음의 ALTER USER 명령을 실행하십시오. 암호를 선택한 강력한 암호로 변경하십시오.

  • ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password‘;

Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect:

  • FLUSH PRIVILEGES;

Check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket plugin:

  • SELECT user,authentication_string,plugin,host FROM mysql.user;
Output

이 출력에서 ​​루트 사용자가 암호를 사용하여 인증 할 것을 알 수 있습니다. 이제 phpMyAdmin 인터페이스에 root 사용자로 로그인하십시오. 여기에 설정 한 암호를 입력하십시오.

전용 MySQL 사용자에 대한 암호 액세스 구성

또는 일부 사용자는 자신의 워크 플로우가 전용 사용자와 phpMyAdmin에 연결하는 데 더 적합하다는 것을 알 수 있습니다. 이렇게하려면 다시 한번 MySQL 쉘을여십시오 :

  • sudo mysql

Note: If you have password authentication enabled, as described in the previous section, you will need to use a different command to access the MySQL shell. The following will run your MySQL client with regular user privileges, and you will only gain administrator privileges within the database by authenticating:

  • mysql -u root -p

From there, create a new user and give it a strong password:

  • CREATE USER ‘sammy‘@’localhost’ IDENTIFIED BY ‘password‘;

Then, grant your new user appropriate privileges. For example, you could grant the user privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command:

  • GRANT ALL PRIVILEGES ON *.* TO ‘sammy‘@’localhost’ WITH GRANT OPTION;

Following that, exit the MySQL shell:

  • exit

You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin:

phpMyAdmin login screen

Log in to the interface, either as root or with the new username and password you just configured.

When you log in, you’ll see the user interface, which will look something like this:

phpMyAdmin user interface

Now that you’re able to connect and interact with phpMyAdmin, all that’s left to do is harden your systems security to protect it from attackers.

Step 3 — Securing Your phpMyAdmin Instance

Because of its ubiquity, phpMyAdmin is a popular target for attackers, and you should take extra care to prevent unauthorized access. One of the easiest ways of doing this is to place a gateway in front of the entire application by using Apache’s built-in .htaccess authentication and authorization functionalities.

To do this, you must first enable the use of .htaccess file overrides by editing your Apache configuration file.

Edit the linked file that has been placed in your Apache configuration directory:

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

Add an AllowOverride All directive within the <Directory /usr/share/phpmyadmin> section of the configuration file, like this:

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

When you have added this line, save and close the file.

To implement the changes you made, restart Apache:

  • sudo systemctl restart apache2

Now that you have enabled .htaccess use for your application, you need to create one to actually implement some security.

In order for this to be successful, the file must be created within the application directory. You can create the necessary file and open it in your text editor with root privileges by typing:

  • sudo nano /usr/share/phpmyadmin/.htaccess

Within this file, enter the following information:

/usr/share/phpmyadmin/.htaccess

Here is what each of these lines mean:

  • AuthType Basic: This line specifies the authentication type that you are implementing. This type will implement password authentication using a password file.
  • AuthName: This sets the message for the authentication dialog box. You should keep this generic so that unauthorized users won’t gain any information about what is being protected.
  • AuthUserFile: This sets the location of the password file that will be used for authentication. This should be outside of the directories that are being served. We will create this file shortly.
  • Require valid-user: This specifies that only authenticated users should be given access to this resource. This is what actually stops unauthorized users from entering.

When you are finished, save and close the file.

The location that you selected for your password file was /etc/phpmyadmin/.htpasswd. You can now create this file and pass it an initial user with the htpasswd utility:

  • sudo htpasswd -c /etc/phpmyadmin/.htpasswd username

You will be prompted to select and confirm a password for the user you are creating. Afterwards, the file is created with the hashed password that you entered.

If you want to enter an additional user, you need to do so without the -c flag, like this:

  • sudo htpasswd /etc/phpmyadmin/.htpasswd additionaluser

Now, when you access your phpMyAdmin subdirectory, you will be prompted for the additional account name and password that you just configured:

phpMyAdmin apache password

After entering the Apache authentication, you’ll be taken to the regular phpMyAdmin authentication page to enter your MySQL credentials. This setup adds an additional layer of security, which is desireable since phpMyAdmin has suffered from vulnerabilities in the past.

Conclusion

You should now have phpMyAdmin configured and ready to use on your Ubuntu 18.04 server. Using this interface, you can easily create databases, users, tables, etc., and perform the usual operations like deleting and modifying structures and data.

Leave a Reply