Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run the django web server even after closing the shell on Amazon Linux

I'm running a Django application on my Amazon Linux instance using the below command:

python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000

I want the application to be running even after I quit the shell. How do I run this web server even after quitting the shell on Amazon Linux?

I tried using the & as shown below, but it didn't work.

python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000 &

like image 413
Manoj H Avatar asked Nov 27 '17 15:11

Manoj H


2 Answers

Running python manage.py ... is how you run in development, but it's not how you run on a web server. You need to deploy your application.

Take a look at Apache and mod_wsgi.

like image 141
jarmod Avatar answered Oct 16 '22 14:10

jarmod


Install screen with below command Screen is basically a tool which runs the process always, even we exit.

sudo apt-get update
sudo apt-get install screen

For details you can see: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server

Create a screen for you command, so your command can run as a daemon.

screen -S <processName> //Process name could be any random name for your process.

To enter inside screen.

screen -r <processName> 

Now you are inside screen and can run your command here.

python manage.py runserver ec2-instance-ip.us-east-2.compute.amazonaws.com:8000

Now exit screen: ctrl+a and then d

You can create multiple screens as many you want and can any time list them by command:

screen -ls

!important: this is not recommended for Production server. Look this to run Python app on production server: https://docs.djangoproject.com/en/2.0/howto/deployment/

like image 20
Jaskaran Singh Avatar answered Oct 16 '22 13:10

Jaskaran Singh