Use phpmyadmin with nginx and php7

phpmyadmin page

Install the phpmyadmin following the normal application installation
process.

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.

# 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_pass 127.0.0.1:9000;
               #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/gettext.inc’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 395” while reading response header from upstream, client: 127.0.0.1, 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.

References:


https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-14-04-server
https://www.digitalocean.com/community/questions/issues-with-phpmyadmin-on-nginx-ubuntu-14-04

6 thoughts on “Use phpmyadmin with nginx and php7

  1. Nathan

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

    Simply disable the following line in php.ini again:
    cgi.fix_pathinfo

    Reply
  2. Mitchell Krog

    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 http://stackoverflow.com/questions/37408704/nginx-with-phpmyadmin-wrong-direction-on-login

    Thanks for your help, works like a charm.

    Reply

Leave a Reply

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