如何在AWS上将PHP脚本作为后台服务运行?

Now I am trying to execute php websocket script as a background. For it, I used below command on the AWS terminal.

php chat-server.php >> log.txt &

But strangely it is terminated without any errors.

My question is two.

  1. Why the php command is terminated on AWS? Is there any limitation to run a php script continually as a background service

  2. How can I run it permanently on AWS? I understand I can use a linux script to run my web-socket server permantely (maybe linux script will be re-lunch my php script when it will be terminated). But I don't know well linux commands. Who can help me?

Thanks for your advice!

First, enable PHP logs to see if there are any errors.

Then, to run it permanently, you can use screen or Tmux. It's simple to use and lets you detach the process and run it in the background. So you are able to logout from your ssh session, and the process is still running.

Please read: