Run PHP scripts in background on Linux

To run a PHP script in background from command line and keep it running even if you exit the terminal, use following syntax:

nohup php script.php < /dev/null &

nohup‘┬áis a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out.

In Unix-like operating systems, ‘/dev/null‘ or the null device is a special file that discards all data written to it.

‘&’ is to send the process in the background and return the command line prompt.

 Scroll to top