Issue
Executing this code:
shell_exec('nohup command&');
or this
shell_exec('nohup command > /path/to/nohup.out 2>&1&');
But there is no nohup.out in both cases. How can I run nohup with nohup.out via php?
Solution
shell_exec('nohup command > /path/to/nohup.out 2>&1&');
This line will work. Just make sure you have write permissions for the output folder. Consider your output folder is /usr/nohup-out
ls -l /usr/nohup-out
It should have write, read and execute permissions (rwx). If not, do this:
sudo chmod -R 777 /usr/nohup-out
Now, try to execute php file. It should create a nohup file in /usr/nohup-out
folder.
Sample script and result:
1. date.php:
<?php
shell_exec('nohup date > /usr/nohup-out/nohup.out 2>&1&');
?>
2. Execute php from terminal:
php date.php
3. nohup.out content after execution
Thu Apr 23 11:30:28 IST 2015
Answered By - Rajesh N