9

I am having issues with my phpmyadmin on my nginx install.

When I enter <ServerIP>/phpmyadmin and logs in, I get redirected to <ServerIP>/index.php?<tokenstuff> instead of <ServerIP>/phpmyadmin/index.php?<tokenstuff>

Nginx config file:

user  nginx;
worker_processes  5;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  2;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

Default.conf:

server {
    listen       80;
    server_name  _;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
    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:/tmp/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_script_name;
    }

    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}
}

(Any general tips on tidying op those config files are accepted too)

  • @MichaelHampton Actually I think that was the problem. I removed the package installed via yum, and downloaded the latest from the phpmyadmin website, and voilá. If you put up an answer, I will accept that. – Frederik Nielsen Oct 2 '12 at 19:15
2

This doesn't sound like an nginx issue. This sounds like phpMyAdmin wasn't installed correctly and thinks that it is at / instead of /phpmyadmin. Check your phpMyAdmin configuration.

| improve this answer | |
  • This is what lead me to the right answer - reinstalling phpmyadmin - Thanks! :) – Frederik Nielsen Oct 2 '12 at 20:41
  • 4
    "just reinstall" is an absurd answer. If phpMyAdmin's configuration is wrong, there should be a way to reconfigure without having to reinstall the entire application! – alexw Aug 16 '16 at 23:15
  • 1
    This begs for more information: Please link to a source that explains how and where to set the 'where PHP thinks it is' parameter. – Diana Dec 30 '16 at 18:13
  • This is more of a comment, than an answer. Great suggestion, but, check phpMyAdmin for what? – SherylHohman Nov 13 '18 at 22:33
  • @SherylHohman That might make an interesting question asked separately. But this one was solved long ago. – Michael Hampton Nov 13 '18 at 23:02
13

Even though the author has solved his problem reinstalling phpMyAdmin, nginx needs to be properly configurated to handle the redirect upon login correctly.

After days smashing my head on the keyboard I finally found the real solution and I'm sharing here as this thread still have high priority on google search.

As stated on the link : http://www.samundra.com.np/use-phpmyadmin-with-nginx-and-php7/1374

To solve the problem, you should add the following block of code to your nginx default site-available, you will access it with :

sudo nano /etc/nginx/sites-available/default

Place this block in server block:

# 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/;
       }
   }

   # Dealing with the uppercased letters
   location /phpMyAdmin {
       rewrite ^/* /phpmyadmin last;
   }

I hope this helps someone one day...

| improve this answer | |
  • I'm glad that this solved you problem ! Happy codings ! – Daniel Alves Aug 22 '16 at 22:01
  • This is it right here... fixes all issues... – ThatTechGuy Nov 12 '16 at 1:28
  • definitely saved me more than one day. up voted! – Xu Yin Dec 27 '16 at 11:58
  • Does not fix it for me. Any other ideas? – Diana Dec 30 '16 at 18:16
  • What if I don't want phpmyadmin at /phpmyadmin but at /whatever instead? I tried changing the nested "locations" but it didn't work. – 0lli.rocks Oct 18 '17 at 13:34
4

This problem is caused by the common configuration of cgi.fix_pathinfo = 0 that disables the current path for PHP-FPM. One quick solution is to change cgi.fix_pathinfo back to 1, or set the path parameters on the virtual server block of nginx.

| improve this answer | |
2

You're problem seems to be similar to this: https://stackoverflow.com/questions/1011101/nginx-location-directive-doesnt-seem-to-be-working-am-i-missing-something

If by reading that and changing you're config you still have problems please do tell!

| improve this answer | |
  • I read that thread, and tried some of the configs, but still the same issue - either gets redirected to / instead of /phpmyadmin, or just goes 404. – Frederik Nielsen Oct 2 '12 at 11:19
  • 404 is "generated" by "try_files", which means that its not finding phpmyadmin files... maybe something wrong with phpmyamdin install? – Mikec Oct 3 '12 at 10:38
  • Just notice the other comment -.- I guess it was phpmyadmin config after all! – Mikec Oct 3 '12 at 10:39
  • Might be.. I think it was a combination of both. – Frederik Nielsen Oct 3 '12 at 11:04
1

open:

/var/lib/phpMyAdmin/config.inc.php

add:

$cfg['PmaAbsoluteUri'] = 'https://www.example.net/path_to_your_phpMyAdmin_directory/';

see:
https://docs.phpmyadmin.net/en/latest/config.html#basic-settings

.

| improve this answer | |
0

add a virtaul host to your lamp server with any domain name like phpmyadmin1.com

server {
    #listen 80 default_server;
    #listen [::]:80 default_server ipv6only=on;

    root /var/www/phpmyadmin;
    #some /var/www/html/phpmyadmin
    index index.php index.html index.htm;

    server_name phpmyadmin1.com;

        location / {
        try_files $uri $uri/ /index.php?$args;
     }

    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Edit your Hosts file

add this line at bottom

192.168.1.xx  phpmyadmin1.com

save and close, then restart your server

service nginx restart

service php5-fpm restart

Access your virtual host url on browser your see phpmyadmin login page

http://screencloud.net/v/nGK5

http://screencloud.net/v/6M8r

| improve this answer | |
  • Welcome to Server Fault! In both your questions and answers please try to refrain from using random domain names and use either your own domain or one of the RFC 6761 reserved domain names such as example.com, example.org or similar . Please refer to this Q&A for our recommendations with regards to how and what (not) to obfuscate in your questions. – HBruijn Aug 31 '16 at 5:42
0

Only this worked for me

location /utils/phpmyadmin/ {
    try_files $uri $uri/ =404;
    index index.php index.html index.htm
    proxy_set_header Proxy "";
}
| improve this answer | |
-1

phpMyAdmin from repositories of Ubuntu 16.04 and later don't properly redirect.

I'm just download new version of phpmyadmin from official phpmyadmin site:

sudo wget https://files.phpmyadmin.net/phpMyAdmin/4.6.6/phpMyAdmin-4.6.6-all-languages.tar.gz

sudo tar xvf phpMyAdmin-4.6.6-all-languages.tar.gz

sudo mv phpMyAdmin-4.6.6-all-languages /usr/share/phpmyadmin

sudo rm -rf phpMyAdmin-4.6.6-all-languages.tar.gz

sudo cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

open config.inc.php:

sudo nano /usr/share/phpmyadmin/config.inc.php

and put some random character berween '

$cfg['blowfish_secret'] = 'i\kywQ>_h4L~S-Pt2rS'VAe)QpED7JI#';

save and open your domain/phpmyadmin in browser

also you can change link to phpmyadmin (for better security) and add basic auth from nginx to link:

sudo ln -s /usr/share/phpmyadmin /var/www/html

cd /var/www/html

sudo mv phpmyadmin anything

now your phpmyadmin work on https://domain/anything, lets add some password:

sudo sh -c "echo -n 'YourNameForLoginThere:' >> /etc/nginx/pmapass"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/pmapass"

now open your nginx config (by default: sudo nano /etc/nginx/sites-available/default) and add befor last }

location /anything {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/pmapass;
}

Enable Configuration Storage:

sudo nano /usr/share/phpmyadmin/config.inc.php

Locate following lines:

// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';

Change to:

$cfg['Servers'][$i]['controluser'] = 'yourdatabaseuser';
$cfg['Servers'][$i]['controlpass'] = 'yourdatabasepassword';

Locate:

// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
// $cfg['Servers'][$i]['relation'] = 'pma__relation';
// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
// $cfg['Servers'][$i]['history'] = 'pma__history';
// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
// $cfg['Servers'][$i]['recent'] = 'pma__recent';
// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
// $cfg['Servers'][$i]['users'] = 'pma__users';
// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

Uncomment them ( remove // )

Now save and exit.

Go to your mysql (by default: sudo mysql -u root -p)

GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'yourdatabaseuser'@'localhost' IDENTIFIED BY 'yourdatabasepassword';
exit;

now try to open domain/anything in browser

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.