Php fpm script error

Nginx 1 FastCGI sent in stderr: “Primary script unknown”

My first time using Nginx, but I am more than familiar with Apache and Linux. I am using an existing project and when ever I am trying to see the index.php I get a 404 File not found. Here is the access.log entry:

2013/06/19 16:23:23 [error] 2216#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.ordercloud.lh" 
server < set $host_path "/home/willem/git/console/www"; access_log /www/logs/console-access.log main; server_name console.ordercloud; root $host_path/htdocs; set $yii_bootstrap "index.php"; charset utf-8; location / < index index.html $yii_bootstrap; try_files $uri $uri/ /$yii_bootstrap?$args; >location ~ ^/(protected|framework|themes/\w+/views) < deny all; >#avoid processing of calls to unexisting static files by yii location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ < try_files $uri =404; ># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php < fastcgi_split_path_info ^(.+\.php)(.*)$; #let yii catch the calls to unexising PHP files set $fsn /$yii_bootstrap; if (-f $document_root$fastcgi_script_name)< set $fsn $fastcgi_script_name; >fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fsn; #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fsn; > location ~ /\.ht < deny all; >> 

My /home/willem/git/console is owned by www-data:www-data (my web user running php etc) and I have given it 777 permissions out of frustration. My best guess is that something is wrong with the config, but I can’t figure it out. UPDATE So I moved it to /var/www/ and used a much more basic config:

server < #listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /var/www/; index index.html index.htm; # Make site accessible from http://localhost/ server_name console.ordercloud; location / < root /var/www/console/frontend/www/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www; include fastcgi_params; >location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ < try_files $uri =404; >location /doc/ < alias /usr/share/doc/; autoindex on; allow 127.0.0.1; deny all; >> 

Also if I call localhost/console/frontend/www/index.php I get a 500 PHP which means it is serving there. It just isn’t serving off console.ordercloud .

Источник

Access denied (403) for PHP files with Nginx + PHP-FPM

I have been spending few hours on that issue and despite the high number of posts related to it, I cannot solve it. I have a Fedora 20 box with Nginx + PHP-FPM that worked quite good until today (after I reloaded php-fpm.service I guess). Nginx is serving static files with no problem, but any PHP file triggers an error 403. The permissions are ok, nginx and php-fpm are running under the user «nginx»:

root 13763 0.0 0.6 490428 24924 ? Ss 15:47 0:00 php-fpm: master process (/etc/php-fpm.conf) nginx 13764 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13765 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13766 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13767 0.0 0.1 490428 7296 ? S 15:47 0:00 php-fpm: pool www nginx 13768 0.0 0.1 490428 6848 ? S 15:47 0:00 php-fpm: pool www 

The served files have been set to nginx user as well, I even ended chmoding 777 those files to try, but still «Access denied» for any PHP files. Below is a server of my Nginx config:

[www] . listen = 127.0.0.1:9000 user = nginx group = nginx . 

For the versions: php-5.5.11 (as well as php-fpm-5.5.11 of course) nginx-1.4.7 I am adding the Nginx error log:

 FastCGI sent in stderr: "Access to the script '/var/www/html' has been denied (see security.limit_extensions)" while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxx.xxx.xxx.xxx" 

And precise that security.limit_extensions is correct, set to: security.limit_extensions = .php . About the path permissions, /var/www/html can be traversed. What am I missing?

Читайте также:  Php fpm webp nginx

Источник

Nginx throws 404 only on php scripts using php-fpm

The server returns 404 on (and only on) .php scripts. I can rename them to .html and they’d be fine. How can I go about this?

user nginx; worker_processes 1; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events < worker_connections 1024; >http < include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; keepalive_timeout 2; include /etc/nginx/conf.d/*.conf; index index.html index.htm; server < listen 80; server_name _; root /var/www/html; location / < root /var/www/html; index index.php index.html index.htm; >error_page 404 /404.html; location = /40x.html < #root /var/www/html; >error_page 500 502 503 504 /50x.html; location = /50x.html < #root /var/www/html; >location ~ \.php$ < root /var/www/html; 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; >> > 

4 Answers 4

Solved it. It turns out that the problem was the permissions set on the socket where php was listening. I just had to change a directive called listen.mode on /etc/php-fpm.d/www.conf

And set the user to nginx :

listen.owner = nginx listen.group = nginx 

So the file looks like this:

srwxr-x---. 1 nginx nginx 0 jul 8 08:59 /var/run/php5-fpm.sock 

Because I was using a unix socket instead of a tcp port:

listen = /var/run/php5-fpm.sock; 

Also, I was getting 404 instead of 500 or 503 because my www.conf was configured to redirect errors to custom pages, and since they weren’t there, I was getting 404 ‘s.

It appears that in most recent versions of the nginx distribution in Fedora (Fedora 22, 23), nginx uses the apache user by default, and the socket is set to the user apache too, so no further configuration is needed.

Right, you must control: — What user/group run nginx (or any webserver) — What user/group run php-fpm

I Actually got a «Not Found» error because a book I read gave me an incorrect matching string for the path /php_status which I had configured in php-fpm 7.0.x (currently 7.0.19) and in nginx 1.12 (currently 1.12.0)

Here is the /etc/php/7.0/fpm/pool.d/

pm.status_path = /php_status 

Here is the config for default in /etc/nginx/sites-available (I’m on Ubuntu)

server < listen 80 default; root /var/www; index index.html index.htm default.html; access_log /dev/null; error_log /dev/null; location / < try_files $uri $uri/ =404; >location /php_status < fastcgi_pass unix:/var/run/php7.0-fpm.sock; # fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; include fastcgi_params; allow 127.0.0.1; deny all; >> 

Note: The following is designed so that /php_status is not publicly available on the internet (nor is PHP served or setup for default host). It also includes fastcgi_pass directive for tcp and unix-socket php-fpm

You also should run the following two commands after

sudo service nginx reload sudo service php7.0-fpm restart 
curl http://127.0.0.1/php_status 

Источник

Читайте также:  Css пробел между блоками

PHP-FPM: How to fix ‘Primary script unknown’ or ‘file not found’

How to fix nginx Primary script unknown or file not found

I encountered this error yesterday after upgraded php-* packages then restart its service. All my websites were stopped working, I got ‘File not found.’ message on the screen and found the ton repeated of error messages in log of nginx Primary script unknown.

TL;DR:

  • Since php-fpm version 7.4.0 php-fpm.service defines ProtectHome=true which restricts access to files located within /home , /root and /run/user , yielding the error message No input file specified .
  • To fix this problem, either set ProtectHome=false in php-fpm.service file or move your document root.

The issue I’m facing after fully upgraded system, reboot my VPS:

  • Browsing to it in browser returns the text “File not found”.
  • nginx error.log contains:

2019/12/17 15:36:09 [error] 1502#1502: *1 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, …

The message is telling us that the FastCGI handler doesn’t like whatever it was sent for some reason. The problem is that sometimes we have no idea what the reason is. On my experience of using nginx, the error message Primary script unknown is almost always related to a wrongly set SCRIPT_FILENAME in the nginx fastcgi_param directive or incorrect permissions. It’s seem correctly answer when the php-fpm.service stopped working with error:

ERROR: failed to open configuration file ‘/etc/php/php-fpm.conf’: Permission denied (13)

I tried turns out that the root location had to match the location of the files on the php-fpm as that’s what was being past through via:

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name

But it doesn’t work.
Well, if I remove my SCRIPT_FILENAME then all I get is an empty, white, blank page by nginx. No error messages either. It’s mean fastcgi_param is not cause of this problem.
If the SCRIPT_FILENAME is wrong, it may also be PHP is running as the wrong user/group. I take a look on php-fpm.conf , php-fpm.d/www.conf and double-checked for errors and inconsistencies. Everything is ok , no conflicted.
Just wait, I stored all LEMP’s config files in a folder then created symlinks of them to /etc/nginx/ and /etc/php folders. Everything was working fine before I upgraded php-fpm to version 7.4.0. After that, the PHP service only started when all the symbolic links were replaced by real files. Furthermore, my website has ‘file not found‘ error, it’s meaning the files on server is inaccessible. They were isolated.
So I’m seem to figure out what is causing this. It’s PHP-FPM service. It has ProtectHome set to true since 7.4.0!
This problem was caused by ProtectHome=true in the php-fpm systemd unit file if you are serving files in /home such as in a virtual host environment. You can disable this feature by editing the php-fpm unit file and restarting php-fpm.

Looking for ProtectHome=true then change it to false or add the following:

Alternatively, move your document root.
If you are not sure about the ProtectHome is existed, here is the command to check it is running:

$ sudo systemctl cat php-fpm.service | grep ProtectHome ProtectHome=true

Before restart php-fpm service, make sure to reload the systemd daemon:

$ sudo systemctl daemon-reload

It’s done. Everything is OK now.

What is ProtectHome?

  • If true, the directories /home , /root , and /run/user are made inaccessible and empty for processes invoked by this unit.
  • If set to “ read-only “, the three directories are made read-only instead.
  • If set to “ tmpfs “, temporary file systems are mounted on the three directories in read-only mode. The value “ tmpfs ” is useful to hide home directories not relevant to the processes invoked by the unit, while still allowing necessary directories to be made visible when listed in BindPaths= or BindReadOnlyPaths= .

Divi 3 is the Ultimate Multi-Purpose and Best Drag Drop WordPress Theme that fit any occasion and it has the tools you need to make your vision a reality …

There are best 10 WordPress plugins which listed here will allow you Improve WooCommerce Product Variations with Swatches, and Photos. …

Do you know? Google is cracking down on mobile-unfriendly sites. If your site isn’t optimized for mobile, you’re losing a whole chunk of users on the go who will quickly look elsewhere if your site does’t load on their device. Here’re 3 fantastic plugins that will automatically optimize your WordPress site for all types of mobile devices. …

There are dozens of WordPress invoice plugins which you can use to turn WordPress into an excellent invoicing and billing system. They help you to generate, edit and send customized and itemized invoices to your clients without having to leave your WordPress site’s control panel. …

About NARGA.NET

NARGA is a blog dedicated to share top quality open source resources for web developer and web designer weekly (then daily asap).
As a web designer or developer, you’ll find some of the best free icons, stock photos, fonts, free WordPress themes, userful WordPress plugins, best jQuery plugins, CSS3 snippets, HTML5 standard and a lot more …

Connect with Us

This site is licensed under Attribution-NonCommercial-ShareAlike 3.0 license. Feel free to change, reuse modify and extend it. Some authors will retain their copyright on certain articles.
NARGA.NET utilizes affiliate links and may receive a comission if you click an affiliate link and make a purchase. No worries though, you’ll still pay the standard amount so there’s no cost on your part.

Источник

How to resolve a PHP-FPM Primary script unknown with a PHP-FPM and an Nginx Docker container?

I’m no nginx expert, but literally every instance of fastcgi_param SCRIPT_FILENAME in the docs ends with $fastcgi_script_name , and yours doesn’t.

I broke my brain trying to figure out why it is not working. As usual, it’s a matter of inattention. So, in my nginx.conf I have lines:

set $root "/var/www/html/web"; root $root; set $bootstrap "index.php"; index $bootstrap; location / < index index.html $bootstrap; try_files $uri $uri/ /$bootstrap?$args; expires -1; >location ~ \.php$ < fastcgi_split_path_info ^(.+.php)(.*)$; set $fsn /$bootstrap; if (-f $document_root$fastcgi_script_name) < set $fsn $fastcgi_script_name; >fastcgi_pass php:9000; fastcgi_index $bootstrap; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fsn; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fsn; try_files $fsn =404; expires -1; > include defaults.conf; 
php: image: aspendigital/octobercms:php7.2-fpm container_name: "$_php" volumes: - ./web:/var/www/html # <- this line is incorrect! Mounts MUST be identical! nginx: image: wodby/nginx:$NGINX_TAG container_name: "$_nginx" depends_on: - php environment: NGINX_STATIC_OPEN_FILE_CACHE: "off" NGINX_ERROR_LOG_LEVEL: debug NGINX_BACKEND_HOST: php NGINX_SERVER_ROOT: /var/www/html/web/ NGINX_CONF_INCLUDE: /var/www/html/nginx/*.conf volumes: - ./:/var/www/html:cached 

So, replaсing in php-part the volume to the same as in the nginx-part solved my problem. Be careful!

Источник

Оцените статью