4

I am trying to get example.com/phpmyadmin to route to a different directory from my site so I can use one universal phpmyadmin install for all of my sites. I have tried this:

server {
    listen      80;
    server_name example.com;

    location / {
        root    /home/web/example.com/public_html;
        index   index.html index.htm index.php;
    }

    location ~ \.php$ {
        root /home/web/example.com/public_html;
        if ($request_uri ~* /phpmyadmin) {
            root /home/web/phpmyadmin;
        }
        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;
    }
}

This doesn't seem to work at all.

And I have also tried this:

server {
    listen      80;
    server_name example.com;

    location / {
        root    /home/web/example.com/public_html;
        index   index.html index.htm index.php;
    }

    location /phpmyadmin {
        root    /home/web/phpmyadmin;
        index   index.html index.htm index.php;
    }

    location ~ \.php$ {
        root /home/web/example.com/public_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;
    }
}

After when I check my error logs with this file I get:

2013/06/28 01:10:47 [error] 7068#0: *1 "/home/web/phpmyadmin/phpmyadmin/index.html" is not found (2: No such file or directory)

So in the location block I changed root to /home/web, thinking it will take out the extra phpmyadmin, however, instead, I don't get anything about phpmyadmin at all in my error log. I can't seem to figure out the correct configuration and why this one is not working. Any ideas?

2 Answers 2

4

On a Ubuntu server i've used the following setup to make phpMyAdmin available under /pma for several Nginx sites.

/etc/phpmyadmin/nginx-php5-fpm.conf

location /pma {
    alias /usr/share/phpmyadmin/;
}

location ~ ^/pma/(.*\.(js|css|gif|jpg|png))$ {
    alias /usr/share/phpmyadmin/$1;
}

location ~ ^/pma(.+\.php)$ {
    alias /usr/share/phpmyadmin$1;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;

    charset utf8;

    include fastcgi_params;
    fastcgi_param DOCUMENT_ROOT /usr/share/phpmyadmin;
}

Then in any /etc/nginx/sites-available/* i can enable pma support with this line:

include /etc/phpmyadmin/nginx-php5-fpm.conf;
1
  • Your setup required me to add index.php right after the URL to access PMA. Namely, http://mysite/pma didn't work. I need to call it with http://mysite/pma/index.php. So I added the index index.php index.html index.htm; directive after the alias /usr/share/phpmyadmin/; directive. This may be specific to my setup, however I want to note it for others.
    – Lashae
    Dec 6, 2016 at 8:43
1

I think your problem in the second config is the index inside /phpmyadmin replace it with just index index.php

Here's my server's phpmyadmin, but it's configured as a subdomain.

server {
    client_header_timeout 0;
    server_name phpmyadmin.example.com;
    root /var/www/phpmyadmin/;
    #replace this with your phpmyadmin location
    #like /usr/share/phpmyadmin for example
    index           index.php;
    access_log /var/log/nginx/phpmyadmin_access_log;
    error_log /var/log/nginx/phpmyadmin_error_log;
    location ~* \.php$ {
        try_files $uri =404;
        fastcgi_index   index.php;
        fastcgi_pass    unix:/var/run/php5-fpm.sock;
        include         fastcgi_params;
        client_max_body_size 64m;
        client_body_buffer_size 128k;
    }
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        access_log        off;
        log_not_found     off;
        expires           360d;
    }
    location ~ /\.  {
        access_log off;
        log_not_found off;
        deny all;
    }
}

These three settings are for exporting and importing big files, nginx fails when the exported file is bigger than a certain amount, or if the server takes time to generate the exported sql file.

client_header_timeout 0;
client_max_body_size 64m; #change this if ur export is bigger than 64mb.
client_body_buffer_size 128k;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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