I'm running php-cgi and NGINX. They are running in a folder, however their root directory is 2 directories out, and 2 in from there. When the root was html (default), they worked perfectly, however now php reports the "No Input File Specified" error. I've tried setting the directory to give full control to all programs, I already have full control, I've tried to see if php is looking in a different directory, tried changing the directories, hard coding the php variable, etc. I've followed about 5 different tutorials on how to fix this problem, but none have resolved it. There are no errors in the console and my fastcgi.conf is unchanged. php and NGINX are both definitely running and communicating, however php fails to get the file for some reason. When accessing any non-php file, NGINX successfully retrieves the file and my browser displays it. I have verified, using netstat, that the only thing listening on port 9100 is my php-cgi. And the only thing listening on port 8080 is NGINX. Both php and NGINX are configured to communicate correctly, and php-cgi is running via RunHiddenConsole.exe which is in the php directory.

Here is the directory tree, in a format similar to YAML:

    - Code
        - Blog
            - Source (NGINX/php root Location/Website Source Files)
    - NGINX
        - 1.9.11 (NGINX Executable Location)
            - php (php Executable Location)

And my nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;

http {
    client_max_body_size 5G;
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        root   ../../Code/Blog/Source;
        client_max_body_size 5G;
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            index  index.php;
            try_files $uri $uri.html $uri/ @extensionless-php;
            index index.html index.htm index.php;
            client_max_body_size 5G;

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        recursive_error_pages off;

        # proxy the PHP scripts to Apache listening on
        #location ~ \.php$ {
        #    proxy_pass;

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
            client_max_body_size 5G;
            try_files      $uri =404;
            include        fastcgi.conf;
            include        fastcgi_params;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht {
        #    deny  all;

        location @extensionless-php {
             rewrite ^(.*)$ $1.php last;

    # another virtual host using mix of IP-, name-, and port-based configuration
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }

    # HTTPS server
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }


What could be the cause of this error and how can I resolve it so that I can view the php files properly in my browser? (I am using Eclipse PHP to edit the source, and the error occurs with and without Eclipse running.)


As php does not like relative directories, my solution was to use batch to set an absolute directory every startup. I inserted the following in my batch start script prior to starting NGINX.

set TEXT_FILE=conf\phploc.conf
set REL_PATH=..\..\Code\Blog\Source
pushd %REL_PATH%
echo fastcgi_param  SCRIPT_FILENAME  %ABS_PATH%$fastcgi_script_name; > %TEXT_FILE%

Then in the NGINX configuration file, I inserted the following in the php location block to load the directory settings.

include phploc.conf;

You define your root as a relative path, which is relative to the nginx configuration directory.

This is then passed to php-cgi, which probably does not care where nginx keeps its files. So cannot resolve ../../.

You should specify an absolute root.

  • This is what I was specifically trying to avoid as I move directories around sometimes and would like a "universal" installation. I will try telling php a different directory however, and this will be last resort. Thanks for the idea. – Josh Feb 21 '16 at 7:03

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.