How to Run the Python Backend Application of learncan.app ?
Introduction:
[edit]This guide provides step-by-step instructions on how to start the Python backend application for learncan.app using two different methods. Whether you choose to run the application in the background using `nohup` or manage it within a `screen` session, these instructions will help you ensure that the application is up and running successfully.
Prerequisites:
[edit]- Access to the server where learncan.app is hosted.
- Basic knowledge of Linux terminal commands.
- Python installed on the server.
- Virtual environment (`myenv`) set up for the Python application.
- Flask installed within the virtual environment.
- API key (`OPENAI_API_KEY`) obtained from OpenAI for the application.
Method 1: Using `nohup`
[edit]1. Change Directory to Document Root:
cd /var/www/html/learncan.app/
2. Activate Virtual Environment and Set Environment Variables:
source myenv/bin/activate export FLASK_APP=app export OPENAI_API_KEY='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'
3. Navigate to PythonBackend Directory and Start Flask Application:
cd PythonBackend/ nohup flask run &
4. Check if Port 5000 is Running:
netstat -nltp
Method 2: Using `screen`
[edit]1. Start a `screen` Session:
screen
2. Change Directory to Document Root:
cd /var/www/html/learncan.app/
3. Activate Virtual Environment and Set Environment Variables:
source myenv/bin/activate export FLASK_APP=app export OPENAI_API_KEY='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'
4. Navigate to PythonBackend Directory and Start Flask Application:
cd PythonBackend/ flask run
5. Check if Port 5000 is Running (in another terminal or another `screen` session):
netstat -nltp
6. Detach the `screen` Session:
Press `Ctrl + A` followed by `d`.
7. List Currently Running `screen` Sessions:
screen -ls
Conclusion:
[edit]These methods provide flexible options to start and manage the Python backend application of learncan.app. Method 1 with `nohup` ensures the application runs in the background persistently, while Method 2 using `screen` allows for session management and easy detachment. Monitoring the port ensures that the application is correctly running and accessible.
By following these steps, you can effectively deploy and maintain the Python backend application for learncan.app, ensuring smooth operation and availability.