This article will show you how to install the latest version of PHPMyAdmin on Nginx. We will be obtaining the latest stable version of PHPMyAdmin from the GitHub repository and periodically pull updates for it via Git.
Create a directory for PHPMyAdmin and change its ownership to the www-data
user.
mkdir /usr/share/phpmyadmin chown www-data:www-data /usr/share/phpmyadmin
Clone the “STABLE” branch of the PHPMyAdmin GitHub repository into this directory.
cd /usr/share/phpmyadmin sudo -u www-data -H git clone --depth=1 --branch=STABLE https://github.com/phpmyadmin/phpmyadmin.git .
Do not miss the dot at the end of the Git command.
Edit the desired virtual host file and add the following to it:
location /phpmyadmin { alias /usr/share/phpmyadmin; } location ~ ^/phpmyadmin(.+\.php)$ { alias /usr/share/phpmyadmin; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1; include fastcgi_params; } location ~ ^/phpmyadmin/(.*\.(eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|xls|tar|bmp))$ { alias /usr/share/phpmyadmin/$1; expires 30d; log_not_found off; access_log off; }
Make sure these blocks are placed above the other location blocks.
Create a database and grant the necessary privileges to utilize the extra features of PHPMyAdmin like bookmarking and history.
mysql -u root -p
CREATE DATABASE phpmyadmin; GRANT USAGE ON mysql.* TO 'pmauser'@'localhost' IDENTIFIED BY 'pmapass'; GRANT SELECT ( Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv ) ON mysql.user TO 'pmauser'@'localhost'; GRANT SELECT ON mysql.db TO 'pmauser'@'localhost'; GRANT SELECT ON mysql.host TO 'pmauser'@'localhost'; GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO 'pmauser'@'localhost'; GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pmauser'@'localhost';
Create a config.inc.php
file for PHPMyAdmin:
nano /usr/share/phpmyadmin/config.inc.php
Place the following code:
<?php $i = 0; $i++; $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['connect_type'] = 'socket'; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['user'] = ''; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['controluser'] = 'pmauser'; $cfg['Servers'][$i]['controlpass'] = 'pmapass'; $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; $cfg['Servers'][$i]['relation'] = 'pma__relation'; $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; $cfg['Servers'][$i]['history'] = 'pma__history'; $cfg['Servers'][$i]['recent'] = 'pma__recent'; $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; $cfg['Servers'][$i]['users'] = 'pma__users'; $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; $cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords'; $cfg['Servers'][$i]['favorite'] = 'pma__favorite'; $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; $cfg['DefaultLang'] = 'en'; $cfg['ServerDefault'] = 1; $cfg['blowfish_secret'] = 'random-secret'; $cfg['ForceSSL'] = false; ?>
Set ForceSSL
to true
if you have an SSL certificate installed.
Obtain a randomly generated blowfish secret from this website and add it to the blowfish_secret
line.
Do an Nginx configuration test and reload if successful:
sudo service nginx configtest sudo service nginx reload
Access PHPMyAdmin from the web browser:
http://example.com/phpmyadmin
Configure Cron to periodically check for updates and pull them from GitHub. Edit the cron file of the www-data
user.
crontab -u www-data -e
Add the following line:
@daily cd /usr/share/phpmyadmin/ && git pull -q origin STABLE
That’s it, we have installed the latest version of PHPMyAdmin on Nginx and also configured it to
Andrey says
ln -s /usr/share/phpmyadmin /usr/share/nginx/html
daksh says
get 403 error
kafka says
it work
add “index index.php;”
location /phpmyadmin {
alias /usr/share/phpmyadmin;
index index.php;
}
location ~ ^/phpmyadmin(.+\.php)$ {
alias /usr/share/phpmyadmin;
index index.php;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$1;
include fastcgi_params;
}
kafka says
location ~ ^/phpmyadmin/(.*\.(eot|otf|woff|ttf|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|xls|tar|bmp))$ {
alias /usr/share/phpmyadmin/$1;
index index.php;
expires 30d;
log_not_found off;
access_log off;
}
Paul P says
I installed this on my Raspberry but get a ‘502 Bad Gateway’ message
basteyy says
First of all: Thanks for the tutorial.
2023 you will run into a timeout, when you try to download via
“`bash
sudo -u www-data -H git clone –depth=1 –branch=STABLE git://github.com/phpmyadmin/phpmyadmin.git .
“`
You should use `https://github.com/phpmyadmin/phpmyadmin.git`.