0

I've recently installed phpmyadmin and nginx on my server, but I want to make it accessible to all domains without copying it to every single domain's web root. Is this possible? if so, how?

EDIT: This is what's in my config now, lain

        location /phpmyadmin/
        {
                alias /home/phpmyadmin/;
        }

        location ~ ^/phpmyadmin/(.+\.php)$
        {
                alias /home/phpmyadmin/$1;
                include fcgi.conf;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
        }

3 Answers 3

4
+100

According to nginx documentation, location cannot be used inside http block. This means that you have to add locations for every virtualhost. However you can save your bunch of layouts into a separate file and include it with includecommand. Here is an example for a generic virtualhost:

server {
  listen 80;
  root /var/www/nginx-default;

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

And you write all global locations in a separate *.conf files under /etc/nginx/global.d. Your code may be placed in /etc/nginx/global.d/phpmyadmin.conf, for example.

Update: As for your PHPMyAdmin locations: instead of aliasing every file you should pass SCRIPT_FILENAME variable in the following way:

location ~ ^/phpmyadmin/(.+\.php)$ {
    include fcgi.conf;
    fastcgi_index index.php;
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_param SCRIPT_FILENAME /home/phpmyadmin$fastcgi_script_name;
}

Note that you need to use /home/phpmyadmin instead of $document_root because alias directive does not change document root. This means that for my generic virtualhost (as above) requesting URL http://localhost/phpmyadmin/test.php will try to execute /var/www/nginx-default/phpmyadmin/test.php which is not the expected behaviour.

7
  • That's rather genius. Thanks. However, why is my location not working? Do you know?
    – Rob
    Mar 7, 2012 at 0:33
  • thanks for the update. Still getting 404 though, and /home/phpmyadmin/ IS where the files are.
    – Rob
    Mar 8, 2012 at 11:48
  • In most cases 404 error is issued by nginx. If this is the nginx 404 page and not fastcgi 404 error (blank screen for php-cgi/php-fpm, for example) then your php files don't match fastcgi location. Please check your nginx error.log for more information which one location takes precedence over your /phpmyadmin/.+\.php location.
    – jollyroger
    Mar 9, 2012 at 9:36
  • What if it's the fastcgi?
    – Rob
    Mar 10, 2012 at 4:02
  • You'll get an empty screen on default PHP-cgi/fastcgi setup. You'll get some meaningfull HTML results only if debug/error reporting flags are enabled in correspondent php.ini. In other cases you should look for a cgi/fastcgi-wrapper logs.
    – jollyroger
    Mar 11, 2012 at 9:31
1

Put your phpmyadmin in a common directory that is accessible by all sites and try an Alias

location  /phpmyadmin/ {
  alias  /path/to/phpmyadmin/;
}

location ~ ^/phpmyadmin/(.+\.php)$ {
  alias /path/to/phpmyadmin/$1;
  include /path/to/your/fastcgi.config;
  fastcgi_pass unix:/tmp/php.socket;
}

If you don't use the unix socket fastcgi then the last line would probably be something like this

fastcgi_pass 127.0.0.1:9000;
11
  • Will I need to put that line in every server {}, or is there a way to make it global?
    – Rob
    Mar 1, 2012 at 7:55
  • I think so, there isn't any way to make a global loation.
    – user9517
    Mar 1, 2012 at 8:22
  • After a bit of research, I've found the answer is no. As such, I've put that line in a few of the server blocks for a few domains; it isn't working :( It returns 404
    – Rob
    Mar 1, 2012 at 8:22
  • Did you put the trailing / on the URL in your browser ? Without it as written above it will 404. f you remove the trailing / from the location block you don't need it in your URL.
    – user9517
    Mar 1, 2012 at 8:29
  • Well this is strange. It seems it simply can't find the .php files... .html and .txt files are working fine.
    – Rob
    Mar 1, 2012 at 8:37
0

@Rob you can change your log level to debug to follow nginx operations. You have to fix your SCRIPT_FILENAME parameter from fcgi.conf file or you can set it in your conf file.

2
  • fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; What do you mean fix? What's wrong with it?
    – Rob
    Mar 4, 2012 at 10:37
  • if you change log level to debug, you can find problem. It will show you which files are tried to open or you can use strace easily to follow nginx process.
    – dirigeant
    Mar 6, 2012 at 3:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .