php7 - php-fpm sock not found after configure - php

I try to install php7 on Debian 8.
I would like configure php-fpm with a socket insteed of a port number.
I have enable --enable-socketsduring php configure. But I have no socket.
How I can found this socket and install it ?

To use a socket instead of a port number, you change your php-fpm configuration file, specifically the following pool directive
listen string: The address on which to accept FastCGI requests. Valid syntaxes are: 'ip.add.re.ss:port', 'port', '/path/to/unix/socket'. This option is mandatory for each pool.
In other words, set this to something like /var/run/fpm.sock.
Make sure that this socket is the same socket your webserver is using, for example in Nginx you will have a config entry like this:
fastcgi_pass unix:/var/run/fpm.sock;
If this doesn't match your listen directive, fpm will not respond to requests by your webserver.
Refer to this article for more information:
https://serversforhackers.com/video/php-fpm-configuration-the-listen-directive

Related

Use Xdebug with dockerized PHP project

Recently I've started to work on a new project that is dockerized and has Xdebug module. Also I've checked in container itself and 9000 port is listening and has Xdebug module version 2.9.8
I don't have any PHP or anything installed on my Ubuntu (host system).
In my PhpStorm I set my PHP interpreter manually:
Also set DBGp proxy like
Also created a server:
This is my etc/hosts:
and I call API in Postman with the following address: api.vendet.local/api/v1/test
UPDATED path mapping:
Still not break in any point. What is the problem and how can I do that?
I've checked in container itself and 9000 port is listening
It is IDE that should be listening on port 9000, not the container.
#1: you don't need to use DBGp proxy.
#2: at PHP | Servers you have to enable "Use path mappings".
If I were you, I would delete all the configuration you made in PhpStorm (#1 & #2) and would start from the scratch.
First: make sure to configure XDebug properly in a container, see Configure Xdebug running in a Docker container. Pay attention to the value of xdebug.client_host described in the article.
Then: just run a simple Zero-configuration debugging
Be aware that as long as you are not using network_mode: "host" for the php container localhost / 127.0.0.1 for Xdebug running within the container is not the same as localhost on your Ubuntu host!
To be able to connect to Xdebug from PHPStorm you need to ensure the following:
the debugger is listening on an IP reachable from the host: listening on 127.0.0.1 it would only be accessible from within the container itself. Connecting to 127.0.0.1:9000 on the host will be forwarded to the container, but to the virtual network interface of the container and not to the loopback device. To simply listen on all devices within the container specify 0.0.0.0 as address
path mappings are enabled - since (most probably) the paths of the PHP files within the container are not identical with the paths to the same files on the host.

How php-fpm container communicates with nginx on host?

I have installed nginx, php and php-fpm on server and my website is working fine. I am trying to containerise only php files. It should be in a way that nginx should stop communicating with my host php and nginx should connect to php-fpm container and my website should work fine. I need to communicate them via TCP.
I am using php:7.1-fpm as base image and copying all php files in Dockerfile.
my questions is
what will be the "listen" value in php-fpm pool configuration for the container?
If both are in the same server, the listen value will be 127.0.0.1:9000. but it’s not the case here.
I know that the "listen" value in php-fpm pool configuration and "fastcgi_pass" in the nginx configuration should be the same.
Here the nginx is in the host and php-fpm is a container. I tried to use X.X.X.X:9000 (X.X.X.X is the ip of host) but i am getting errors like
ERROR: failed to post process the configuration
ERROR: FPM initialization failed
can anyone help me

Webserver not listening to ports

Problem
I've recently found out that PHP has a built-in webserver which can be used for development purposes. Starting the server with the address "127.0.0.1" and the port "8080" works without any problems and my requests are handled properly. However, if I dare to use the address "localhost" with the same port, the webserver doesn't handle any requests.
Specs
Windows 10 64-Bit
Php 64-Bit Thread-Safe installed
MongoDB installed (Not running)
IIS Server installed and running
MariaDB installed (Not running)
Name resolution for localhost is handled by your DNS server which is likely resolving it to the IPv6 address ::1.
If you run:
php -S 127.0.0.1:8080
The webserver is running on the IPv4 address but localhost resolves to the IPv6 address.
So you can either use 127.0.0.1:8080 in the browser address bar.
Or force the address by un-commenting the following line from C:\Windows\System32\drivers\etc\hosts:
# 127.0.0.1 localhost
Or bind the webserver to the IPv6 address (this is what I do):
php -S localhost:8080

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

Using php5-fpm and nginx in a debian machine

I am trying to set up nginx server to run a php app in debian. I followed this tutorial among others. Most seems the same. My recent configuration is based on the link above. When I try to run this php script,
<?php
phpinfo();
?>
I get the same output on the browser instead of php info result. Kindly someone help me figure out where I went wrong.
Note: My error logs are clean,contains details on nginx server start only.
Thank you.
You might want to make sure php5-fpm is listening on the correct port you're expecting it to be using. Do a netstat listing and see if php-fpm is listening on port 9000:
netstat -tulpn
You should see a line that looks something like this:
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2390/php-fpm.conf
If not, check your www.conf file (in /etc/php5/fpm/pool.d/www.conf) and look for the "listen = ..." line and make sure it says:
listen = 127.0.0.1:9000
I have seen default configurations of php5-fpm use a socket instead of a tcp port.

Categories