user1128677
user1128677

Reputation: 479

nginx + fast-cgi - how to make phpmyadmin work

I've configured my nginx server + php. Eeverything works fine, except phpmyadmin.

I googled a lot and found some alias tricks, but they didn't work to me.

That works great:

        location ~ ^/ololo/(.*\.php)$ {
                alias $root_path/img/$1;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                include /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $request_filename;
        }

        location /ololo/ {
                alias $root_path/img/;
                index index.php;
        }

There is img directory in my site path and when I request sitename/ololo/ or sitename/ololo/index.php everything is fine.

But that:

         location ~ ^/myadmin/(.*\.php)$ {
                alias /usr/share/phpmyadmin/$1;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $request_filename;

        }

        location /myadmin/ {
                alias /usr/share/phpmyadmin/;
                index index.php;
        }

won't work!

when I'm trying to request mysite/myadmin/ or mysite/myadmin/index.php server throws me

No input file specified.

error message. In /usr/share/phpmyadmin/ are all .php files.

What's wrong with my nginx.conf?

Upvotes: 3

Views: 12398

Answers (3)

G. Alex
G. Alex

Reputation: 1

This is my config:

location /phpmyadmin {
    alias   /usr/share/phpmyadmin;
    index index.php;
    location ~ /([^/]+\.php)$ {
        try_files /$1 =404;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        location ~ /phpmyadmin/js/([^/]+\.php)$ {
            try_files /phpmyadmin/js/$1 =404;
            fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
}

Upvotes: 0

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42799

Ok so according to what I understood from your replies I'm modifying this answer, Add this to your main server and it should work.

location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
        try_files $uri =404;
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
    }
}

EDIT:

Ok so a down vode made me take a look at this again, It's been a while since I've wrote this answer and I should say this isn't how I'd write the config file if it was today, here's the config that I would use.

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

location ~* \.php$ {
    include fastcgi_params;
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
}

if you want to use alias then replace the phpmyadmin block with this

location /phpmyadmin {
    index index.php index.htm;
    alias /usr/share/phpmyadmin;
}

Note: If your server block already contains the index then you don't need to redefine it inside the phpmyadmin block.

Upvotes: 2

ewwink
ewwink

Reputation: 19154

read the comment the order must be exact, if still error read the error.log

### first define phpmyadmin static files
location ~ ^/phpmyadmin/.*\.(jpg|jpeg|gif|png|ico|css|js|woff|ttf)$ {
        root /usr/share/;
        expires max;
        #log_not_found off;
}

### then your public_html static file   
location ~* \.(jpg|jpeg|gif|png|ico|css|js|woff|ttf)$ {
        root /path/public_html;
        expires max;
        #log_not_found off;
}

because phpmyadmin path outside public_html so you need try_files to redirect slash "/" to "/index.php"

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

and now the last, fastcgi

### Define phpmyadmin PHP files
location ~ ^/phpmyadmin/(.*)\.php$ {
    ## optional, try uncomment if error
    #root /usr/share/phpmyadmin/;

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/$fastcgi_script_name;
    include fastcgi_params;
}

### then your public_html files 
location ~ \.php$ {
    ##optional, try uncomment if error
    #root           /path/public_html;

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /path/public_html/$fastcgi_script_name;
    include        fastcgi_params;
}

now you can access phpmyadmin on http://yoursite/phpmyadmin

Upvotes: 0

Related Questions