├── README.md
├── __init__.py
├── deploy.sh
├── sampleSite.conf
├── sampleWsgi.wsgi
└── templates
└── index.html
/README.md:
--------------------------------------------------------------------------------
1 | # FlaskDeploymentUbuntu18
2 | A Minimal Flask App along with deployment instructions
3 |
--------------------------------------------------------------------------------
/__init__.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template
2 | app = Flask(__name__)
3 |
4 | @app.route('/')
5 | def index():
6 | return render_template('index.html')
7 |
8 |
9 | if __name__ == "__main__":
10 | app.run(host='0.0.0.0', port=8080)
--------------------------------------------------------------------------------
/deploy.sh:
--------------------------------------------------------------------------------
1 | # INITIAL SERVER SETUP
2 | adduser harry
3 | usermod -aG sudo harry
4 | ufw app list # [to check]
5 | ufw allow OpenSSH
6 | ufw enable # [y enter]
7 | ufw status # [to check]
8 | # Now login as harry using putty and ssh
9 |
10 |
11 | # INSTALLING APACHE
12 | sudo apt update
13 | sudo apt --assume-yes install apache2
14 | sudo ufw app list
15 | sudo ufw app info "Apache Full" # [just to see info]
16 | sudo ufw allow in "Apache Full"
17 |
18 |
19 | # INSTALLING MYSQL
20 | sudo apt --assume-yes install mysql-server
21 | sudo mysql
22 | mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
23 | mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyStrongPassword123'; # [This will be mysql password]
24 | mysql> FLUSH PRIVILEGES;
25 | mysql> SELECT user,authentication_string,plugin,host FROM mysql.user; # [just to check]
26 | mysql> exit
27 |
28 |
29 | # INSTALLING PHP
30 | sudo apt --assume-yes install php libapache2-mod-php php-mysql
31 | sudo nano /etc/apache2/mods-enabled/dir.conf # replace index.html by index.php and vice versa
32 | sudo systemctl restart apache2
33 | sudo nano /var/www/html/info.php
34 |
35 | # Create info.php to test as follows:
36 |
39 |
40 |
41 | # INSTALLING PHPMYADMIN
42 | sudo apt install phpmyadmin php-mbstring php-gettext # press space to select apache2
43 | sudo phpenmod mbstring
44 | sudo systemctl restart apache2
45 | sudo mysql
46 | SELECT user,authentication_string,plugin,host FROM mysql.user; # (just to see)
47 | SELECT user,authentication_string,plugin,host FROM mysql.user; # (to check)
48 | CREATE USER 'harry'@'localhost' IDENTIFIED BY 'MyStrongPassword123';
49 | GRANT ALL PRIVILEGES ON *.* TO 'harry'@'localhost' WITH GRANT OPTION;
50 | exit
51 |
52 |
53 | # DEPLOYING FLASK APP
54 | sudo apt-get install libapache2-mod-wsgi-py3
55 | sudo a2enmod wsgi
56 | cd /var/www
57 | sudo mkdir cwh
58 | cd cwh
59 | sudo mkdir cwh
60 | cd cwh
61 |
62 |
63 | # GITHUB SSH KEYS
64 | # Do sudo su before these steps
65 | ssh-keygen -t rsa -b 4096 -C "name@domain.com"
66 | eval $(ssh-agent -s)
67 | ssh-add ~/.ssh/id_rsa
68 | copy using vim ~/.ssh/id_rsa.pub
69 |
70 |
71 | sudo apt --assume-yes install python3-pip
72 | sudo pip3 install virtualenv
73 | sudo virtualenv venv
74 | source venv/bin/activate
75 | sudo apt --assume-yes install libmysqlclient-dev
76 | pip install flask flask-sqlalchemy requests bs4 pandas mysqlclient
77 | deactivate
78 | sudo nano /etc/apache2/sites-available/cwh.conf # ADD Following
79 |