"Primary script unknown" PHP - 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.

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.

Related

OROCRM Nginx Virtual Host Configuration Not Working

I have installed a orocrm on a AWS Lightsail VPS with Nginx & PHP7. orocrm installed without a hitch but I'm using Nginx for the first time and my virtual host doesn't seem to be working.
sites-available/default:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index app.php index.php index.html;
server_name 34.127.224.10;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I then purchased & pointed crmdomain.com to my instance and created another file.
sites-available/crm:
server {
listen 80;
server_name crmdomain.com www.crmdomain.com;
root /var/www/html/crm/web;
index app.php;
error_log /var/log/nginx/orocrm_error.log;
access_log /var/log/nginx/orocrm_access.log;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location #rewrite { rewrite ^/(.*)$ /app.php/$1; }
location / {
try_files $uri /app.php$is_args$args;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_index app.php;
fastcgi_read_timeout 10m;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I honestly don't know most of what is above, it's mostly based on tutorial and apache experience.
Errors
Domain based
- crmdomain.com -> 403 Forbidden nginx/1.10.0 (Ubuntu)
- crmdomain.com/app.php -> No input file specified.
- crmdomain.com/app_dev.php -> No input file specified.
- crmdomain.com/index.nginx-debian.html -> Welcome to nginx!
- crmdomain.com/user/login -> 404 Not Found nginx/1.10.0 (Ubuntu) **This is what should word**
Static IP based
- 34.127.224.10 -> 403 Forbidden nginx/1.10.0 (Ubuntu)
- 34.127.224.10/crm/web/ - No input file specified.
- 34.127.224.10/crm/web/app.php - No input file specified.
- 34.127.224.10/crm/web/app_dev.php - No input file specified.
- 34.127.224.10/index.nginx-debian.html -> Welcome to nginx!
- 34.127.224.10/crm/web/app.php/user/login -> 404 Not Found nginx/1.10.0 (Ubuntu) **This is what should word**
What am I doing wrong?
It's weird how often I answer my own questions:
I was able to change the default files and remove the extra virtual host. Since the server was only going to host the one app.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 34.127.224.10 crmdomain.com www.crmdomain.com;
root /var/www/html/crm/web;
index app.php app_dev.php index.php;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config|install)\.php(/|$) {
#fastcgi_pass 127.0.0.1:9000;
# or
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/orocrm_error.log;
access_log /var/log/nginx/orocrm_access.log;
}

Creating new Lumen app on nginx throwing 404 when hiting IP Adress through browser

I am trying to create a plain Lumen application on Nginx server on Digital Ocean. Following the official documentation for Laravel, I followed everything as it is said until the Laravel Installation bit.
Just instead of this
composer create-project laravel/laravel /var/www/lumen/ 4.1
I used
composer create-project --prefer-dist laravel/lumen blog` instead.
The Lumen document seems on the directory now when I use ls.
However when I hit the IP address, or IPAdress/index.php, it shows
404 Not Found - nginx/1.4.6 (Ubuntu)
Also, this is my configuration for Virtual Host file (nano /etc/nginx/sites-available/default)`:
server {
listen 80 default_server;
root /var/www/laravel/public/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
What am I doing wrong or missing?
Also, if I try connect to the SSH directory with PhpStorm, I received an error:
ssh://root#46.101.172.134:22null /usr/bin/php
env: /var/www/Lumen: Permission denied
Process finished with exit code 126
Please also check this question for further info on this error..
Edit 2:
I tried changing my server to..
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
listen 443 ssl;
root /var/www/lumen/public;
index index.php index.html index.htm;
server_name IPAddress;
ssl_certificate /etc/nginx/ssl/nginx.crt; // I didn't set this
ssl_certificate_key /etc/nginx/ssl/nginx.key; // and this
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =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;
}
}
I used this guide to create an SSL Certificate on nginx. Then, hitting http://ipaddress gives me the Lumen/Laravel stuff.

PHP with gitlab bundled nginx not working

I've setup gitlab using the omnibus package on CentOS 7. I'd like to use the gitlab server to host additional websites. I've enabled custom nginx conf by adding the below code to /etc/gitlab/gitlab.rb
nginx['custom_nginx_config'] = "include /etc/nginx/conf.d/*.conf;"
I've also created conf files in /etc/nginc/conf.d. Static HTML files are working but when i try to run php scripts, I'm getting a File not found - 404 error.
Following is the nginx conf for php :
server{
listen 80;
server_name example.com;
root /var/www/vhosts/example;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/gitlab/embedded/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /opt/gitlab/embedded/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
The following is the error log:
FastCGI sent in stderr: "Primary script unknown" while reading response from upstream, client x.x.x.x, server: example.com, request: "GET / HTTP/1.1", upsteam: "fastcgi://127.0.0.1:9000", host: "example.com"
Maybe your problem comes from your "location ~ .php$" config.
You already fix the first problem with gitlab omnibus by included the right fatscgi_params instead of the default. Now it seems to comes from the location config.
Try the following code for your configuration :
location ~ \.php$ {
#in your case maybe : /opt/gitlab/embedded/html
root [YOUR APP DIRECTORY];
try_files $uri $uri/ /index.php?$args;
index index.html index.htm index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include /opt/gitlab/embedded/conf/fastcgi_params;
}
This fix works for me on a Debian 8 server.
Hope it could help.

Yet another FastCGI Primary Script Unknown error (nginx, php5-fpm)

This is my error.log from nginx:
2014/10/02 14:51:29 [error] 15936#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 134.106.87.55, server: sumomo.shitteru2.net, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "sumomo.shitteru2.net"
this is my enabled site:
server {
listen 80;
server_name sumomo.shitteru2.net;
index index.php index.html index.htm;
location / {
root /mnt/firstsite;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
As far as I can see everything is very simple so it should work. I even copied it directly from http://wiki.nginx.org/PHPFcgiExample#Connecting_nginx_to_PHP_FPM. Do you guys see any potential problems?
I made a solution I can use everywhere in /etc/nginx/snippets/common.conf:
index index.php index.html index.htm index.nginx-debian.html;
location ~ \.php$
{
include snippets/fastcgi-php.conf;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
And now all my site config files look very simple:
server {
listen 80;
listen [::]:80;
server_name do-it-big.com www.do-it-big.com;
root /var/www/doitbig;
client_max_body_size 10m;
include snippets/common.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
}

Why does nginx return a 403 error on the index.php file?

Calling "http://test.local/" in the browser returns a "403 Forbidden" error.
Calling "http://test.local/index.php" works well.
If I create a "index.html" file, calling "http://test.local/" shows me the "index.html" file correctly.
So just the "index.php" file doesn't work.
This is my vhost configuration:
server {
listen 80;
server_name test.local;
root /var/www/public;
index index.html index.htm index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
The error.log file contains this error:
2013/12/28 14:00:57 [error] 2854#0: *50 directory index of "/var/www/public/" is forbidden, client: 10.0.2.2, server: test.local, request: "GET / HTTP/1.1", host: "test.local"
Why's that? I've googled a lot now and checked permissions (which are all set to 777) and tried lots of other stuff too, but I don't get it working.
I'm new to nginx so probably I'm just missing something.
Thanks a lot!
Your configuration seems fine, but I think it can be simplified, try this
server {
listen 80;
server_name test.local;
root /var/www/public;
index index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}

Categories