Configure Monit to monitor PHP5-FPM on Ubuntu/Nginx setup - php

System: LEMP running on Ubuntu 14.04
I'm trying to configure the tool Monit to restart Nginx or PHP-FPM if ever there is a problem. It is correctly monitoring Nginx however Monit says it will "Not Monitor". Apparently I'm having it check the wrong location.
Here is my Nginx configuration for PHP-FPM that is running on a socket:
location ~ \.php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
fastcgi_keep_conn on; #hhvm param
}
Here is my Monit configuration for both Nginx and PHP-FPM:
## Check Nginx
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
## Check PHP-FPM
check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
group www-data #change accordingly
start program = "/etc/init.d/php5-fpm start"
stop program = "/etc/init.d/php5-fpm stop"
if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart
if 3 restarts within 5 cycles then timeout
I went with the suggested start and stop recommendations despite always restarting with "service php5-fpm restart".
My group - according to /etc/php5/fpm/pool.d/www.conf is "group = www-data". Any suggestions?

Ok, I was able to solve it myself. There were a number of problems. "php5" needed to replace almost every instance of "php". The bad connection I was receiving was referring to the unixsocket so I had to update that as well. Also the new PID location changed it looks like with PHP5-FPM. Here is the final configuration.
## Check PHP-FPM
check process php5-fpm with pidfile /var/run/php5-fpm.pid
group www-data #change accordingly
start program = "/etc/init.d/php5-fpm start"
stop program = "/etc/init.d/php5-fpm stop"
if failed unixsocket /var/run/php5-fpm.sock then restart
if 3 restarts within 5 cycles then timeout

Related

Nginx upstream unix socket keepalive?

Do I need to add any additional configuration to enable keepalive to my PHP-FPM backend?
upstream php_backend {
zone upstreams 64K;
server unix:/var/run/php-fpm.sock max_fails=1 fail_timeout=2s;
keepalive 10;
}
# Pass off php requests to PHP-FPM
location ~* \.php {
try_files $uri =404;
access_log /var/log/php-fpm/example_access.log;
include /usr/local/etc/nginx/php-fpm.conf;
fastcgi_pass php_backend;
}
In the following Nginx guides, when you don't use unix sockets you must add :
proxy_http_version 1.1;
proxy_set_header "Connection" "";
Source :
https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#no-keepalives
https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/#upstream-groups
Is there any additional config I need to add when using a unix socket?
You will need to change keepalive_timeout value in nginx.conf.
In linux (Debian) it is located in /etc/nginx/nginx.conf:
And restart your server with: sudo service nginx restart.
You may also restart fpm after any change in config with sudo service php7.4-fpm restart. (It is php7.4-fpm in may case)
To see all available services use systemctl list-units --type=service --all

Xdebug silently catches connections with no reason

The application runs on docker containers: nginx and php-fpm. Xdebug is configured with PhpStorm. The app was working correctly until suddenly Xdebug started to catch all connections even when I didn't enable debugging. I didn't even change anything in configuration - it just started to do this (a bit magic but of course there should be something).
Why it's Xdebug: if I remove the Xdebug settings from Dockerfile, everything starts working. Also, requests hang like it happens when I debug them, i.e. they die after a few minutes waiting with the 504 Gateway Time-out error.
PhpStorm doesn't start a debug session, so it happens silently. Closing PhpStorm doesn't help. Restart of containers, the docker daemon itself and even OS don't help as well. Nothing changes in different browsers.
php-fpm/Dockerfile:
FROM php:7.3.18-fpm-alpine
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.9.8 \
&& docker-php-ext-enable xdebug
#...there are more lines, but even when I remove them, the issue remains
#When I comment this line and do `docker-compose build && docker-compose down && docker-compose up -d`,
# the app returns to life.
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
php-fpm/xdebug.ini:
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=off
xdebug.remote_host=docker.for.mac.localhost
xdebug.remote_port=10000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=true
xdebug.var_display_max_depth = 16
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = -1
docker-compose.yml:
version: '3.7'
services:
nginx:
image: nginx:stable
volumes:
- ./docker/nginx/vhost.conf.template:/tmp/vhost.conf.template
- ./docker/nginx/logs:/logs
- ./:/app
depends_on:
- php-fpm
php-fpm:
build: docker/php-fpm
environment:
PHP_IDE_CONFIG: serverName=app.local
volumes:
- ./:/app
nginx/vhost.conf:
server {
charset utf-8;
client_max_body_size 250M;
listen 80;
server_name app.local;
root /app/public;
index index.php;
access_log /logs/nginx.app.access.log;
error_log /logs/nginx.app.error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass fpm:9000;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
location ~* "/\." {
deny all;
return 404;
}
}
It's Docker Desktop 2.5.0 on MacOS 10.14.6.
What could it be?
Why it's Xdebug: if I remove the Xdebug settings from Dockerfile, everything starts working. Also, requests hang like it happens when I debug them, i.e. they die after a few minutes waiting with the 504 Gateway Time-out error.
Enable Xdebug log to confirm that the debug session is established and check what communication is going on there (if any). This should give you some clues on what that might be.
Anyway, it looks like you have some service on that TCP 10000 port already (on your host OS (Mac)) that prevents PhpStorm from listening there (IDE can detect already occupied port on Windows and Linux but not on Mac -- WI-29443).
Use something like sudo lsof -nP -iTCP -sTCP:LISTEN and check what that service might be. Then either shutdown that app or use another port (either for that app or for your Xdebug communications).

webserver process permissions problems on vagrant+nginx+php fpm

I have a vagrant box with a LEMP (linux, nginx, mariadb, php) stack for developing a webapp and I am currently having some issues configuring nginx and php-fpm. I am using puppet and puPHPet to provision the VM.
It seems that the combo php-fpm and nginx are unable to write files (ie. log files generated, assets published by the framework (yii2) etc).
This project worked just fine using apache instead of nginx, so I would discard a programming issue and I have been following the guidelines for nginx installation and still getting messages such as "The directory is not writable by the Web process" or "Permission denied" like errors.
As recommended I set /etc/php5/fpm/php.ini the option cgi.fix_pathinfo = 0.
nginx/sites-available/site.conf
server {
listen *:80;
server_name site.dev;
client_max_body_size 128M;
root /var/www/frontend/web;
index index.php;
access_log /var/log/nginx/test.access.log;
error_log /var/log/nginx/test.error.log;
location / {
root /var/www/frontend/web;
try_files $uri $uri/ index.php /index.php$is_args$args;
}
location ~ \.php$ {
root /var/www/frontend/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APP_ENV dev;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
php-fpm/www.conf
user = www-data
group = www-data
listen-owner = www-data
listen-group = www-data
listen-mode = 0660
I've seen other posts where listen-mode is commented out, I tried both methods and setting mode to 0666 but still no luck.
I tried also setting permissions from the out and the inside of the vagrant to 0777 over the folders that I know that the framework uses to write data but still no luck.
I have a very similar project at work configured just the same that it works but this one doesn't and I can't find the difference (in fact I took config files from this project to set up the new one after the first failed attempt).
ps aux | grep php
root php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data php-fpm: pool www
www-data php-fpm: pool www
Directories in the different projects seem to have the same permissions number yet onw eorks and the other doesn't.
I'm completely clueless! Ideas are very welcomed!

Trouble Installing Nginx and php5-fpm on Debian 7.3

I have a Debian 7.3 installation in a VM that I am practising installing Nginx and php5-fpm on. I got the Nginx working, by assigning it a manual port of :8080 and that points to /var/www/ for data and in that directory is an index.html and info.php file.
The config file for my Nginx is located at /etc/nginx/conf.d/default.conf and looks like this:
server {
listen 8080;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I have tried changing fastcgi_pass both ways:
fastcgi_pass 127.0.0.1:9000;
and also as:
fastcgi_pass unix:/var/run/php5-fpm.sock;
In my /etc/php5/fpm/pool.d/www.conf file I have the following configuration:
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
;listen = /var/run/php5-fpm.sock
Here too, I have uncommented the line to match in the Nginx default.conf file.
In my php.ini file I have edited it so that it shows cgi.fix_pathinfo = 0 as required by most of the guides I have seen.
When I try to load nginx, it runs OK. When I try to run php5-fpm this is what happens:
root#debianx86:/# /etc/init.d/php5-fpm status
[FAIL] php5-fpm is not running ... failed!
root#debianx86:/# /etc/init.d/php5-fpm reload
[ ok ] Reloading PHP5 FastCGI Process Manager: php5-fpm.
root#debianx86:/# /etc/init.d/php5-fpm restart
[FAIL] Restarting PHP5 FastCGI Process Manager: php5-fpm failed!
root#debianx86:/# /etc/init.d/php5-fpm start
root#debianx86:/# /etc/init.d/php5-fpm status
[FAIL] php5-fpm is not running ... failed!
root#debianx86:/#
I then open up any of the browsers on my VM and point them to either 127.0.0.1:8080 or localhost:8080 and I get the custom index.html loading that I made and it works! So I then try to load theinfo.php file and I get presented with a 404 Not Found - nginx/1.4.4.
I don't understand what I'm doing wrong. Is there something I'm missing from all this?
I installed nginx from sudo apt-get -y install nginx and sudo apt-get -y install php5-fpm too. Any dependencies they required would have been installed along with that.
Is there a script that I can run on a fresh install of Debian 7.3 that someone has got that will install it properly for me, and make all the modifications so that nginx and php5-fpm are up and running? I've looked over many of the websites with the instructions and I seem to be doing pretty much everything they do, except for the default-sites and enabled-sites, as neither of those folders exist for me, and I don't want to run my virtual hosts like that. I will run them with their own servers listed in the default.conf file.
EDIT: I have even tried following this article at DigitalOcean and it still doesn't work.
EDIT #2: I also did chown -R www-data:www-data /var/www to ensure that the user and group match the information in the www.conf file. I also tried by changing it back to the original root:root specs too. Still nothing.
I think maybe port 9000 is already being used, so php5-fpm can't bind with that port and fails to start.
in the fpm pool settings swap the line of port 9000 with the line with the sock file, then try to start php5-fpm like you were doing, if it works then all you need is to update the nginx configuratuin to proxy pass to the sock file instead of the port.

PHP-FPM and Nginx: 502 Bad Gateway

Configuration
Ubuntu Server 11.10 64 bit
Amazon AWS, Ec2, hosted on the cloud
t1.micro instance
Before I write anything else, I'd like to state that I've checked both nginx 502 bad gateway and Nginx + PHP-FPM 502 Bad Gateway threads, which unfortunately haven't helped me in this regard.
The issue appears to be rather common: a misconfiguration of nginx or php-fpm can lead to a 502 Bad Gateway error, which is something that I haven't been able to get rid of. Note that this appears even when I go to my domain root, without specifying any particular directory.
I'm running an Amazon EC2 webserver, with port 9000 enabled, port 80 open, etc.
The question in particular is, how can I get rid of this nasty error? Or, better yet, how can I get php5-fpm to actually work.
What I Have Attempted so Far
Mostly consistent editing of configuration files, notably php-fpm.conf and nginx.conf.
i. php-fpm.conf
I've added the following, which hasn't quite helped much:
;;;;;;;;;;;;;
; Fpm Start ;
;;;;;;;;;;;;;
;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35
Now, afterward I tried including my configuration files:
include=/etc/php5/fpm/*.conf
Which only screwed me even further.
Full Configuration
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr). This prefix can be dynamicaly changed by using the
; '-p' argument from the command line.
; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p arguement)
; - /usr otherwise
;include=/etc/php5/fpm/*.conf
;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;
[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /var/run/php5-fpm.pid
; Error log file
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php5-fpm.log
; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice
; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0
; Interval of time used by emergency_restart_interval to determine when
; a graceful restart will be initiated. This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 0
; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0
; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
daemonize = no
;;;;;;;;;;;;;
; Fpm Start ;
;;;;;;;;;;;;;
;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
; Multiple pools of child processes may be started with different listening
; ports and different management options. The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)
; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf
ii. nginx.conf
In all honesty this configuration is a smattering of a few websites I've visited, but I can tell you that before this 502 Bad Gateway business, the server was running fine (without PHP working. Period.).
The issue primarily lies in the fact that something is terribly, terribly wrong. And now, when I try to do a service php5-fpm restart, it hangs in what I'm guessing is an infinite loop or something, which I can't even CTRL-C out of.
Full Configuration
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;
events {
worker_connections 64;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush off;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name ec2-xx-xx-xx-xx.compute-x.amazonaws.com;
location ~ ^(.+\.php)(.*)$ {
root /home/wayvac/public;
fastcgi_pass unix:/var/run/php5-fpm.pid;
#fastcgi_pass 127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm.
fastcgi_index index.php;
set $document_root2 $document_root;
if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root2$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root2$fastcgi_path_info;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT $document_root2;
}
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
root /home/wayvac/public;
index index.html index.htm index.php;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
#include drop.conf;
#include php.conf;
}
}
If anyone finds this page by encountering the same problem I had, I found the answer here.
For those of you who can't be bothered to click and work it out for themselves... ;)
The Condition:
Ubuntu or Debian server with NGINX and PHP 5.3 works fine but upgrading PHP to 5.4 gives 502 Bad Gateway errors. Looking for services running on port 9000 (typically running netstat -lp or similar) returns nothing.
The fix:
Open /etc/php5/fpm/pool.d/www.conf and make a note of the 'listen' parameter (in my case /var/run/php5-fpm.sock):
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock
and replace the fastcgi_pass variable in your vhost with the location you just noted.
So this sample symfony2 configuration (taken from here):
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
becomes this:
# pass the PHP scripts to FastCGI server at /var/run/php5-fpm.sock
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
Then restart nginx:
sudo /etc/init.d/nginx restart
Note: replace ~ ^/(app|app_dev)\.php(/|$) { with ~ ^/index\.php(/|$) { if you're not on SF2**
Hope this saves someone a little bit of time :)
Edit
Of course, you could change the listen = /var/run/php5-fpm.sock to listen = 127.0.0.1:9000 in /etc/php5/fpm/pool.d/www.conf then restart php5-fpm (which would save you from having to change your vhosts), but you have to assume they changed php5-fpm to run through a socket rather than listening on port 9000 for a reason.
Edit2
If you're still experiencing 502 error see this answer.
Try setting these values, it solves problem in fast-cgi
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
I made all this similar tweaks, but from time to time I was getting 501/502 errors (daily).
This are my settings on /etc/php5/fpm/pool.d/www.conf to avoid 501 and 502 nginx errors…
The server has 16Gb RAM. This configuration is for a 8Gb RAM server so…
sudo nano /etc/php5/fpm/pool.d/www.conf
then set the following values for
pm.max_children = 70
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500
After this changes restart php-fpm
sudo service php-fpm restart
If you met the problem after upgrading php-fpm like me, try this:
open /etc/php5/fpm/pool.d/www.conf
uncomment the following lines:
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
then restart php-fpm.
Don't forget that php-fpm is a service. After installing it, make sure you start it:
# service php-fpm start
# chkconfig php-fpm on
For anyone else struggling to get to the bottom of this, I tried adjusting timeouts as suggested as I didn't want to stop using Unix sockets...after lots of troubleshooting and not much to go on I found that this issue was being caused by the APC extension that I'd enabled in php-fpm a few months back. Disabling this extension resolved the intermittent 502 errors, easiest way to do this was by commenting out the following line :
;extension = apc.so
This did the trick for me!
You should see the error log.
By default, its location is in /var/log/nginx/error.log
In my case, 502 get way because of:
GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
2016/05/25 11:57:28 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
When we know exactly what is wrong, then fix it. For these error, just modify the buffer:
fastcgi_buffers 16 512k;
fastcgi_buffer_size 512k;
The port was changed to 9001 in 5.4, just changing the port from 9000 to 9001 in the nginx conf and in php-fpm configuration worked for me.
Hope this tip will save someone else's life. In my case the problem was that I ran out of memory, but only slightly, was hard to think about it. Wasted 3hrs on that. I recommend running:
sudo htop
or
sudo free -m
...along with running problematic requests on the server to see if your memory doesn't run out. And if it does like in my case, you need to create swap file (unless you already have one).
I have followed this tutorial to create swap file on Ubuntu Server 14.04 and it worked just fine:
http://www.cyberciti.biz/faq/ubuntu-linux-create-add-swap-file/
I've also found this error can be caused when writing json_encoded() data to MySQL. To get around it I base64_encode() the JSON. Please not that when decoded, the JSON encoding can change values. Nb. 24 can become 24.00
All right after trying every solution on the web I ended up figuare out the issue using very simple method , first I cheked php-fpm err log
cat /var/log/php5-fpm.log
and the most repeated error was
" WARNING: [pool www] server reached pm.max_children setting (5), consider raising it "
I edit PHP-fpm pools setting
nano /etc/php5/fpm/pool.d/www.conf
I chenged This Line
pm.max_children = 5
To new Value
pm.max_children = 10
BTW I'm using low end VPS with 128MB ram As everyone else I was thinkin redusing pm.max_children will make my server run faster consume less memory , but the setting we using were too low tho even start PHP-fpm process .
I hope this help others since I found this after 24 hour testing and failing , ever my webhost support were not able to solve the issue .
I'm very late to this game, but my problem started when I upgraded php on my server. I was able to just remove the .socket file and restart my services. Then, everything worked. Not sure why it made a difference, since the file is size 0 and the ownership and permissions are the same, but it worked.
Before messing with Nginx config, try to disable ChromePHP first.
1 - Open app/config/config_dev.yml
2 - Comment these lines:
chromephp:
type: chromephp
level: info
ChromePHP pack the debug info json-encoded in the X-ChromePhp-Data header, which is too big for the default config of nginx with fastcgi.
In your NGINX vhost file, in location block which processes your PHP files (usually location ~ \.php$ {) through FastCGI, make sure you have next lines:
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
After that don't forget to restart fpm and nginx.
Additional:
NGINX vhost paths
/etc/nginx/sites-enabled/ - Linux
'/usr/local/etc/nginx/sites-enabled/' - Mac
Restart NGINX:
sudo service nginx restart - Linux
brew service restart nginx - Mac
Restart FPM:
Determine fpm process name:
- systemctl list-unit-files | grep fpm - Linux
- brew services list | grep php - Mac
and then restart it with:
sudo service <service-name> restart - Linux
brew services restart <service-name> - Mac
Maybe this answer will help:
nginx error connect to php5-fpm.sock failed (13: Permission denied)
The solution was to replace www-data with nginx in /var/www/php/fpm/pool.d/www.conf
And respectively modify the socket credentials:
$ sudo chmod nginx:nginx /var/run/php/php7.2-fpm.sock

Categories