10. HANDS-ON TUTORIAL: Deploying a full-stack application on Ubuntu
Using AWS to deploy a Flask App with MySQL on Ubuntu 22.04 LTS in an EC2 Instance using Visual Studio Code
Table of contents
Tools Utilised:
Ubuntu
Git
GitHub
venv
Python
Flask
pip3
MySQL
Step-by-Step Guide
1. Update and install the necessary packages
sudo apt update && sudo apt install pip mysql-server python3-virtualenv -y
2. Clone the repo & cd
into the directory
git clone
https://github.com/mrbilalshafiq/DevOps-Project-1
&& cd DevOps-Project-1
3. Initiate the virtual environment
virtualenv venv
4. Activate the virtual environment
source venv/bin/activate
5. Install the requirements
pip3 install -r application/requirements.txt
6. Log into MySQL
sudo mysql -u root
7. Create the user which matches what is written in init.py
CREATE USER 'bilalhalal'@'localhost' IDENTIFIED BY 'password';
8. Grant the necessary privileges to the newly created user
GRANT ALL PRIVILEGES ON *.* TO 'bilalhalal'@'localhost';
9. Flush the privileges to update the privileges table
FLUSH PRIVILEGES;
10. Create the database which matches the database name written in init.py
CREATE DATABASE halalworlddb;
11. Exit out of MySQL
EXIT
12. Create the tables
python3
create.py
13. Find your public IP
curl ifconfig.me
14. Start the app using Python
python3
app.py
15. Enter your public IP in your browser on port 5000
Example:
3.8.95.114:5000/
16. Test the application
Clean Up
17. Stop the app correctly (using CTRL+Z will leave the process running)
CTRL+C
18. Deactivate the virtual environment
deactivate