2

I am trying to use PHP in my machine. I have nginx server running few other servers along.

Due to curiosity on how to use PHP , i tried to install php-cli and php5-fpm.

The nginx file below seems to work , however on front-end i get the error " 404". When i checked the error log , i found the error

"2016/03/29 14:28:50 [error] 19752#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ::1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "localhost:84"

So i am assuming either my php5-fpm configuration is wrong or my nginx config is wrong .

Here is my nginx configuration file:

server {
listen 84 default_server;
listen [::]:84 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;

server_name localhost;
location / {
    index index.php index.html index.htm;
    root /home/sijan/personal/php_site;
}
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    #fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    #fastcgi_index index.php;
    #include fastcgi_params;
    }
}

I followed the following link from Digital Oceans and skip few steps to install MySQL since i will be using psql.

Any Help will be Highly appreciated.

3
  • Reads as if none of the files configured as index files (index.php, index.html, index.htm) acutally exist in the configured location (/home/sijan/personal/php_site). Commented Mar 29, 2016 at 7:55
  • There is actually index.php, i also tried to change mode and gave full permission it did not solve the issue. Commented Mar 29, 2016 at 11:31
  • You only need read access for the worker process to your scripts, you should remove those "full permissions" again. If your setup succeeds with a static index.html file then most likely your nginx setup is fine. So you will have to check deeper if your php setup is actually usable. Try executing some script an CLI to see if that works. Commented Mar 29, 2016 at 11:36

1 Answer 1

1

I can't immediately see anything wrong with your nginx config but I've found that PHP-FPM and Nginx can be really really temperamental when configuring... Try the following Nginx config instead...

server {
    listen 84 default_server;
    listen [::]:84 default_server ipv6only=on;
    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name _;

    location / {
        index index.php index.html index.htm;
        root /home/sijan/personal/php_site;
    }

    location ~ \.php$ {
        try_files $uri =404;

        fastcgi_index                           index.php;
        fastcgi_pass                            unix:/var/run/php5-fpm.sock;
        fastcgi_connect_timeout                 10;
        fastcgi_send_timeout                    180;
        fastcgi_read_timeout                    180;
        fastcgi_buffer_size                     512k;
        fastcgi_buffers                         4       256k;
        fastcgi_busy_buffers_size               512k;
        fastcgi_temp_file_write_size            512k;
        fastcgi_intercept_errors                on;
        fastcgi_split_path_info                 ^(.+\.php)(/.*)$;
        fastcgi_keep_conn                       on;
        include fastcgi_params;
    }
}

Also, don't forget that you've got your Nginx server listening on port 84 in your config, not the standard port 80.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried using the configuration, but i am having the same issue. However i tried something else, in /php_site , previously i had index.php with <?php phpinfo() ?> , this was not working at all, i removed index.php to index.html and added simple text and it seems to work. So i am wondering, is it actually the fault of php5-fpm . Here is link to my original nginx config [link] (gist.github.com/sidzan/5f7b066a930140007d27) and here is link to my php-fpm-config [link]([gist.github.com/sidzan/a46b5702bc9e63a6f8c5) I really need advice on fixing this.
And i am sorry, i dont know how to use the link properly in comment. Tried to follow this stackoverflow.com/editing-help#comment-formatting .
out of interest, what version of PHP are you using?
I am using PHP 5.5.9. in ubuntu 14.04.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.