Bobcares

Let’s fix – php fpm file not found error

by | Oct 29, 2019

Got stumbled by the error ‘php fpm file not found‘?

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

php-fpm File not found

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.

location ~ \.php$ {
root /opt/nginx/html;
fastcgi_pass unix:/tmp/fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
}

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.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

3 Comments

  1. Kate

    Thanks! You helped me.

    Reply
  2. Alex

    Thank you! I suffered for half a day until I found this page!

    Reply
    • Hiba Razak

      Hello Alex,
      We are glad to know that our article helps you solves the issue 🙂

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.