I want to run php under nginx, I have some difficulties. I'm almost done, however, I have an error 502, I don't know why.
I have Nginx 1.18, php 7.4.x with fpm. I created a php file in: /usr/share/nginx/html/info.php, however when I am on it, I have an error 502. Here is the file I have for the default conf:
server {
listen 80;
root /usr/share/nginx/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
I have seen this line in some cases, however when I do "nginx -t" it fails.
include snippets / fastcgi-php.conf;
I looked carefully, everything works locally, everything works. I do not understand.
In your post above you have server_name example.com. Check if you have the right server name there. Also, make sure your application server is running because nginx is unable to reach that's why you are seeing 502
The problem is having more than 1 config file in /etc/php/7.4/fpm/pool.d
usr#server:/etc/php/7.4/fpm/pool.d$ ls
www.conf foor-php-fpm.conf bar-php-fpm.conf.bak
Solution
Step 1: Remove or rename any other .conf files and leave only www.conf
usr#server:/etc/php/7.4/fpm/pool.d$ sudo mv other-php-fpm.conf other-php-fpm.conf.bak2
Step 2: systemctl restart php7.4-fpm.service
Done!
user#server:~$ systemctl status php7.4-fpm.service
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-12-31 16:16:22 UTC; 6s ago
Docs: man:php-fpm7.4(8)
Process: 381508 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
Main PID: 381487 (php-fpm7.4)
Status: "Ready to handle connections"
Tasks: 3 (limit: 4568)
Memory: 12.1M
CGroup: /system.slice/php7.4-fpm.service
├─381487 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
├─381506 php-fpm: pool www
└─381507 php-fpm: pool www
This solution applies to php-fpm-7.2 as well.
Related
i tryed so much and followed countless guides for that problem but just cant find a solution, so i hope that you can find a problem in my configs or have a other idea what the problem could be.
Beside my planned webpage i run the AMP-Webinterface for server-administration on a supdomain amp.EXAMPLE.COM, on my debian10 server, and that always works like a charm, only my own test-php-site (see below) wont show correctly, i tested with a example html site and that works perfectly.
php8.0-fpm is installed and the only php version (had 7.3 too before and removed it already)
#######################################################
index.php
<html>
<head>
<title>PHP-Test</title>
</head>
<body>
<?php echo '<p>Hallo Welt</p>'; ?>
</body>
</html>
#######################################################
EXAMPLE.COM.conf
server {
if ($host = www.EXAMPLE.COM) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = EXAMPLE.COM) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80; listen [::]:80;
server_name EXAMPLE.COM www.EXAMPLE.COM;
root /var/www/EXAMPLE.COM;
index index.php index.html index.htm index.nginx-debian.html;
location / {
location ~* \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
try_files $uri #yii =404;
}
} }
server {
listen 443; listen [::]:443;
server_name EXAMPLE.COM www.EXAMPLE.COM;
root /var/www/EXAMPLE.COM;
index index.php index.html index.htm index.nginx-debian.html;
location / {
location ~* \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
try_files $uri #yii =404;
}
}
ssl_certificate /etc/letsencrypt/live/EXAMPLE.COM/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/EXAMPLE.COM/privkey.pem; # managed by Certbot
}
#######################################################
nginx -t
nginx: [warn] conflicting server name "amp.EXAMPLE.COM" on [::]:443, ignored
nginx: [warn] conflicting server name "amp.EXAMPLE.COM" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "amp.EXAMPLE.COM" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "amp.EXAMPLE.COM" on [::]:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Nginx Error log isnt showing any errors too, except the "conflicting server name thing"
#######################################################
php8.0-fpm is installed and working ("php-fpm" cant be found by systemctl, could this be a problem?)
systemctl status php8.0-fpm
● php8.0-fpm.service - The PHP 8.0 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php8.0-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-03-16 14:08:33 UTC; 18h ago
Docs: man:php-fpm8.0(8) Main PID: 100460 (php-fpm8.0) Status: "Processes active: 0, idle: 2, > Requests: 11, slow: 0, Traffic: 0req/sec"
Tasks: 3 (limit: 9508) Memory: 17.6M CGroup: /system.slice/php8.0-fpm.service
├─100460 php-fpm: master process (/etc/php/8.0/fpm/php-fpm.conf)
├─100461 php-fpm: pool www
└─100462 php-fpm: pool www
Mar 16 14:08:33 localhost systemd[1]: Starting The PHP 8.0 FastCGI Process Manager... Mar 16 14:08:33 localhost systemd[1]: Started The PHP 8.0 FastCGI Process Manager.
#######################################################
tail -f /var/log/nginx/error.log
[error] 129821#129821: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 217.254.148.38, server: EXAMPLE.COM, request: "GET / HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "EXAMPLE.COM"
#######################################################
Thank you i finally found the solution! breaksdownintearsofjoy
Problem has been that fastcgi wasnt installed >_>
For my debian 10 i just did: apt-get install fcgiwrap
problem was the localhost ip it kinda didnt liked; so i just replaced "fastcgi_pass 127.0.0.1:9000;" with the complete dir of the php fpm sock "fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;"
I have upgraded with success my ubuntu server from php7.0 to php7.2
I am using Nginx with php-fpm. Although php -v output is:
PHP 7.2.11-4+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 4 2018 05:10:57) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.2.5, Copyright (c) 2002-2018, by ionCube Ltd.
with Zend OPcache v7.2.11-4+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
I noticed that Nginx still runs with php-fpm7.0.
I checked and both php-fpm 7.0 & 7.2 are running.
My /etc/nginx/conf.d/mysite.com.conf doesn't include
location ~* .php$
line.
Output of
find / ( -iname "php.ini" -o -name "www.conf" )
is
/etc/php/7.0/apache2/php.ini
/etc/php/7.0/fpm/pool.d/www.conf
/etc/php/7.0/fpm/php.ini
/etc/php/7.0/cli/php.ini
/etc/php/7.2/fpm/pool.d/www.conf
/etc/php/7.2/fpm/php.ini
/etc/php/7.2/cli/php.ini
Also I don't have any /etc/nginx/conf.d/mysite.com.conf file
I only have global_locations_ssl.conf.inc inside /etc/nginx/conf.d/
Output of
ps -aux | grep nginx
is
root 3123 0.0 0.0 37944 4192 ? Ss Nov05 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 3124 0.0 0.0 37944 8416 ? S Nov05 0:54 nginx: worker process
www-data 3125 0.0 0.0 37944 8500 ? S Nov05 0:58 nginx: worker process
www-data 3126 0.0 0.0 37944 8552 ? S Nov05 2:04 nginx: worker process
www-data 3127 0.0 0.0 37944 8588 ? S Nov05 1:04 nginx: worker process
www-data 3128 0.0 0.0 37944 8668 ? S Nov05 1:10 nginx: worker process
www-data 3129 0.0 0.0 37944 8536 ? S Nov05 1:27 nginx: worker process
root 22931 0.0 0.0 13348 916 pts/0 R+ 12:50 0:00 grep --color=auto nginx
So my Nginx master process runs as root.
What should I check to fix this?
you can find solution full solution in https://linode.com/docs/web-servers/nginx/serve-php-php-fpm-and-nginx/
Depending on your distribution and PHP version, the PHP configuration files will be stored in different locations. This guide is using PHP 7.0 from Ubuntu’s repositories on Ubuntu 16.04 as an example, and the
`/etc/php/7.0/fpm/pool.d/www.conf and /etc/php/7.0/fpm/php.ini`
files are what we’ll be modifying.
Find those full file paths using a find command:
`find / \( -iname "php.ini" -o -name "www.conf" \)`
The output should look similar to:
`root#localhost:~# find / \( -iname "php.ini" -o -name "www.conf" \)
/etc/php/7.0/fpm/php.ini
/etc/php/7.0/fpm/pool.d/www.conf
/etc/php/7.0/cli/php.ini
`
The listen.owner and listen.group variables are set to www-data by default, but they need to match the user and group NGINX is running as. If you installed NGINX using our Getting Started with NGINX series, then your setup will be using the nginx user and group. You can verify with:
`ps -aux | grep nginx`
The output should be similar to:
`
root#localhost:~# ps -aux | grep nginx
root 3448 0.0 0.0 32500 3516 ? Ss 18:21 0:00 nginx: master process / usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 3603 0.0 0.0 32912 2560 ? S 18:24 0:00 nginx: worker process
nginx 3604 0.0 0.0 32912 3212 ? S 18:24 0:00 nginx: worker process
`
This shows the NGINX master process is running as root, and the worker processes are running as the nginx user and group. Change the listen variables to that:
`
sed -i 's/listen.owner = www-data/listen.owner = nginx/g' /etc/php/7.0/fpm/pool.d/www.conf
sed -i 's/listen.group = www-data/listen.group = nginx/g' /etc/php/7.0/fpm/pool.d/www.conf
`
When pairing NGINX with PHP-FPM, it’s possible to return to NGINX a .php URI that does not actually exist in the site’s directory structure. The PHP processor will process the URI, and execute the .php file, because its job is to process anything handed to it by NGINX. This of course presents a security problem.
It’s important limit what NGINX passes to PHP-FPM so malicious scripts can’t be injected into return streams to the server. Instead, the request is stopped, possibly then resulting in a 404. There are multiple ways to do this (see the NGINX wiki) but here we chose to specify the setting in PHP-FPM rather than in NGINX’s configuration.
`sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.0/fpm/php.ini`
You’ll notice that ;cgi.fix_pathinfo=1 is commented out by default. Setting it to 0 and uncommenting it will enforce the configuration should there be any upstream changes in the default value in the future.
Restart PHP-FPM to apply the changes:
`systemctl restart php7.0-fpm.service`
Configure the NGINX Server BlockPermalink
Again pulling from Part 1 of our NGINX series, we’ll start with a basic Server Block for a static HTTP page being served from /var/www/example.com. Replace example.com with your site’s domain or IP address, and the root directive with your site’s root directory.
`/etc/nginx/conf.d/example.com.conf
`server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
}
`
To the Server Block above, add a location block containing the PHP directives. You should then have:
/etc/nginx/conf.d/example.com.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
root /var/www/example.com;
index index.html;
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
This is just a bare minimum to get PHP-FPM working and you will want to configure it further for your specific needs. Some further points about the configuration above:
The location ~* \.php$ means that NGINX will apply this configuration to all .php files (file names are not case sensitive) in your site’s root directory, including any subdirectories containing PHP files.
The * in the ~* \.php$ location directive indicates that PHP file names are not case sensitive. This can be removed if you prefer to enforce letter case.
The fastcgi_pass location must match the listen = value in /etc/php/7.0/fpm/pool.d/www.conf. It is preferable for performance reasons for PHP-FPM to listen on a UNIX socket instead of a TCP address. Only change this if you require PHP-FPM use network connections.
Using $document_root in the SCRIPT_FILENAME parameter instead of an absolute path is preferred by NGINX’s documentation.
Here’s a variation of the location block above. This includes an if statement which disallows the FPM to process files in the /uploads/ directory. This is a security measure which prevents people from being able to upload .php files to your server or application which the FastCGI process manager would then execute.
This only applicable if you allow users to upload or submit files to your site. Change the name of the directory from uploads to whatever suits your need.
/etc/nginx/conf.d/example.com.conf
location ~* \.php$ {
if ($uri !~ "^/uploads/") {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
Reload NGINX:
nginx -s reload
I found the solution.
In my /etc/nginx/sites-enabled/my-site.conf had a line
upstream fastcgi_backend {
server 127.0.0.1:9000;
}
Nginx was configure without the
location ~* .php$
line.
So you don't have to change configuration every time you change php versions.
My problem was that I didn't checked that php-fpm7.0 was running at socket 9000.
The solution was to change in php.ini inside php-fpm7.2 to run at socket 9000
Conclusion : Ok so, now my configuration works, and I think the problem comes from the location of my project, in another user's directory. For some reasons, the either nginx or php-fpm is unhappy with it, and doesn't seem to work.
What's still bugging me is that it was a 404 error, not a 403.
Well, I don't think I will find the final answer.
I have read zillions of ways to do that, and unfortunately I don't understand what could go wrong.
server {
server_name onepage.cendrounet.com;
listen 80;
root /home/pag/workspace/test_css_platform;
location / {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Nginx is running.
# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
└─php-fpm.conf
Active: active (running) since Fri 2017-12-22 09:48:06 CET; 10h ago
Php-fpm is running :
# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2017-12-22 09:40:29 CET; 10h ago
Php-fpm is indeed an unix socket
# ls -l /var/run/php-fpm/www.sock
srw-rw----+ 1 root root 0 déc. 22 09:40 /var/run/php-fpm/www.sock
I am running fedora, but ausearch -m avc doesn't yield anything. (In case I don't understand how selinux works, setenforce 0 hasn't yielded any better resutls. But still, I returned it on.)
Furthermore, curl -i 'http://onepage.cendrounet.com' returns
HTTP/1.1 404 Not Found
Server: nginx/1.12.1
Date: Fri, 22 Dec 2017 19:11:49 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/7.1.12
Furthermore, my user nginx belongs to my group pag.
I have set my permissions like so :
# namei -om /home/pag/workspace/css_test_platform/index.php
f: /home/pag/workspace/css_test_platform/index.php
dr-xr-xr-x root root /
drwxr-xr-x root root home
drwxr-x--x pag pag pag
drwxr-xr-x pag pag workspace
drwxrwxr-x pag pag css_test_platform
-rw-rw-r-- pag pag index.php
The configuration of php-fpm is the default one, some details picked :
user = apache
group = apache
listen = /run/php-fpm/www.sock
listen.acl_users = apache,nginx
listen.allowed_clients = 127.0.0.1
Theorically, user and group should be for RPM stuff, but I still have given the pag group to apache.
What could cause a 404 error on my index ?
This was on Arch, but it is systemd related.
This solution is for use on a development machine, and for good reasons, you shouldn't run a public site from your /home folder.
I configured php-fpm and nginx to run as my user. Edit the following file, and remove the ProtectHome=true line
sudo vi /etc/systemd/system/multi-user.target.wants/php-fpm.service
Reload, and restart everything;
systemctl daemon-reload
systemctl restart nginx.service
systemctl restart php-fpm.service
You need to add try_files $uri /index.php; or similar in your location block:
location / {
try_files $uri /index.php;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
include fastcgi.conf;
}
On my vagrant box , centtos 7, i had installed php7.0.3 and nginx 1.9.12. the php config www.conf. this file in the /usr/local/php/etc/php-fpm.d/ directory, Its configuration like this
user = www
group = www
;listen = /tmp/php-fpm.sock
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
and the nginx config. the file vm.demo.com.conf in the /usr/local/nginx/conf/vhost/ directory. Its configuration like this
server {
listen 80;
server_name vm.demo.com;
index index.html index.htm index.php;
root /data/wwwroot/demo;
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
location ~ .*\.(php|php5)?$ {
#fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log logs/demo.log main;
}
in the nginx conf, if i use fastcgi_pass 127.0.0.1:9000 and the php-fpm.conf listen 127.0.0.1:9000, They are working properly
bug if i use the socket configuration:
php www.conf
user = www
group = www
listen = /tmp/php-fpm.sock
listen.owner = www
listen.group = www
nginx vm.demo.com.conf
location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
the nginx show 502 Bad gateway. in the nginx error.log show this.
2016/03/14 21:17:04 [crit] 4208#0: *5 connect() to unix:/tmp/php-fpm.sock failed (2: No such file or directory) while
connecting to upstream, client: 192.168.1.101, server: vm.demo.com, request: "GET /test.php HTTP/1.1",
upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "vm.demo.com"
2016/03/14 21:17:04 [crit] 4208#0: *5 connect() to unix:/tmp/php-fpm.sock failed (2: No such file or directory) while
connecting to upstream, client: 192.168.1.101, server: vm.demo.com, request: "GET /test.php HTTP/1.1",
upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "vm.demo.com"
2016/03/14 21:18:01 [crit] 4208#0: *5 connect() to unix:/tmp/php-fpm.sock failed (2: No such file or directory) while
connecting to upstream, client: 192.168.1.101, server: vm.demo.com, request: "GET /test.php HTTP/1.1",
upstream: "fastcgi://unix:/tmp/php-fpm.sock:", host: "vm.demo.com"
when i check the /tmp/php-fpm.sock file, it's existing
[root#vbox1 vhost]# ll /tmp/php-fpm.sock
srw-rw---- 1 www www 0 Mar 14 21:06 /tmp/php-fpm.sock
this are php and nginx running status:
[root#vbox1 vhost]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/etc/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-03-14 21:06:27 CST; 42min ago
Process: 4189 ExecStop=/bin/kill -SIGINT $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 4198 (php-fpm)
CGroup: /system.slice/php-fpm.service
├─4198 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
├─4199 php-fpm: pool www
└─4200 php-fpm: pool www
Mar 14 21:06:27 vbox1 systemd[1]: Started The PHP FastCGI Process Manager.
Mar 14 21:06:27 vbox1 systemd[1]: Starting The PHP FastCGI Process Manager...
[root#vbox1 vhost]# systemctl status nginx.service
● nginx.service - nginx
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-03-14 21:06:35 CST; 42min ago
Process: 4180 ExecStop=/usr/local/nginx/sbin/nginx -s quit (code=exited, status=0/SUCCESS)
Process: 4206 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 4207 (nginx)
CGroup: /system.slice/nginx.service
├─4207 nginx: master process /usr/local/nginx/sbin/nginx
├─4208 nginx: worker process
└─4209 nginx: worker process
Mar 14 21:06:35 vbox1 systemd[1]: Starting nginx...
Mar 14 21:06:35 vbox1 systemd[1]: Started nginx.
Can someone help me? If anyone encountered the same problem
I have met the same problem.
And I just change the socket path to another directory but '/tmp',
Then everything goes OK.
Basically, the problem arises with ONE process (php-fpm) setting up the sock in the /tmp path, but it would not be visible by ANOTHER process (nginx).
There is a setting in the service config, which would block files created by different process, even though using the same user.
Find your service config file (ex: /etc/systemd/system/myapp.service) and then on add this setting: PrivateTmp=No to both your services (php and nginx).
[Service]
...
PrivateTmp=No
more info about systemd units here:
https://www.freedesktop.org/software/systemd/man/systemd.unit.html
I have found a config (php5) that continues to use the unix socket and does not involve editing any other config files (except the nginx default site file).
location ~ \.php$ {
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
# \Add following to use sqlite as db.
fastcgi_param DB_CONNECTION sqlite;
}
Note:- the unix socket is not at /run/php/ (though it is for php7).
The include fastcgi_params; is required to prevent the php file downloading instead of being interpreted.
For completeness the following is my entire default file.
index index.php index.html index.htm;
server {
listen 80;
server_name sponk.co.uk;
rewrite_log on;
root /vagrant/public_html;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
fastcgi_pass unix:/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
You need to change the listen.owner and the listen.group
listen.owner = nginx
listen.group = nginx
In my case in this file: /etc/php-fpm.d/www.conf
The socket must be the same in you nginx block (like vhost in apache). I also moved the socket under /var/sockets
You could try changing user in /usr/local/php/etc/php-fpm.d/www.conf to nginx and restart service.
user = nginx
group = nginx
listen = /tmp/php-fpm.sock
For all those who use Homestead inside Vagrant:
I solved simply reloading vagrant with provision flag:
from project root:
cd Homestead
and then:
vagrant reload --provision
in this manner recompile all configurations
I had this problem, you can do this:
chmod 777 yourpath/php-fpm.sock
This worked for me.
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.