Skip to content

Instantly share code, notes, and snippets.

@matipl-pl
Forked from magnetikonline/README.md
Created May 7, 2018 14:04
Show Gist options
  • Save matipl-pl/b9034f6f5b65fc84ec4252211517c16d to your computer and use it in GitHub Desktop.
Save matipl-pl/b9034f6f5b65fc84ec4252211517c16d to your computer and use it in GitHub Desktop.
Example Nginx & PHP-FPM systemd service configs.

Example Nginx & PHP-FPM systemd service configs

A set of really basic systemd configs for starting Nginx and PHP-FPM on system boot.

  • Ensures Nginx web server has started before starting the PHP-FPM process.
  • 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.

Both scripts placed in /lib/systemd/system and enabled by the following:

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

Fin.

[Unit]
Description=Nginx HTTP server
After=local-fs.target network.target
[Service]
PIDFile=/run/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 network.target nginx.service
[Service]
PIDFile=/run/php7/php-fpm.pid
ExecStartPre=/bin/mkdir --parents /run/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment