Solved Error : unable to bind listening socket for address '127.0.0.1:9000' : address already in use.

Hello.

I'm reinstalling Apache, PHP, MySQL and phpMyAdmin on my FreeBSD 13R-p8. The error that Im getting is the following :

Error : unable to bind listening socket for address '127.0.0.1:9000' : address already in use.
Error : FPM initialization failed.


I think that it is due to a bad configuration of the module php-fpm. I have tried to reconfigure the conf file below from :

Code:
nano /usr/local/etc/php-fpm.d/www.conf

listen = 127.0.0.1:9000

nano /usr/local/etc/php-fpm.d/www.conf.default

listen = 127.0.0.1:9000

to :

Code:
nano /usr/local/etc/php-fpm.d/www.conf

listen = 0.0.0.0:9000

nano /usr/local/etc/php-fpm.d/www.conf.default

listen = 0.0.0.0:9000

and I've opened port 9000 on my router,but it didn't work. It means that I still see the error on the boot screen messages,even if php-fpm seems to work ok :

Code:
# service php-fpm status
php_fpm is running as pid 5305.

Anyway,I would like to remove the error from the boot messages.
 
Check this. I don't see any error if I stop and restart php-fpm when the system is running,but I see the error during the boot.

Code:
# service php-fpm stop
Stopping php_fpm.
Waiting for PIDS: 5305.


# service php-fpm start
Performing sanity check on php-fpm configuration:
[02-Apr-2022 00:45:40] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful

Starting php_fpm.

# netstat | grep 9000
NO OUTPUT HERE.
 
That fpm port (9000) is not meant to be made public.

How it works is that Apache should be configured to not use the older CGI or mod_php plugins but instead use the fastcgi stuff. This works by offloading the .php processing to whatever fpm service is listening on that port.

If you make it public, anyone could run arbitrary malicious PHP script on your server, so do try to close that as soon as possible (and also only listen on 127.0.0.1:9000 instead).

Have a read through here and perhaps adapt it for your needs: https://dev.to/joetancy/php-fpm-with-apache2-2mk0

(Personally, unless you are dealing with seriously high volume (and so may need to compromise on security), you might want to consider standard cgi (i.e slowcgi). Separate processes for each php-cgi is actually a *feature* rather than a performance hindrance. Unless of course the php-fpm is (pre-)forked in which case you are probably OK)
 
I've found the reason of this error. It is that inside this folder : /usr/local/etc/rc.d/; there are a lot of *.pkgsave files. One of these,is : php-fpm.pkgsave ; I see that they are executable files, even if they don't seem. I've removed every file of this type and all problems are gone.
 
Back
Top