2 title: Socket Activation with Popular Daemons
3 category: Manuals and Documentation for Users and Administrators
5 SPDX-License-Identifier: LGPL-2.1-or-later
10 nginx includes an undocumented, internal socket-passing mechanism based on the `NGINX` environmental variable. It uses this to perform reloads without having to close and reopen its sockets, but it's also useful for socket activation.
12 **/etc/nginx/my-nginx.conf**
17 listen [::]:80 ipv6only=on;
23 **/etc/systemd/system/my-nginx.service**
29 Environment=NGINX=3:4;
30 ExecStart=/usr/sbin/nginx -c/etc/nginx/my-nginx.conf
35 **/etc/systemd/system/my-nginx.socket**
40 Requires=network.target
44 ListenStream=0.0.0.0:80
45 BindIPv6Only=ipv6-only
48 WantedBy=sockets.target
54 Like nginx, PHP-FPM includes a socket-passing mechanism an environmental variable. In PHP-FPM's case, it's `FPM_SOCKETS`.
56 This configuration is possible with any web server that supports FastCGI (like Apache, Lighttpd, or nginx). The web server does not need to know anything special about the socket; use a normal PHP-FPM configuration.
58 Paths are based on a Fedora 19 system.
60 ### First, the configuration files
62 **/etc/php-fpm.d/my-php-fpm-pool.conf**
66 pid = /run/my-php-fpm-pool.pid ; Not really used by anything with daemonize = no, but needs to be writable.
67 error_log = syslog ; Will aggregate to the service's systemd journal.
68 daemonize = no ; systemd handles the forking.
71 listen = /var/run/my-php-fpm-pool.socket ; Must match systemd socket unit.
72 user = nginx ; Ignored but required.
73 group = nginx ; Ignored but required.
80 **/etc/systemd/system/my-php-fpm-pool.service**
86 Environment="FPM_SOCKETS=/var/run/my-php-fpm-pool.socket=3"
87 ExecStart=/usr/sbin/php-fpm --fpm-config=/etc/php-fpm.d/my-php-fpm-pool.conf
92 **/etc/systemd/system/my-php-fpm-pool.socket**
96 ListenStream=/var/run/my-php-fpm-pool.socket
99 WantedBy=sockets.target
103 ### Second, the setup commands
106 sudo systemctl --system daemon-reload
107 sudo systemctl start my-php-fpm-pool.socket
108 sudo systemctl enable my-php-fpm-pool.socket
112 After accessing the web server, the service should be running.
115 sudo systemctl status my-php-fpm-pool.service
119 It's possible to shut down the service and re-activate it using the web browser, too. It's necessary to stop and start the socket to reset some shutdown PHP-FPM does that otherwise breaks reactivation.
122 sudo systemctl stop my-php-fpm-pool.socket my-php-fpm-pool.service
123 sudo systemctl start my-php-fpm-pool.socket