# Deploy Flask app to AWS EC2 ## 1. Connect to EC2 Launch an instance on AWS. You'll get a `.pem` file. Download and save it to a private path. Change permission first: `chmod 400 /path/to/your/pemfile.pem` Connect to instance via ssh: ``` ssh -i /path/to/your/pemfile.pem ubuntu@my-instance-public-ip-address ``` ## 2. Install something you'll need ``` sudo apt-get update sudo apt install pipenv sudo apt install python3 python3-pip sudo apt-get install apache2 sudo apt-get install libapache2-mod-wsgi-py3 ``` install python 3.7 ``` sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python3.7 ``` ## 3. Configure Apache Settings ### 3.1 Apache settings ``` cd /etc/apache2/sites-enabled sudo vim 000-default.conf ``` add the conten below: ``` WSGIDaemonProcess flaskapp threads=5 WSGIScriptAlias / /var/www/html/{your_app_name}/flaskapp.wsgi <Directory flaskapp> WSGIProcessGroup flaskapp WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> ``` ### 3.2 wsgi settings ``` vim flaskapp.wsgi ``` add the conten below: ``` import sys sys.path.insert(0, '/var/www/html/{your_app_name}') from {main.py} import app as application ``` make a symbolic link ``` sudo ln -sT ~/{your_app_name} /var/www/html/{your_app_name} ``` ## 4. Useful Commands ### Upload to EC2 ``` scp -i /path/to/your/pemfile.pem /local/path/to/your.csv ubuntu@my-instance-public-ip-address:path/to/your.csv ``` ### Restart Apache Server ``` sudo service apache2 restart ``` ### Trace Apache Log ``` tail -f /var/log/apache2/error.log ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up