To work with databases through the web interface, there is a web editor phpMyAdmin. This tool connects to the MariaDB database and displays existing databases, allows you to create new ones, edit data in tables. In general, everything is the same as what can be done in the mysql console, but much more convenient and clearer, especially when working with data frequently. Consider installing phpMyAdmin on Debian 12 Linux Server with Nginx + MariaDB + PHP (LEMP) preconfigured.
We make all settings from the root user, if you are using a regular user, add before the command sudo.
1. Install the necessary components and the database editor itself
apt install php-mbstring
apt install phpmyadmin
During the installation process, the user will be prompted to select for which web server the editor should be configured.
- []apache2
- []lighttpd
In our case, the server has LEMP pre-installed and we leave both fields empty and click OK.
Next, it will be proposed to create a database for the database editor itself, where the editor's user settings and other data necessary for its operation will be stored. Here we select the Yes option and in the next window you will be asked to come up with a password for the phpmyadmin user. We enter the password and confirm it in the next window to avoid input errors.
2. Basic settings
Let's follow the link http://server-ip/phpmyadmin to check the work, we can enter the login and password from any database, for example, the newly created one, the phpmyadmin login and the password we set. Sometimes, for convenience, it is required to work with several databases at once, in order to display them under one user, we need to create one and delegate the rights of the root user.
mysql -u root -p
CREATE USER 'alldbuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON . TO 'alldbuser'@'localhost';
FLUSH PRIVILEGES;
Now, when authorizing under the alldbuser user, all databases created on this server are displayed.
If you need to set a password for the root user, use the following commands:
mysql -u root
use mysql;
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
FLUSH PRIVILEGES;
exit
Add a link to the phpMyAdmin folder in the root directory of the nginx web server:
ln -s /usr/share/phpmyadmin /usr/share/nginx/html
3. Security setup
In order to protect the database editor from guessing passwords and potential vulnerabilities, let's add authorization at the level without a server.
vi /etc/nginx/conf.d/default.conf
location /phpmyadmin {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
}
Add a user and specify a password for it:
htpasswd -c /etc/nginx/pma_pass pma_username
Restart the nginx service:
systemctl restart nginx
Now, when you click on the link http://server-ip/phpmyadmin, a window will appear for entering your login and password. In our case, the login will be pma_username.
The setup is complete, we strongly recommend that you enter passwords only using the https protocol with an SSL certificate, in order to avoid data interception.