This article was last reviewed for Debian 9 (Stretch).
phpMyAdmin installation and configuration for Nginx using PHP-FPM (Debian, repository)
Author: | Stefán Örvar Sigmundsson |
---|---|
Initial publication: | |
Last updated: | |
Written in: | English (United Kingdom) |
phpMyAdmin is a free and open-source web-based MySQL administrator and the world's most popular as such. This article will demonstrate how to install and configure phpMyAdmin on Debian or its derivatives such as Ubuntu and Linux Mint. The administrator will be configured for the domain phpmyadmin.example.org as a virtual server of Nginx using PHP-FPM.
Installation
phpMyAdmin can be installed from the official Debian repository using APT:
root@computer:~# apt --assume-yes install phpmyadmin
During the installation the user will be prompted for the following information:
- The web server to serve phpMyAdmin: [any]
- Whether to create the phpMyAdmin database: Yes
Configuration
There is a lot of clutter in the configuration directory. The necessary files are temporarily moved so that the directory can be cleared and are then moved back:
root@computer:~$ mv /etc/phpmyadmin/config.inc.php /tmp/ root@computer:~$ mv /etc/phpmyadmin/config-db.php /tmp/ root@computer:~$ rm --recursive /etc/phpmyadmin/* root@computer:~$ mv /tmp/config.inc.php /etc/phpmyadmin/ root@computer:~$ mv /tmp/config-db.php /etc/phpmyadmin/
A file is created to contain the configuration for the phpmyadmin.example.org virtual server:
root@computer:~$ touch /etc/nginx/sites-available/phpmyadmin.example.org.conf
The phpmyadmin.example.org.conf file contains a virtual server declaration:
server
{
access_log /var/log/nginx/phpmyadmin.example.org.log;
error_log /var/log/nginx/phpmyadmin.example.org.error.log;
listen 80;
location ~ [^/]\.php(/|$)
{
fastcgi_pass unix:/run/php/php7.0-fpm.socket;
include /etc/nginx/conf.d/http_fastcgi.conf;
}
root /usr/share/phpmyadmin/;
server_name phpmyadmin.example.org;
}
Conclusion
User creation (optional)
It may be impossible to log into phpMyAdmin as the root MySQL user. A new MySQL user can be created with all privileges granted and remote access.
Log into MySQL as root:
root@computer:~$ mysql --user="root" --password Enter password:
Create a MySQL user:
mysql> CREATE USER 'example'@'%' IDENTIFIED BY '[PASSWORD]'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'example'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
Directory ownership and permissions
The configuration directory should be protected:
root@computer:~$ chown --recursive root:adm /etc/phpmyadmin/ root@computer:~$ chmod --recursive 0775 /etc/phpmyadmin/
The log directory should be protected:
root@computer:~$ chown --recursive nginx:adm /var/log/nginx/ root@computer:~$ chmod --recursive 0750 /var/log/nginx/
The following will prevent permission errors in the log files:
root@computer:~$ chmod 0755 /var/lib/phpmyadmin/ root@computer:~$ chmod 0664 /var/lib/phpmyadmin/blowfish_secret.inc.php root@computer:~$ chmod 0664 /var/lib/phpmyadmin/config.inc.php
Configuration enablement
The virtual server is enabled by creating a symbolic link to its configuration file in the sites-enabled directory:
root@computer:~$ ln --symbolic /etc/nginx/sites-available/phpmyadmin.example.org.conf /etc/nginx/sites-enabled/phpmyadmin.example.org.conf
Server reinitiation
Nginx is restarted when the configuration is done:
root@computer:~$ systemctl reload nginx.service