1 (edited by Wolf 2014-11-05 16:13:29)

Topic: Problems with php-fpm.service

Hi!

I have installed php-fpm via the Remi RPM on CentOS 7 and everything works fine
as long as I only start it by running:

[#] systemctl start php-fpm.service

[#] netstat -tulnp | grep 9000
tcp        0      0 127-0-0-1:9000          0.0.0.0:*               LISTEN      3541/php-fpm: maste

I then stop the system:
[#] systemctl stop php-fpm.service
[#] netstat -tulnp | grep 9000
            (empty)

I now change the port number of the default pool: "w w w pool" from 9000 to 9001
(but the same would happen if I let the default pool connect to port 9000 and
add other pools that listen to ports: 9001, 9002 etc.)


[#] vi  /etc/php-fpm.d/www.conf

Changing line from:
listen = 127-0-0-1:9000
Change to:
listen = 127-0-0-1:9001

Reloading daemon:
[#] systemctl daemon-reload

Then starting php-fpm.service again:
[#] systemctl start php-fpm.service

Startup fails, and I run the following to see the reason:
[#] systemctl status php-fpm.service

    Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled)
    Active: failed (Result: exit-code) since on. 2014-11-05 16:10:27 CET; 10s ago
    Process: 2943 ExecStart=/usr/sbin/php-fpm --nodaemonize (code=exited, status=78)
....
nov. 05 16:10:27 my.localdomain php-fpm[2943]: [05-Nov-2014 16:10:27] ERROR: unable to bind listening socket for address '127.0.0.1:...ed (13)

If I start php-fmp directly without going via the php-fmp.service I have no problem though:
[#] /usr/sbin/php-fpm --daemonize
[#] netstat -tulnp | grep 9001
tcp        0      0 127.0.0.1:9001          0.0.0.0:*               LISTEN      3591/php-fpm: maste

So php-fmp can listen to the port, but it won't allow me to do it when going via the php-fmp.service.

I have even commented out and changed the following in /usr/lib/systemd/system/php-fpm.service

# EnvironmentFile=/etc/sysconfig/php-fpm
# ExecStart=/usr/sbin/php-fpm --nodaemonize
ExecStart=/usr/sbin/php-fpm --daemonize

BUT the service won't start:
[#] systemctl start php-fpm.service
[#] systemctl -l status php-fpm.service

     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled)
     Active: failed (Result: exit-code) since on. 2014-11-05 16:53:54 CET; 1min 7s ago
     Process: 2795 ExecStart=/usr/sbin/php-fpm --daemonize (code=exited, status=70)
...
nov. 05 16:53:54 my.localdomain php-fpm[2795]: [05-Nov-2014 16:53:54] ERROR: unable to bind listening socket for address '127.0.0.1:9001': Permission denied (13)
...

I have searched pretty much everywhere, and I still can't find any info on why I have problems using other ports than the default: 9000 when using the php-fpm.service, when using the /usr/sbin/php-fpm command directly works without problems.

Thanks for any input! :-)

Wolf

Re: Problems with php-fpm.service

Is SELinux enabled ?

If yes, try to temporary disable it to confirm (and look to audit.log, for more information about AVC)
IIRC, used port need to be set as http_port_t

semanage port -a -t http_port_t -p tcp 9001

P.S. I think I also remember I avoid using 9001 (which have some specific context, but usually prefer 9002 and up, see this old article)

Laptop:  Fedora 38 + rpmfusion + remi (SCL only)
x86_64 builder: Fedora 39 + rpmfusion + remi-test
aarch64 builder: RHEL 9 with EPEL
Hosting Server: CentOS 8 Stream with EPEL, rpmfusion, remi