Where is php7.0-fpm.sock located - php

I have a simple project with directory structure
I am setting up nginx config for my drupal site, and for the fastcgi_pass I have been using 127.0.0.1:9000 but I want to use a unix socket as suggested in this conf:
# PHP 7 socket location.
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
but I can't find php/php7.0-fpm.sock;
I have the following path in my centos distro
/var/run/php-fpm/php-fpm.pid

Check the php-fpm config where the socket will be created with:
$ cat /etc/php/7.0/fpm/pool.d/www.conf
Look for listen, for example:
listen = /run/php/php7.0-fpm.sock
php-fpm creates the socket file after you started the process.
sudo service php7.0-fpm stop
sudo service php7.0-fpm start
Check the directory if socket file was created:
$ cd /run/php && ls -la

First check if php-fpm is running on your system, for doing this you could use pgrep for example:
# pgrep -fa php-fpm
5666 php-fpm: master process (/etc/php-fpm.conf)
5667 php-fpm: pool www
5668 php-fpm: pool www
5669 php-fpm: pool www
5670 php-fpm: pool www
5671 php-fpm: pool www
In this case, it shows is up and running and using the configuration file /etc/php-fpm.conf. Before checking the configuration file and trying to check for the listen = directive you could quickly look into /proc/net/unix for example:
# grep php /proc/net/unix
Which may return something like:
ffff8800bfb2f400: 00000002 00000000 00010000 0001 01 28561 /tmp/php-fpm.sock
In this case, it shows that the path for the php-fpm socket is located in /tmp/php-fpm.sock the one could be verified by checking the conf in /etc/php-fpm.d/www.conf in this case being: listen= /tmp/php-fpm.sock
In case you don't get any result and php-fpm is up and running, by checking the configuration you may find that is using the defaults by listing on a TCP socket:
listen = 127.0.0.1:9000
Something you could change to listen on a Unix socket like your suggested conf:
listen = /var/run/php/php7.0-fpm.sock
In some Linux distros normally this is used:
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
After modifying your configuration don't forget to restart the services systemctl restart php-fpm. To check that the socket has been created you could do:
$ file /var/run/php/php7.0-fpm.sock
If socket exists if should print out something like this:
/var/run/php/php7.0-fpm.sock: socket

you can see it by running
$ ss --unix |grep 'php'

It is likely that an older libpcre3 is installed and satisfies the dependency in the php7.0 package, but only the newer library package provides pcre_jit_stack_free.
If this is the case, do an apt-get install libpcre3, and you’re good to go.
Ref.: https://github.com/oerdnj/deb.sury.org/issues/372
I hope this helps you.

Use this:
cat /etc/php/7.0/fpm/pool.d/www.conf | grep 'listen ='
Output example: listen = /run/php/php7.2-fpm.sock
Or for universal php vesions:
cat /etc/php/$(php -r "echo PHP_VERSION;" | grep --only-matching --perl-regexp "7.\d+")/fpm/pool.d/www.conf | grep 'listen ='

Related

Missing /var/run/php-fpm/php7.4-fpm.sock or /var/run/php-fpm/

Using: Ubuntu 20.04
PHP starts failed because missing /var/run/php-fpm/php7.4-fpm.sock & /var/run/php-fpm/php7.4-fpm.pid.
Heres the details: (feedback from systemctl status php7.4-fpm.service)
● php-fpm7.4[3465899]:ERROR: unable to bind
listening socket for address '/var/run/php-fpm/php7.5-fpm.sock': No such
file or directory (2)
● php-fpm7.4[3465899]:ERROR: unable to bind
listening socket for address '/run/php-fpm/php7.5-fpm.pid': No such
file or directory (2)
I checked "/etc/php/7.4/fpm/pool.d/www.conf", but there is the following code in the file:
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php7.4-fpm.sock
Type in:
cd /run
sudo mkdir php
sudo mkdir php7.4-fpm
cd /etc/php/7.4/fpm/pool.d/
cp www.conf www.conf.backup
vi www.conf
Find following code:
line 36:
listen = /run/php/php7.4-fpm.sock
change it to:
listen = 127.0.0.1:9000
line 133:
listen = /var/run/php-fpm/php7.4-fpm.sock
Remove that line, save that file, and type in:
sudo service php7.4-fpm stop
sudo service php7.4-fpm start
Thanks:
#tkausl
#dai007uk

Starting supervisor programs as another user

I have a docker (php:7-fpm-alpine) container with supervisor installed. It is added to a default installation by:
RUN apk add nginx composer php7-fpm php7-session supervisor && \
... ... ...
cp supervisord.conf /etc/supervisor.d/conf.ini
Supervisor has its default config (didn't change it after installation), I have added my own config to append to it (supervisord.conf):
[program:php-fpm7]
command = /usr/sbin/php-fpm7 --nodaemonize --fpm-config /etc/php7/php-fpm.d/www.conf
autostart=true
autorestart=true
priority=5
stdout_logfile=/var/log/supervisor/php-fpm.log
stderr_logfile=/var/log/supervisor/php-fpm.error.log
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
priority=10
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx.error.log
Now the original issue I have is that my Laravel app can't write to storage folder. I could chmod 777 the folder recursively, and it works, but is not what I want.
So steps I took first is to chown -R nginx:nginx /var/www/* leaving permissions as is. This resolved nothing, still can't write.
Doing a ps aux revealed this:
PID USER TIME COMMAND
1 root 0:00 {supervisord} /usr/bin/python2 /usr/bin/supervisord --nodaemon --configuration /etc/supervisord.conf
8 root 0:00 {php-fpm7} php-fpm: master process (/etc/php7/php-fpm.d/www.conf)
9 root 0:00 nginx: master process /usr/sbin/nginx -g daemon off;
10 nginx 0:00 nginx: worker process
11 nginx 0:00 nginx: worker process
12 nginx 0:00 nginx: worker process
13 nginx 0:00 nginx: worker process
14 nginx 0:00 {php-fpm7} php-fpm: pool www
15 nginx 0:00 {php-fpm7} php-fpm: pool www
So php-fpm is running as nginx user (I've changed it's original config to replace user nobody to nginx). This did nothing good, as with this settings instead of nobody user, request returns 502 error.
Nginx master process is running as root, and worker processes as nginx.
This is a tad confusing as I am not sure which user is my web server using here? Root or nginx? Does it take the user from supervisor, nginx master or nginx worker?
I've tried changing supervisor to start as nginx user, but that fails as supervisor needs root access to create pid.
Reverting supervisor to root and adding user=nginx to [program:nginx] section made supervisor not start nginx at all.
How can I do the permissions here the right way?
I think the best you can do , is to run both nginx and php-fpm as www-data:www-data
step one
add/edit this to your nginx.conf:
user www-data www-data;
step two
add/edit php-fpm.conf and set user and group to www-data more info here
I hope that will help you

48)Address already in use: AH00072: make_sock: could not bind to address [::]:80

I get a apache error when I try access to anything folder or file, it returns Http Not found or Forbidden
I am trying restart and start apache
sudo apachectl restart
output:
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
I am trying stop it
sudo apachectl stop
output
httpd (no pid file) not running
I run sudo lsof -i:80
output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 8904 root 5u IPv6 0x21884d81f1597d8f 0t0 TCP *:http (LISTEN)
httpd 9012 _www 5u IPv6 0x21884d81f1597d8f 0t0 TCP *:http (LISTEN)
httpd 12726 _www 5u IPv6 0x21884d81f1597d8f 0t0 TCP *:http (LISTEN)
httpd 12731 _www 5u IPv6 0x21884d81f1597d8f 0t0 TCP *:http (LISTEN)
httpd 12732 _www 5u IPv6 0x21884d81f1597d8f 0t0 TCP *:http (LISTEN)
Any idea to solve that ?
Useful information:
OS X El Capitan
In my Mac with Mojave (10.14.1) suddenly Apache couldn't give to serve ipv4 anymore, then gave me ERROR 403. I tried to kill all apache (sudo killall httpd)... checking de PID's on (sudo lsof | grep AMP | grep apache)... even didn't work... just ipv6 was available... still ERROR 403.
What works for me: Disable OSX's built-in Apache server.
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
After that:
sudo apachectl -k restart
Be happy :)
This one helped me:
Please edit httpd.conf file.
/usr/local/etc/httpd/httpd.conf
And replace
Listen 80
with
Listen 127.0.0.1:80
Restart apache
sudo apachectl -k restart
One of a couple of things could be happening:
You have a different version of apache running. You can make sure that you're using the correct one by running which apachectl. As an example, I also have two versions of apache /usr/sbin/apachectl and /usr/local/bin/apachectl
You're not running apachectl start as root, although it appears that you are.
You can run sudo lsof -i:80 to see what's binding that port currently
Try
sudo netstat -ltnp | grep ':80'
Output: tcp6 0 0 :::80 :::* LISTEN 1500/apache2
sudo kill 1500
sudo service apache2 restart
this error ocurs because apache server listen by deafult in port 80 so another service or program is using that port and apache canot start.
The solution is identify what program or service is using that port an then close, disable or unistall it.
to identify you can run netstat
sudo netstat -ltnp | grep ':80'
or
sudo lsof -i:80
in my case i have installed nginx and apache at the same time and both uses the port 80.
Temporary Solution: Stop or kill the service, program, etc.
Permanent Solution:
Change the port of apache server in config file
/etc/apache2/apache2.conf
Uninstall the service or program that uses port 80.
in my case I needed both so I decided to temporarily fix it by disabling the service with:
systemctl stop MyServiceName.service
If it is a service otherwise use kill command.
I had my configuration set up this way before as well, and ran into the same problem after I upgraded OSX this last time. I tried to find ANYTHING that was listening on either port 80 or 443 and couldn't find a thing anywhere. It took me a while but finally found another article that described a fix that actually worked. Keep in mind I'm using a homebrew install and have unloaded the default apache2 install that comes with Mac OSX.
Here's what I had before in my httpd.conf:
Listen 80
and I had something similar in ssl.conf
Listen 443 https
I had to alter my httpd.conf file to use a ServerName of localhost and Listen on 0.0.0.0:80, and same for ssl.conf but 0.0.0.0:443 https
httpd.conf:
ServerName localhost
Listen 0.0.0.0:80
and ssl.conf
Listen 0.0.0.0:443 https
Once I tried starting it again, everything was happy. Hope that helps! I would link to the article but I'm having trouble finding it again!
Well, it looks as if httpd is already running. To check run
lsof -i TCP:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 281 root 3u IPv6 19479 0t0 TCP *:80 (LISTEN)
....
So kill httpd and do what you want
If you've recently done a software update and you renamed or removed any of the default files in /etc/httpd/conf.d/ go have a look there. You might have duplicate directives because the package manager re-installed them.
In my case, I prefixed the files with numbers so I could control the load order... but an OS update re-installed the original files so
I had two files with "Listen 443" in them which conflicted and wasn't caught by the syntax check. Removing the os files fixed the issue.
(This time I left them but made them empty so the conflict will be displayed on re-install or update)

How to find my php-fpm.sock?

I'm running Wordpress with: Nginx + PHP-FPM + APC + W3 Total Cache + PageSpeed.
After 3 days researching and configuring, I succeeded to make it work.
I configured PHP-FPM to run via 127.0.0.1:9000. But now I want to configure via Socket.
The problem is that I can't find the socket path in my server. I just found /var/run/php-fpm/php-fpm.pid, but php-fpm.sock was not there.
Running whereis php-fpm the output is:
php-fpm: /usr/sbin/php-fpm /etc/php-fpm.d /etc/php-fpm.conf /usr/share/man/man8/php-fpm.8.gz
But there isn't any php-fpm.sock there.
How can I find php-fpm.sock?
My specs:
Amazon Micro EC2
Linux version 3.4.48-45.46.amzn1.x86_64 Red Hat 4.6.3-2 (I think it's based on CentOS 5)
PHP 5.3.26 (fpm-fcgi)
I know this is old questions but since I too have the same problem just now and found out the answer, thought I might share it. The problem was due to configuration at pool.d/ directory.
Open
/etc/php5/fpm/pool.d/www.conf
find
listen = 127.0.0.1:9000
change to
listen = /var/run/php5-fpm.sock
Restart both nginx and php5-fpm service afterwards and check if php5-fpm.sock already created.
I faced this same issue on CentOS 7 years later
Posting hoping that it may help others...
Steps:
FIRST, configure the php-fpm settings:
-> systemctl stop php-fpm.service
-> cd /etc/php-fpm.d
-> ls -hal (should see a www.conf file)
-> cp www.conf www.conf.backup (back file up just in case)
-> vi www.conf
-> :/listen = (to get to the line we need to change)
-> i (to enter VI's text insertion mode)
-> change from listen = 127.0.0.1:9000 TO listen = /var/run/php-fpm/php-fpm.sock
-> Esc then :/listen.owner (to find it) then i (to change)
-> UNCOMMENT the listen.owner = nobody AND listen.group = nobody lines
-> Hit Esc then type :/user = then i
-> change user = apache TO user = nginx
-> AND change group = apache TO group = nginx
-> Hit Esc then :wq (to save and quit)
-> systemctl start php-fpm.service (now you will have a php-fpm.sock file)
SECOND, you configure your server {} block in your /etc/nginx/nginx.conf file. Then run:systemctl restart nginx.service
FINALLY, create a new .php file in your /usr/share/nginx/html directory for your Nginx server to serve up via the internet browser as a test.
-> vi /usr/share/nginx/html/mytest.php
-> type o
-> <?php echo date("Y/m/d-l"); ?> (PHP page will print date and day in browser)
-> Hit Esc
-> type :wq (to save and quite VI editor)
-> open up a browser and go to: http://yourDomainOrIPAddress/mytest.php
(you should see the date and day printed)
Check the config file, the config path is /etc/php5/fpm/pool.d/www.conf, there you'll find the path by config and if you want you can change it.
EDIT:
well you're correct, you need to replace listen = 127.0.0.1:9000 to listen = /var/run/php5-fpm/php5-fpm.sock, then you need to run sudo service php5-fpm restart, and make sure it says that it restarted correctly, if not then make sure that /var/run/ has a folder called php5-fpm, or make it listen to /var/run/php5-fpm.sock cause i don't think the folder inside /var/run is created automatically, i remember i had to edit the start up script to create that folder, otherwise even if you mkdir /var/run/php5-fpm after restart that folder will disappear and the service starting will fail.
Solved in my case, i look at
sudo tail -f /var/log/nginx/error.log
and error is php5-fpm.sock not found
I look at sudo ls -lah /var/run/
there was no php5-fpm.sock
I edit the www.conf
 
sudo vim /etc/php5/fpm/pool.d/www.conf
change
listen = 127.0.0.1:9000
for
listen = /var/run/php5-fpm.sock
and reboot
When you look up your php-fpm.conf
example location:
cat /usr/src/php/sapi/fpm/php-fpm.conf
you will see, that you need to configure the PHP FastCGI Process Manager to actually use Unix sockets. Per default, the listen directive` is set up to listen on a TCP socket on one port. If there's no Unix socket defined, you won't find a Unix socket file.
; 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 IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all IPv4 addresses on a
; specific port;
; '[::]:port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
I encounter this issue when I first run LEMP on centos7 refer to this post.
I restart nginx to test the phpinfo page, but get this
http://xxx.xxx.xxx.xxx/info.php is not unreachable now.
Then I use tail -f /var/log/nginx/error.log to see more info. I find is the
php-fpm.sock file not exist. Then I reboot the system, everything is OK.
Here may not need to reboot the system as Fath's post, just reload nginx and php-fpm.
restart php-fpm
reload nginx config

nginx 502 bad gateway

I get a 502 Bad Gateway with nginx when using spawn fcgi to spawn php5-cgi.
I use this to span an instance on server start using the following line in rc.local
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
presumably I'm getting the error because the spawn-fcgi / php5-cgi dies and there is nothing listening there anymore to parse php.
I get nothing in the logs that I can see anywhere, I'm out of ideas (and new to this setup with nginx)
I executed my localhost and the page displayed the 502 bad gateway message. This helped me:
Edit /etc/php5/fpm/pool.d/www.conf
Change listen = /var/run/php5-fpm.sock to listen = 127.0.0.1:9000
Ensure the location is set properly in nginx.conf.
Run sudo service php5-fpm restart
Maybe it will help you.
Source from: http://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm
The 502 error appears because nginx cannot hand off to php5-cgi. You can try reconfiguring php5-cgi to use unix sockets as opposed to tcp .. then adjust the server config to point to the socket instead of the tcp ...
ps auxww | grep php5-cgi #-- is the process running?
netstat -an | grep 9000 # is the port open?
Go to /etc/php5/fpm/pool.d/www.conf and if you are using sockets or this line is uncommented
listen = /var/run/php5-fpm.sock
Set couple of other values too:-
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Don't forget to restart php-fpm and nginx. Make sure you are using the same nginx owner and group name.
You have to match the settings for PHP-FPM and Nginx to communicate over sockets or TCP.
So go to /etc/php5/fpm/pool.d/www.conf and look for this line:
listen = /var/run/php5-fpm.sock
Then go to /etc/nginx/nginx.conf
Look for this:
upstream php {
server unix:/var/run/php5-fpm.socket;
}
Match those values and you should be all set.
If running a linux server, make sure that your IPTABLES configuration is correct.
Execute sudo iptables -L -n , you will recieve a listing of your open ports. If there is not an Iptables Rule to open the port serving the fcgi script you will receive a 502 error. The Iptables Rule which opens the correct port must be listed before any rule which categorically rejects all packets (i.e. a rule of the form "REJECT ALL -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable or similar)
On my configuration, to properly open the port, I had to execute this command (assume my fcgi server is running at port 4567):
sudo iptables -I INPUT 1 -p tcp --dport 4567 -j ACCEPT
WARNING: This will open port 4567 to the whole world.
So it might be better to do something like this:
sudo iptables-save >> backup.iptables
sudo iptables -D INPUT 1 #Delete the previously entered rule
sudo iptables -I INPUT 1 -p tcp --dport 8080 -s localhost -j ACCEPT # Add new rule
Doing this removed the 502 error for me.
change
fastcgi_pass unix:/var/run/php-fpm.sock;
to
fastcgi_pass unix:/var/run/php5-fpm.sock;
When I did sudo /etc/init.d/php-fpm start I got the following error:
Starting php-fpm: [28-Mar-2013 16:18:16] ERROR: [pool www] cannot get uid for user 'apache'
I guess /etc/php-fpm.d/www.conf needs to know the user that the webserver is running as and assumes it's apache when, for nginx, it's actually nginx, and needs to be changed.
You can make nginx ignore client aborts using:
location / {
proxy_ignore_client_abort on;
}
I had the same problem while setting up an Ubuntu server. Turns out I was having the problem due to incorrect permissions on socket file.
If you are having the problem due to a permission problem, you can uncomment the following lines from: /etc/php5/fpm/pool.d/www.conf
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Alternatively, although I wouldn't recommend, you can give read and write permissions to all groups by using the following command.
sudo chmod go+rw /var/run/php5-fpm.sock
Try disabling the xcache or apc modules. Seems to cause a problem with some versions are saving objects to a session variable.
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 a 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/
If you're on Ubuntu, and all of the above has failed you, AppArmor is most likely to blame.
Here is a good guide how to fix it: https://www.digitalocean.com/community/tutorials/how-to-create-an-apparmor-profile-for-nginx-on-ubuntu-14-04
Long story short:
vi /etc/apparmor.d/nginx
Or
sudo aa-complain nginx
sudo service nginx restart
See everything working nicely... then
sudo aa-logprof
I still had problems with Nginx not being able to read error.log, even though it had all the permissions possible, including in Apparomor. I'm guessing it's got something to do with the order of the entries, or some interaction with Passenger or PHP-Fpm... I've run out of time to troubleshoot this and have gone back to Apache for now. (Apache performs much better too FYI.)
AppArmor just lets Nginx do whatever it wants if you just remove the profile:
rm /etc/apparmor.d/nginx
service apparmor reload
Shockingly, but hardly surprising, a lot of posts on fixing Nginx errors resorts to completely disabling SELinux or removing AppArmor. That's a bad idea because you lose protection from a whole lot of software. Just removing the Nginx profile is a better way to troubleshoot your config files. Once you know that the problem isn't in your Nginx config files, you can take the time to create a proper AppArmor profile.
Without an AppArmor profile, especially if you run something like Passenger too, I give your server about a month to get backdoored.
For me the error was in default file of Nginx
located at /etc/nginx/sites-available/default
I noticed the version of php-fpm used was 7.0 and the php version i downloaded was 7.2
I simply changed the version to 7.2 and it worked.
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
Similar setup here and looks like it was just a bug in my code. At the start of my app I looked for the offending URL and this worked: echo '<html>test</html>'; exit();
In my case, turns out the problem was an uninitialized variable that only failed under peculiar circumstances.

Categories