Interpreting nohup: Ignoring Input and Appending Output to 'nohup.out'
When you run a long-running process like a PHP server from a terminal, the session that spawned it is inherently fragile. If you close the SSH connection or terminate the terminal window, the operating system sends a SIGHUP signal to all processes attached to that shell. Unless explicitly detached, these processes will die immediately. The standard solution for this scenario on Unix-like systems involves the nohup utility, which stands for "no hang up."
The specific message you are encountering, nohup: ignoring input and appending output to 'nohup.out', is not an error in the traditional sense; it is a confirmation that nohup is functioning exactly as designed. When this message appears after executing nohup php server1.php, it indicates two critical behavioral changes applied to your script by the shell:
First, the command's standard input (stdin) is being detached and redirected to /dev/null. This prevents any attempt by the running PHP process to read from the terminal. Second, and more importantly for debugging, both standard output (stdout) and standard error (stderr) are redirected to a file named nohup.out in your current working directory.
This redirection happens regardless of whether you explicitly specify 2>&1. If your script attempts to write logs or print debug messages, they will not appear on the screen while the terminal is active; instead, they accumulate in that file. This design ensures that closing your SSH session does not terminate the process, but it also means you lose visibility into real-time execution unless you monitor that specific output file later.
Why You Should Not Rely on nohup.out
The default behavior of writing to nohup.out is often considered a temporary workaround rather than a production solution. As your application grows, logging everything to a single file in the current directory can lead to clutter and makes rotating logs difficult without additional configuration. Furthermore, if you are using a framework like Laravel, the default error handling mechanisms might expect output streams to behave differently than a simple file append, potentially masking critical exceptions if not handled correctly.
Instead of relying on the implicit nohup.out file, it is best practice to redirect your process's output explicitly. You can do this by adding redirection operators directly to your command line:
nohup php server1.php > /var/log/myapp/server.log 2>&1 &
In this example, the > operator redirects stdout, while 2>&1 ensures that stderr is appended to the same file. The trailing & detaches the process from the shell entirely, allowing it to continue running even if the parent shell exits immediately. This approach gives you full control over where logs go and allows for easier log rotation using tools like logrotate.
Handling Input Streams Carefully
The warning message also confirms that input is being ignored. If your PHP script attempts to read from stdin, it will encounter an empty stream or fail depending on how the stream is handled within the code. This is rarely a problem for typical web server scripts, but it becomes critical if your application expects interactive input or reads configuration from a pipe.
If your script requires specific environment variables or file paths that are only available when run interactively, simply using nohup might not be sufficient. In such cases, you may need to explicitly set these variables in the command line before invoking nohup. Additionally, if you are running this on a shared hosting environment or a containerized setup, ensure that the user running the process has write permissions for the output file; otherwise, the redirection will fail silently or throw a permission error.
For more robust process management, consider using screen or tmux. These tools allow you to create sessions where you can detach and reattach, offering more flexibility than nohup alone. However, if your goal is truly to run a daemon-like service in the background without any terminal attachment, explicit redirection and proper log handling remain the gold standard for maintaining stability and observability.
