Page 1 of 1

Deploy the application to

Posted: Sun Dec 22, 2024 9:39 am
by poxoja9630
Bash Copy the code $ mkdir deployedapp Create a new tab or window on your terminal so that you have one tab using the Ubuntu shell, while the other tab uses your machine's zsh or bash. Locate the directory where your application is located.

If your application does not have a file directly requirements.txt, create one by typing pip freeze > requirements.

txt in the terminal. Copy the full path to this directory into philippines mobile number example the command at the end of this subsection to transfer the folder from the local host to the remote host. <CHEMIN_COMPLET> Your application's page may look like /Users/<VOTRE_NOM>/documents/<VOTRE_DOSSIER_APP>/. The deployedapp at the end of the command refers to the folder created earlier in the Ubuntu shell.

Bash Copy the code $ sudo rsync -rv <FULL_PATH>/ ubuntu@<YOUR_IP_ADDRESS>:/home/ubuntu/deployedapp This may take a few minutes depending on the size of the project.

Deploy the application to the EC2 instance Switch back to the Ubuntu shell in the other tab or window. If you type the command cd deployedapp in the terminal and see the familiar project files in the folder, you're on the right track.

Image

Use the commands tmux to create a new session. This is where your application will run live. In the command below, I used “mytestapp” to name the tmux session, but you can name it whatever you like. Bash Copy the code tmux new -s mytestapp After running this command, you will be redirected to the tmux session "mytestapp".



Now that your application is installed on the EC2 server, install the required configuration for your application. Bash Copy the code $ pip3 install -r requirements.txt If your Flask application is regularly run in a virtual environment, start the virtual environment using the command source venv/bin/activate. Otherwise, it's time to run your application as you normally would within your local machine.

Bash Copy the code (venv) ubuntu@ip-172-31-31-102:~/deployedapp$ flask run --host=0.0.0.0 --port=8080 * Serving Flask app "app" (lazy loading) * Environment: development * Debug mode: on * Running on (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 199-963-168 Press Ctrl B and on D your keyboard to leave the tmux session running in the background.