Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active November 25, 2023 13:59
Show Gist options
  • Save magnetikonline/c1a214e12cdbc65df7c620bbbc3af6e8 to your computer and use it in GitHub Desktop.
Save magnetikonline/c1a214e12cdbc65df7c620bbbc3af6e8 to your computer and use it in GitHub Desktop.
Nginx & PHP-FPM systemd services.

Nginx & PHP-FPM systemd services

A basic set of systemd units for starting Nginx and PHP-FPM daemons on system startup.

  • Ensures Nginx web server has started before the PHP-FPM process.
  • Nginx pid file placed at /run/nginx.pid.
  • PHP-FPM pid file placed at /run/php7/php-fpm.pid, PHP7 PHP-FPM config at /etc/php7.
  • Based on usage with Ubuntu 16.04LTS / 18.04LTS.

Unit files are placed in /etc/systemd/system and enabled with:

$ sudo systemctl enable nginx.service
$ sudo systemctl enable php-fpm.service

Fin.

[Unit]
Description=Nginx HTTP server
After=local-fs.target
After=network.target
[Service]
PIDFile=%t/nginx.pid
ExecStart=/usr/local/sbin/nginx
ExecReload=/bin/kill -HUP $MAINPID
Type=forking
[Install]
WantedBy=multi-user.target
[Unit]
Description=PHP FastCGI process manager
After=local-fs.target
After=network.target
After=nginx.service
[Service]
PIDFile=%t/php7/php-fpm.pid
ExecStartPre=/bin/mkdir --parents %t/php7
ExecStart=/usr/local/sbin/php-fpm --fpm-config /etc/php7/php-fpm.conf --nodaemonize
ExecReload=/bin/kill -USR2 $MAINPID
Type=simple
[Install]
WantedBy=multi-user.target
@RonnyW0ng
Copy link

RonnyW0ng commented Jan 10, 2019

Thanks!It was helpful for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment