Php fpm not running

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.

Читайте также:  Xinki ru doku php bootswatchtheme spacelab

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.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP-FPM service showing as not running #82

PHP-FPM service showing as not running #82

Comments

I just decided to give Ajenti (V) a test-run for one of our internal servers and I do really like it.
Set-up was quite simple, but now trying to set-up a PHP site, when I got to ‘Websites’ Ajenti is showing me

capture decran 2014-07-01 a 12 39 00

Even though when I check through the server it is showing me:

Читайте также:  Html div label input

capture decran 2014-07-01 a 12 37 45

So things actually do work and it just seems to be an issue with Ajenti. Any idea what the cause could be?

Edit: I am also not even getting a simple index.php to show up. I looked at the wordpress tutorial and some other things online, but all the server seems to do when I go to the URL is downloading the .php file instead displaying what it should display. Anyone here know what the issue could be?

Any help/comment is really appreciated.

The text was updated successfully, but these errors were encountered:

Источник

How to Fix Nginx 502 Bad Gateway Error on PHP-FPM

Nginx is one of the fast performing web servers on the internet. Nginx and php-fpm are the most used combinations on the internet to server PHP websites. Sometimes we came across a very bad Nginx 502 Bad Gateway error generated by Nginx server and it is not very easy to identify the problem and fix. Here are some quick solutions to fix Nginx 502 Bad Gateway error on a web-server.

Nginx 502 Bad Gateway Error

How Nginx 502 Bad Gateway Error happens and what is its connection with php-fpm

Common 502 errors include the following messages from Nginx server

  • “502 Bad Gateway”
  • “502 Bad Gateway NGINX”
  • “502 Proxy Error”
  • “502 Service Temporarily Overloaded”
  • “Error 502”
  • “HTTP Error 502 – Bad Gateway”
  • “HTTP 502 Bad Gateway”

These errors point to the same situation of Nginx server and the error came across below situations

  • Nginx server running with php-fpm service
  • Nginx is running as a reverse proxy to Apache server
  • Nginx running as a gateway to other services like Python, Ruby, etc.
  • Bad configuration of cache or timeout.

Now the error says there is a “BAD GATEWAY”. That means Nginx server is trying to communicate to another service through a gateway and it is not getting any answer from that gateway. This is Nginx 502 Bad Gateway error situation.

So Nginx and another service (Apache, php-fpm, other services) running. Both are communicating through a gateway and Nginx is not getting any answer from the gateway. To solve 502 Bad Gateway Error the other service running with Nginx must answer through the gateway.

Usually, this happens due to a misconfiguration in the configuration files of the server. Or the other service is not running properly with Nginx. So to solve this problem a two-step check is required.

  • Step 1: Check the other server status, whether it is running perfectly, is it giving the desired output?
  • Step 2: Is the configuration correct? Is the second service configured to answer the gateway perfectly?

Nginx 502 Bad Gateway Error

Nginx 502 Bad Gateway Error with PHP-FPM

The problem occurs due to the following conditions

  • PHP-FPM won’t get started
  • PHP-FPM not running
  • NGINX can’t communicate with PHP-FPM server
  • NGINX is timing out
  • PHP-FPM is timing out with requests

Check whether php-fpm is running or not

systemctl status php-fpm.service

will tell you about the current situation of php-fpm server

Just restart the php-fpm server to solve this problem

systemctl restart php-fpm.service

for php5 the name of service may be php5-fpm, for PHP 7 it may be php7.0-fpm or php7.1-fpm or php7.2-fpm check accordingly.

Php-fpm is not communicating with Nginx and causing a 502 Bad Gateway Error

This is caused due to the misconfiguration of the php-fpm server or the misconfiguration of Nginx server.

Check the following configuration files in the worker pool configuration (the file is in /etc/php/fpm/pool.d/www.conf , this may vary with installation) and verify these lines ( www-data is the owner of the web server process, that is nginx)

user = www-data group = www-data listen = /var/run/php7-fpm.sock listen.owner = www-data listen.group = www-data

then restart the php-fpm service.

Читайте также:  Python terminate from thread

If the Nginx server and php-fpm are running and still getting a 502 Bad Gateway error then it is the problem with communicating the gateway. The problem is happening due to the misconfiguration in the file /etc/nginx/sites-enabled/default , by default or the file name in the name of the website called /etc/nginx/sites-enabled/mywebsite.com.conf

Look at the segment where the fastcgi_pass configuration. It must be the same as the listen in the above configuration

Then restart both Nginx and php-fpm servers. Now check the website whether it is serving properly.

502 Bad Gateway Error due to Nginx is timing out

if php-fpm is running and serving the requests properly then there will be a chance of Nginx is timing out. That is php-fpm do not respond to NGINX in a timely manner will cause a 502 because NGINX couldn’t wait any longer for a response from php-fpm.

In this case, increasing the maximum execution time of the application and NGINX’s timeout window would be the best solution.

To get this we need two changes:

First , increase the maximum execution time of the php-fpm server. To do this open PHP-FPM’s configuration file

sudo nano /etc/php7/fpm/php.ini

find the following line and increase the number to a higher value. Usually 60 or 120.

The value depends upon the expected execution time of the application running in the php-fpm server. Add some extra buffer time to get rid of the situation again.

Exceptionally large execution time will affect the server performance and it may lead to a dead server process in the memory.

Second , edit the NGINX config

sudo nano /etc/nginx/nginx.conf

add the following within the HTTP block to increase timeout windows, buffers, and buffer sizes:

Save the changes to the file and exit. Now restart Nginx and php-fpm

systemctl restart php-fpm.service and
systemctl restart nginx.service

502 Bad Gateway Error due to PHP-FPM is timing out

if the php-fpm server is timing out upon execution of an exceptionally long PHP script or the script is blocked by a large MySQL query process then these solutions may not work. In that situation, you could temporarily extend PHP’s execution time limit by invoking the set_time_limit() function from within the PHP application, but if you are continuously reaching into the execution timeout limit then as a long-term solution like profiling or increasing PHP-FPM’s timeout may be more appropriate to get rid of a 502 error more safely. These things must be done after an extensive research of the execution time of the corresponding PHP function or MySQL query. Take a look at the memory and system load during the execution is a must for a smooth operation of this server.

Nginx 502 Bad Gateway Error when Nginx as Proxy for Apache

In this situation, the gateway service is Apache and the Nginx is a proxy for Apache. If apache server dies or it’s not well configured, it can cause this 502 Bad Gateway error. How to fix the apache error? Most of the times, restarting apache web server will get rid of this, but you must check the log files to know why exactly this was caused.

Nginx with other services/apps and 502 Bad Gateway Error

In this situation, the app is gone not responding. Try restarting the other service behind Nginx server and check the logs created by the application to find the exact reason why a 502 Error happened.

Check the status codes HTTP Status Codes on W3C for more details.

Источник

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