MacBook Pro affichant un éditeur de code

Nginx – phpmyadmin configuration as location next to a website

To start, install phpmyadmin at the desired location.

compose create-project phpmyadmin/phpmyadmin

I prefer to use composer, but there are other possibilities

Once this is done, go in the folder /etc/nginx.
To keep the configuration independent, it is possible to create a snippet.

sudo nano snippets/phpmyadmin.conf

Then the following configuration must be created. In this example phpmyadmin is installed under /www

location /phpmyadmin {
    root /www/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+.php)$ {
        try_files $uri =404;
        root /www/;
        fastcgi_pass unix:/run/php/php7.3-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 /www/;
    }
}

The website configuration must be opened for editing and a line in the server block allows you to add the snippet: include snippets/phpmyadmin.conf;

server
  listen 80;
  server_name website.local;



  include snippets/phpmyadmin.conf;


}

And simply restart the services

sudo service nginx restart && sudo service php7.3-fpm restart

Leave a comment