Skip to content

Instantly share code, notes, and snippets.

@ebta
Last active June 23, 2021 05:06
Show Gist options
  • Save ebta/4537eebdd4731c81e30a84fe233ab46b to your computer and use it in GitHub Desktop.
Save ebta/4537eebdd4731c81e30a84fe233ab46b to your computer and use it in GitHub Desktop.
Run php application (cli) as service (daemons) in Ubuntu
# Save this file ex. /etc/systemd/system/myapp.service
# then run using: systemctl <start|status|restart|stop|enable> myapp
[Unit]
Description=My PHP APP Service
# May your script needs MySQL or other services to run, eg. MySQL Memcached
Requires=mysqld.service memcached.service
After=mysqld.service memcached.service
[Service]
User=user
Type=simple
TimeoutSec=0
PIDFile=/var/run/myapp.pid
ExecStart=/bin/sh -c '/usr/bin/php -f /var/www/app/myapp.php 2>&1 > /var/log/myapp.log'
KillMode=mixed
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment