Sijan Shrestha
Sijan Shrestha

Reputation: 2266

"Primary script unknown" PHP

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.

Upvotes: 2

Views: 2663

Answers (1)

Garry Welding
Garry Welding

Reputation: 3609

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.

Upvotes: 1

Related Questions