- Arch Linux
- #2 2019-11-30 14:56:57
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #3 2019-11-30 15:27:08
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #4 2019-11-30 16:47:57
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #5 2019-11-30 17:00:54
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #6 2019-11-30 17:03:13
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #7 2019-11-30 17:15:20
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #8 2019-11-30 17:29:30
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- #9 2019-11-30 17:34:32
- Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
- Let’s fix – php fpm file not found error
- How php-fpm works?
- What causes PHP FPM file not found error?
- 1. Parameter placement error
- 2. Wrong permissions
- 3. FPM not running
- How we fix php fpm file not found error?
- 1. Configuration details problem
- 2. Checking permissions to fix php fpm file not found
- Conclusion
- PREVENT YOUR SERVER FROM CRASHING!
- nginx + php-fpm = File not found
- Solution 2
- Solution 3
- Solution 4
- Nginx & Symlinks
- Solution 5
- Documentation for variables above:
- Read more
Arch Linux
Hello, I just updated packages and now php-fpm seems not working at all. It gives the errors «File not found» in the browser, and «primary script unknown while reading response header» in the log.
I checked all the bhosts, but they are just fine. I suspect there is some change due to the recent security issue in php-fpm, but I cannot find a reference to fix the issue. Any idea?
Last edited by aquilarubra (2019-12-18 05:28:39)
#2 2019-11-30 14:56:57
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
Telling us you looked at the logs is useless, show us. Saying you checked the bhosts is the same. Show us. Post logs, configs, etc, otherwise there is nothing we can offer here but sympathy (and even that’s not so likely). Is this a publicly available server? Give an example to a failing url.
FWIW, I just upgraded my server and have no issues with php-fpm on nginx.
Last edited by Trilby (2019-11-30 14:59:37)
«UNIX is simple and coherent. » — Dennis Ritchie, «GNU’s Not UNIX» — Richard Stallman
#3 2019-11-30 15:27:08
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
access.log:
2019/11/30 16:16:29 [error] 9842#9842: *3 FastCGI sent in stderr: «Primary script unknown» while reading response header from upstream, client: 203.15.17.121, server: thelord.space, request: «GET /phpinfo.php HTTP/2.0», upstream: «fastcgi://127.0.0.1:9000», host: «thelord.space»
error.log:
151.95.156.135 — — [30/Nov/2019:16:16:29 +0100] «GET /phpinfo.php HTTP/2.0» 404 36 «-» «Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0»
I tried with the different settings for SCRIPT_FILENAME and none seems working. Previously, the server was working with the full path: fastcgi_param SCRIPT_FILENAME /home/thelord.space/public_html$fastcgi_script_name;
The php-fpm error log contains nothing (just the lines when I restart the server).
Obviously, the paths are correct and if I try with user «http», the files are accessible.
Html pages work and Perl works. Only php-fpm seems broken. Php-fpm server runs just fine.
#4 2019-11-30 16:47:57
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
The title of the thread I linked to is «Post complete logs/output/. «
Obviously, the paths are correct and if I try with user «http», the files are accessible.
How/why is this obvious? What do you mean you try with user «http»? What do you actually do? What are (again) the actual commands and output?
«UNIX is simple and coherent. » — Dennis Ritchie, «GNU’s Not UNIX» — Richard Stallman
#5 2019-11-30 17:00:54
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
ls /home/thelord.space/public_html/phpinfo.php shows it exists.
If I «su http», I can run a command such as «php /home/thelord.space/public_html/phpinfo.php» and it displays the expected output. So, the issue is when php goes through php-fpm.
From my tests, $document_root might not be correct. But I have no clue how to debug that.
#6 2019-11-30 17:03:13
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
Three posts in and you have still failed to provide any of the necessary context despite being explicitly asked twice. I am unable (and now unwilling) to help. I’d encourage you to be much more transparent and forthcoming if you want the next forum member who sees this thread to put in any effort to help you.
Last edited by Trilby (2019-11-30 17:05:26)
«UNIX is simple and coherent. » — Dennis Ritchie, «GNU’s Not UNIX» — Richard Stallman
#7 2019-11-30 17:15:20
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
You must be joking, I have answered every question and published my configuration and logs. Get glasses.
#8 2019-11-30 17:29:30
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
Is the system using php-fpm.service ?
#9 2019-11-30 17:34:32
Re: [SOLVED] nginx + php-fpm — file not found, primary script unknown
Yes. Sorry, I saw I omitted a few lines, as I am doing many tests.
location ~ \.php$ < fastcgi_split_path_info ^(.+?\.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) < return 404; ># Mitigate https://httpoxy.org/ vulnerabilities fastcgi_param HTTP_PROXY ""; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; access_log /home/thelord.space/logs/access_log; error_log /home/thelord.space/logs/error_log;
fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param HTTPS $https if_not_empty; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; #fastcgi_param REQUEST_SCHEME $scheme;
netstat -pnltu | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 12417/php-fpm: mast
Last edited by aquilarubra (2019-11-30 17:36:40)
Let’s fix – php fpm file not found error
The php fpm file not found error is normally caused due to permissions error or due to improper details in the configuration file.
At Bobcares, we receive requests to fix php-fpm related errors as a part of our Server Management Services.
Today, let’s discuss the causes for PHP-FPM error and see how our Support Engineers fix it.
How php-fpm works?
Let’s begin by checking the working of PHP-FPM ( FastCGI Process Manager ).
Traditionally, the web server compiles PHP scripts through server modules such as suPHP, CGI, DSO. PHP-FPM provides a new experience that avoids the drawbacks of other PHP handlers like suPHP, CGI, DSO.
In PHP-FPM, a separate service is designed specifically for processing PHP scripts. In addition, PHP-FPM has a “master process” managing pools of individual “worker processes.”
When the webserver requests for any PHP scripts, it uses a proxy, Fastcgi connection to forward the request to PHP-FPM service. As PHP-FPM receives a proxied connection, a free PHP-FPM worker accepts the web server’s request.
PHP-FPM then compiles and executes the PHP script, sending the output back to the webserver. Once a PHP-FPM worker finishes handling a request, the system releases the worker and waits for new requests.
What causes PHP FPM file not found error?
Often when accessing the website files, Nginx server may not be serve the pages. It ends up in file not found error. For instance, on a misconfigured server, the error shows up as:
Now, let’s discuss the different reasons causing this error.
1. Parameter placement error
Usually, when the configuration file of Nginx has improper parameters, then it will throw errors. Also, placing the configuration file in the wrong path will cause errors.
There must not be any confusion for the webserver modules to understand these parameters. This includes setting the proper document root. For the website files to show up, they must be accessible for the Nginx server.
2. Wrong permissions
In a similar way, the user running the php-fpm must have proper permissions to run the PHP scripts. By default, Nginx runs under the ownership of the user ‘www-data‘. This varies according to the configuration of the server.
If the files have any incorrect permissions, then the scripts don’t execute and end up with the file not found error.
Occasionally, security settings like SELinux may also affect the file access.
3. FPM not running
FPM not running on the server can also be an obvious reason for the error. In many cases, improper configuration of PHP-FPM results in frequent restart of the service. At times, the service may not even start. Then also it would report the file not found error.
How we fix php fpm file not found error?
Till now we saw what causes this error to occur. Now, let’s see how our Support Engineers fix it.
1. Configuration details problem
One of our customers received the below error message while accessing info.php
And, he was using the configuration that set the default file location as /var/www. But, the FastCGI was set as /usr/share/nginx/html.
server < listen 80; listen [::]:80 default ipv6only=on; server_name localhost; location / < root /var/www; index index.html index.htm index.php; ># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ < fastcgi_pass 127.0.0.1:7777; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; . . >>
This caused FastCGI to look for the file at /usr/share/nginx/html/info.php;
As this was unavailable, it returned the error.
To fix the error, our Dedicated Engineers updated the above code and set the same root for html and PHP. Also, we kept the root and index parameters outside the location except for specific users.
Then, we suggested customer to write $document_root$fastcgi_script_name instead of /usr/share/nginx/html$fastcgi_script_name within the location as below.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Finally, this fixed the error.
2. Checking permissions to fix php fpm file not found
We received another request from our customer telling us that he received a “file not found” error on all PHP files.
Initially, our Support Engineers went checking the configuration file and suggested to put “include fastcgi_params;” before all “fastcgi_param *” lines.
Here, “include fastcgi_params;” overrides all the “fastcgi_param *” lines as below.
Then, we went checking the user running Nginx, PHP-FPM, etc. Then we checked their permissions for accessing the website folder.
We used the below commands:
ps aux | grep php-fpm ps aux | grep nginx
Finally, we solved this problem by changing user and group to the current user:group in php-fpm.d/www.conf
[Need any help in fixing php-fpm errors? – We’ll help you]
Conclusion
In short, the php fpm file not found error normally occurs due to permissions error or due to improper details in the configuration file. Today, we saw how our Support Engineers fix this error.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
nginx + php-fpm = File not found
Use the same root for html and php. Also, root and index parameters should be outside a particular location except for very specific uses.
needless to say, you still need to make sure your php-fpm service is listening at port 7777. Common case is to have it listening at port 9000.
Solution 2
If you checked every thing and it’s correct configured, then there is last point i got:
Solution 3
Solution 4
Nginx & Symlinks
Note, if root /var/www; is a symlink, change it to root /var/www/; otherwise nginx won’t go past the symlink and you’ll get a File not found error
Solution 5
In location nginx section, if you use root then the value for $document_root$fastcgi_script_name is correct. But if you use alias the value is wrong. When use alias you need use $request_filename instead of $document_root$fastcgi_script_name .
Documentation for variables above:
file path for the current request, based on the root or alias directives, and the request URI
root or alias directive’s value for the current request
request URI or, if a URI ends with a slash, request URI with an index file name configured by the fastcgi_index directive appended to it. This variable can be used to set the SCRIPT_FILENAME and PATH_TRANSLATED parameters that determine the script name in PHP. For example, for the “/info/” request with the following directives