I am in the middle of setting up a FreeBSD system1 with nginx (v1.24.0) and php (v5.6 2), that uses php-fpm to communicate between nginx and php.

Because of the age of php v5.6, I had to build it from scratch as there was no suitable pre-built package (and I built it with the php-fpm option). I got the source code from:


And because I built it from scratch I had to manually install the init files for php-fpm, but I am missing something as while I can manually start the php-fpm service (and have nginx successfully serve up a php based file), I am missing the magic that automatically starts that service when the system starts.

Thus I have these executable script files:


And /etc/rc.conf contains:


While the nginx service starts automatically, I have to manually start the php-fpm service via something like:

service php-fpm start

When I ask for a list of services using:

service -e

It lists the nginx service, but does not list the php-fpm service.

In checking the service documentation. it says:

-e  List services that are enabled.  The list of scripts to check is
    compiled using  rcorder(8) the same way that it is done in rc(8),
    then that list of scripts is checked for an "rcvar" assignment.  If
    present the script is checked to see if it is enabled.

Thus to me it seems that while I have the init file in the correct location, I am missing whatever rcorder uses to identify an actual service.

What do I need to change to tell FreeBSD that php-fpm is a service that needs to automatically start on reboot?

Update #1

In comparing the the nginx script to the php-fpm script, I noticed that the nginx scripts has

. /etc/rc.subr

And that the service docs refer to the rcvar assignment. So I added this to my php-fpm script:

. /etc/rc.subr

But after rebooting, service -e still does not recognize php-fpm as a service to start.

Update #2

After questions from Richard, I saw that my nginx script has:

# PROVIDE: nginx
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

But my original php-fpm script has:

# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon

I deleted this INIT INFO block and replaced it with:

# PROVIDE: php-fpm
# REQUIRE: nginx

And now, when I run service -e, it reports the php-fpm script is enabled. However, when I reboot the system, that service still doesn't start automatically.

1. Actually a FreeBSD jail running on the latest TrueNAS Core 13

2. Yes I know, v5.6 is very old. I'm trying to stabilize a system on a new platform before actually upgrading it

  • @RichardSmith That is literally in the 3rd paragraph of my question. And without that script I couldn't manually start the service.
    – Peter M
    Commented Feb 25 at 18:27
  • Is the script executable? Is the x bit set? Commented Feb 25 at 18:29
  • 1
    @D'ArcyNader The current version uses the same naming convention. I suspect that hyphens cannot be used in shell variables. Commented Feb 25 at 20:09
  • 2
    @PeterM My only suggestion would be to grab FreeBSD's rc.script from cgit.freebsd.org/ports/tree/lang/php83/files/php-fpm.in and adapt it for the earlier version. Commented Feb 25 at 20:14
  • 1
    @RichardSmith I thought of something similar just now. I was going to spin up another system and install php from a freebsd package and see what turns up. I'll probably end up answering my own question.
    – Peter M
    Commented Feb 25 at 20:24

1 Answer 1


Based on Richard's comment, I looked at https://cgit.freebsd.org/ports/tree/lang/php83/files/php-fpm.in

This file matches the style of what I am seeing in the nginx service control script.

Nginx (partial):


# PROVIDE: nginx
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable nginx:
# nginx_enable (bool):      Set to "NO" by default.
#               Set it to "YES" to enable nginx
# nginx_profiles (str):     Set to "" by default.
#               Define your profiles here.
# nginx_pid_prefix (str):   Set to "" by default.
#               When using profiles manually assign value to "nginx_"
#               for prevent collision with other PIDs names.
# nginxlimits_enable (bool):    Set to "NO" by default.
#               Set it to yes to run `limits $limits_args`
#               just before nginx starts.
# nginx_reload_quiet (bool):    Set to "NO" by default.
#               Set it to yes to suppress info output when testng config.
# nginx_flags (str):        Set to "" by default.
#               Extra flags passed to start command.
# nginxlimits_args (str):   Default to "-e -U www"
#               Arguments of pre-start limits run.
# nginx_http_accept_enable (bool): Set to "NO" by default.
#               Set to yes to check for accf_http kernel module
#               on start-up and load if not loaded.
# nginx_sig_stop (str):     Default to "TERM"

. /etc/rc.subr


extra_commands="reload configtest upgrade gracefulstop"

php-fpm (partial):


# PROVIDE: php-fpm
# KEYWORD: shutdown

# Add the following line to /etc/rc.conf to enable php-fpm:
# php-fpm_enable (bool):        Set to "NO" by default.
#                               Set it to "YES" to enable nginx
# php-fpm_profiles (str):       Set to "" by default.
#                               Define your profiles here.
# php_fpm_pid_prefix (str):     Set to "" by default.
#                               When using profiles manually assign value to "php_fpm_"
#                               for prevent collision with other PIDs names.

. /etc/rc.subr



load_rc_config "${name}"

When I copied this file to my system (and replaced %%PREFIX%% with absolute paths - just because), service -e reported the php-fpm as enabled.

After a reboot, the php-fpm service was running:

# ps -aux
root  53435  0.0  0.0  26876  10016  -  SsJ  09:33   0:00.01 php-fpm: master process (/usr/local/etc/php-fpm.conf) (php-fpm)
www   53436  0.0  0.0  26876  10224  -  IJ   09:33   0:00.00 php-fpm: pool www (php-fpm)
www   53437  0.0  0.0  26876  10024  -  IJ   09:33   0:00.00 php-fpm: pool www (php-fpm)

And I can access a php based file from nginx immediately after a reboot.

However, to add to the confusion when checking the status of the service:

# service php-fpm status
php_fpm is not running.

I just checked, and it seems that the status of a service depends on there being a pid file located at:


But this doesn't exist on my system. As pointed by another comment from Richard, for php-fpm, the location of this file needs to be defined in php-fpm.conf (even though it is already defined in the php-fpm service script file, and nginx only defines it in its service script file and not in nginx.conf).

When I added this to php-fpm.conf:

pid = /var/run/php-fpm.pid

Then checking the status of the php-fpm service works correctly.

I can only assume that the difference in functionality between php-fpm and nginx has to do with the details in their service control scripts. Analyzing this difference is beyond the scope of this question.

  • Check the /usr/local/etc/php-fpm.conf file and make sure you have pointed the pid file location to the same place that FreeBSD expects to see it. Commented Feb 26 at 20:33
  • Also, add rc_debug='yes' to your /etc/rc.conf and examine the debugging output closely to ensure the PID file is indeed getting created in the location you're asking that it be placed.
    – Jim L.
    Commented Feb 26 at 20:50
  • @RichardSmith The pid entry in php-fpm.conf is commented out. I also did a find / -name "*.pid" and nothing for php-fpm shows up.
    – Peter M
    Commented Feb 27 at 0:13
  • @JimL. I set that flag, but no errors are showing up. And there is no php-fpm.pid file anywhere (and I output 'pidfile' in the php-fpm service script and it thinks that it should be in /var/run/php-fpm.pid)
    – Peter M
    Commented Feb 27 at 1:03
  • On both v7.4 and v8.3 the php-fpm.conf file contains a [global] section with pid = run/php-fpm.pid (and it's not commented out). php-fpm is responsible for creating the pidfile, if the line is commented out, the pidfile will not be created. Commented Feb 27 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .