Use phpmyadmin with nginx and php7

phpmyadmin page

Install the phpmyadmin following the normal application installation

Install phpmyadmin

sudo apt-get install phpmyadmin

Follow the normal installation process of phpmyadmin. Once the
phpmyadmin configuration is finished, we need to configure the
nginx configuration.

Nginx Configuration

Edit the nginx configuration (/etc/nginx/sites-available/default)
and add the following configurations to it. Open the sample configuration

# Phpmyadmin Configurations
    location /phpmyadmin {
       root /usr/share/;
       index index.php index.html index.htm;
       location ~ ^/phpmyadmin/(.+\.php)$ {
               try_files $uri =404;
               root /usr/share/;
               #fastcgi_param HTTPS on; # <-- add this line
		       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
       location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
               root /usr/share/;
   location /phpMyAdmin {
       rewrite ^/* /phpmyadmin last;

php7 and php-gettext symbolic links

Since php7 by default do not come with php-gettext we will need to install
these packages too.

sudo apt-get install php-gettext

If this package is not available then you will see following error messages
in your nginx error logs in /var/log/nginx/error.log

2016/04/28 10:22:30 [error] 17184#0: *6 FastCGI sent in stderr: “PHP message: PHP Fatal error: require_once(): Failed opening required ‘./libraries/php-gettext/’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 395” while reading response header from upstream, client:, server: localhost, request: “GET /phpmyadmin/ HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php/php7.0-fpm.sock:”, host: “localhost”

Once php-gettext is installed use the below command to reconfigure the
symbolic links to gettext.

rm /usr/share/phpmyadmin/libraries/php-gettext/*
ln /usr/share/php/php-gettext/* /usr/share/phpmyadmin/libraries/php-gettext

Restart the nginx server

sudo service nginx restart

Browse http://localhost/phpmyadmin and it should show up the phpmyadmin login page.
– You may have to hard refresh to get to the page, since browser caches this page.


Samundra Shrestha

I work as fullstack developer. Having spent more than 5 years in the web development technologies, I aspire to create an environment where we can share, learn and grow together.

12 thoughts on “Use phpmyadmin with nginx and php7

  • March 19, 2017 at 7:36 AM

    Man you save my days!! I love you! YOu are the best!

  • March 17, 2017 at 4:34 PM

    I also have this redirect problem and wanted to fix it. The solution is here but badly explained.

    I know what to add and to what file, but where exactly in that file? Tried to add it at the end, on the beginning, each time it messed the nginx itself and had to go back to default default file ;).

    Can anyone tell exactly in which place I must add this block of text? On other site someone mentioned I should add it to server block but I have no idea what is it, there is so many lines in that file mentioning server, so placing that text in wrong position easily can mess everything. Any help?

    • March 17, 2017 at 5:15 PM

      Hi Mike,

      You can do it in different ways. Easiest is to place it directly in nginx. Please check this I have updated the code near the bottom. After updating it you should restart nginx. Before restarting server, I would also suggest you check that your nginx configuration file has no syntax problems. You can do that with `sudo nginx -t` at command line. Please let me know if you still have problem with it.

      • March 17, 2017 at 10:08 PM

        Wow, thanks for such quick replay!

        I tried to use this code but nginx fails, so I check it as you suggested and got:

        nginx: [emerg] “location” directive is not allowed here in /etc/nginx/sites-enabled/default:84
        nginx: configuration file /etc/nginx/nginx.conf test failed

        If I counted well to 84, the issue is with those lines:

        location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {

        Seems like location of files are incorrect, but then again, I do have /usr/share/phpmyadmin so I have no clue what it wants.

        I’m on Ubuntu Server 16.04 if that helps.

  • September 13, 2016 at 7:13 AM

    Actually, the fix for the redirect issue was much simpler.

    Simply disable the following line in php.ini again:

  • September 7, 2016 at 11:01 AM

    How to config /etc/nginx/sites-available/default when I want to have phpmyadmin under url and not

    • October 9, 2016 at 4:27 PM

      If you haven’t found the solution yet. Actually /phpmyadmin is just an alias. You can edit phpmyadmin.ini to use your own alias.

  • June 28, 2016 at 12:26 PM

    I found hundreds of very bad and incorrect answers out there to a problem of phpmyadmin redirecting to http://my.server.ip/ instead of http://my.server.ip/phpmyadmin after logging in.

    Your configuration section above to be added to the nginx default conf file is the only correct solution out there.

    I have added it as a suggested answer at

    Thanks for your help, works like a charm.

    • August 8, 2016 at 12:49 AM

      Hey Mitchell,

      Thanks for stopping by and sharing your thoughts. I really feel grateful that it worked :)


Leave a Reply

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