Issue
I have developed a Django website and hosted the application in an Amazon EC2 instance. AMI name: ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231207 Instance type: t2.micro
I run the project following these steps:
- SSH into the EC2 instance from my terminal.
- I locate into the proper django project folder.
- I run this command: python3 manage.py runserver 0.0.0.0:8000
Now, following these steps, I'm able to run the project and it works fine. But when I close the cmd opened in my local PC that I used to SSH into the EC2 instance and to run the application, then the application doesn't work anymore. My aim would be to simply run the django project from my cmd once (of course after having SSH to the EC2) and then close my laptop and having the application still alive.
Do you know how can I do this?
Solution
You can use nohup for running it even after you terminate processes on your terminal/cmd.
nohup python3 manage.py runserver 0.0.0.0:8000 &
You can also log the output of above command by writing it to a file for debugging purpose.
nohup python3 manage.py runserver 0.0.0.0:8000 & > runserver.out
Note: Not recommended for production environment.
Answered By - TheResolver Answer Checked By - Terry (WPSolving Volunteer)