Step 1 installing phpMyAdmin
2; configuring nginx with phpMyAdmin root directory
3rd optional” using a secret keyword.
install phpmyadmin ubuntu nginx
sudo apt-get update && sudo apt-get install phpmyadmin
after installation complete
2nd configure the nginx server access to phpmyadmin (unlike apache its manual)
if access after above step
serverip/phpmyadmin
403 Forbidden
nginx
add this to default.conf or
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
#fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
Optional steps acesing phpmyadmin by secure url
sudo ln -s /usr/share/phpmyadmin /var/www/html/secretword
add this default.conf or (with in sever block)
location /secretword {
root /var/www/html;
index index.php;
try_files $uri $uri/ /index.php?$args;
location ~ ^/secretword/(.+\.php)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/secretword/(doc|sql|setup)/ {
deny all;
}
}
example:
location /sqlc {
root /var/www/html;
index index.php index.html index.htm;
location ~ ^/sqlc/(.+\.php)$ {
try_files $uri =404;
root /var/www/html;
#fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/sqlc/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /var/www/html;
}
}
3rd step reload nginx
nginx -s reload
Test Phpmyadmin installation
serverip/phpmyadmin
Points on phpmyadmin nginx installation
Location block should be within server block.
if phpmyadmin location kept in snippets or sites enabled make sure it include in any server block.
apache & lightthp automatically configures for webserver bug nginx not.
fastcgi_pass : unix socket or tcp whicherver is your server using.