Php phar nginx No input file specified

359 Views Asked by At

To upgrade cms, I have a php file which is a phar file

(https://www.cmsmadesimple.org/downloads/cmsms/)

I leave it at the root of my site

When access to the file, an index.php is added at the end of the url Like that :

https://xx.domain.be/cmsms-2.2.12-install.php

become

https://xx.domain.be/cmsms-2.2.12-install.php/index.php

But nginx sends me an error : No input file specified.

I have to add a configuration for this url but I do not know what

Config nginx :

server {

       listen 443 ssl;

       server_name xxx.domain.be;

       root /var/www/sites/xxx;

       index index.html index.php;

       location / {
            # This is cool because no php is touched for static content.
            # include the "?$args" part so non-default permalinks doesn't break when using query string
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            include fastcgi.conf;
            fastcgi_intercept_errors on;
            fastcgi_pass php;
            fastcgi_buffers 16 16k;
            fastcgi_buffer_size 32k;
        }
}

Thank you

2

There are 2 best solutions below

0
symcbean On

I see nobody has answered - I was investigating the same problem when I came across your post. While I don't know what the solution is, I note your configuration only hands off .php files to the php interpreter. perhaps you need to add...

 location ~ \.phar$ {
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
    }

?

0
Alex Barker On

In order to fix that specific error, I needed to specify the SCRIPT_FILENAME manually in the location block. Packaging a simple app as a phar was far more challenging than I expected. There are so many things that can go wrong.

I am not sure how you are serving your phar. If you want to serve the phar files out of the public root with other static assets, you can. You just need to change the try_files to try the phar file instead of index.php, and add the location change suggested by @symvbean.

server {
       listen 443 ssl;
       server_name xxx.domain.tld;

       # root points to the public folder where you put the 
       # phar instead of index.php, let's assume index.phar
       root /var/www/sites/xxx;

       index index.html index.phar;

       location / {
           try_files $uri $uri/ /index.phar;
       }

       location ~ \.phar$ {
           include fastcgi.conf;
       }
}

I have been configuring nginx to server phar's per location as follows, but this is not really appropriate for serving static content.

server {
       listen 443 ssl;
       server_name api.domain.tld;

       # root points to a folder that contains all 
       # deployed phar files
       root /var/www/apps;

       location /v1/service-a {
           include fastcgi.conf;

           # document_root will come from root above
           # we will use a unique phar per service.
           fastcgi_param SCRIPT_FILENAME $document_root/service-a.v1.phar;
       }

       location /v2/service-b {
           include fastcgi.conf;
           fastcgi_param SCRIPT_FILENAME $document_root/service-b.v2.phar;
       }
}