Nginx: phpMyAdmin configuration template for nginx.conf

Last updated on | 5 replies

This is a template for phpMyAdmin. It should go into your server block in your Nginx config file.

To edit the Nginx configuration file.

sudo nano /etc/nginx/nginx.conf

nginx.conf may also call some other config files, so your server block may be located in:

sudo nano /etc/nginx/sites-enabled/default
/etc/nginx/nginx.conf
    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/php7.2-fpm.sock;
                   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/;
           }
    }

Note that php7.2-fpm.sock should refer to your version of PHP. If you are unsure, list the folder to find out which .sock is available: ls /run/php/

Save file and exit. (Press CTRL + X, press Y and then press ENTER)

Check that the Nginx config file is valid.

sudo nginx -t

If valid, restart Nginx service.

sudo systemctl restart nginx

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

5 replies

Leave a reply

Your email address will not be published. Required fields are marked *

  1. Thanks….saved me hours of searching…the only modification I had to make was the socket…everything worked out of the box.

  2. Hi, Thanks for your support, But I am facing the following error:

    nginx: [emerg] “location” directive is not allowed here in /etc/nginx/conf.d/phpmyadmin.conf:1
    nginx: configuration file /etc/nginx/nginx.conf test failed

    Please guide after having look at the following phpmyadmin.conf file as per my system:

    location /testvm {
    root /var/www/html/phpmyadmin;
    index index.php index.html index.htm;
    location ~ ^/testvm/(.+\.php)$ {
    try_files $uri =404;
    root /var/www/html/;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
    }
    location ~* ^/testvm/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /var/www/html/;
    }
    }

    In the above code: testvm is my hostname of the server
    Direcotry path containing phpmyadmin: /var/www/html/phpmyadmin

    Regards