- Clone repository
git clone https://github.com/vug/personalwebapp.git
- Create a new virtual
conda create --name personalwebapp python=3.5
(or whatever the latest version is, say 3.7) - Activate environment. Windows:
activate personalwebapp
, OSX:source activate personalwebapp
- Deactive environment. Windows:
deactivate personalwebapp
, OSX:source deactivate personalwebapp
There is no Python 3.5 in apt-get
. Download source code of release, for example Python Release Python 3.5.2 | Python.org, from https://www.python.org/downloads/
First install the sqlite dependencies sudo apt-get install libsqlite3-dev
cd ~
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar -zvxf Python-3.5.2.tgz
mkdir python35
cd Python-3.5.2/
./configure --prefix=$HOME/python35 --enable-loadable-sqlite-extensions
make
make install
Now we have a working Python 3.5 executable at ~/python35/bin/python
. Use that to create a new virtual environment. mkvirtualenv personalwebapp -p ~/python35/bin/python3
.
- mikasa dependencies
- On Windows install Microsoft Visual C++ Build Tools
- On Unix install
sudo apt-get install -y libffi-dev libssl-dev
pip install -r requirements.txt
Install sqlite3 sudo apt-get install sqlite3
Connect to local sqlite database file sqlite3 app.db
Some commands
SELECT * from sqlite_master;
SELECT name FROM sqlite_master WHERE type='table';
SELECT * FROM user;
.exit
Create secret_key
for Flask-Login security features, create SQLite database, create at least one user to be able to write blog posts.
python manage.py gen_secret
python manage.py create_db
python manage.py populate_db
python manage.py create_user --email johndoe@mail.com --password pass --fullname "John Doe" --timezone -5
At the project root directory, run python -m unittest tests
or python -m unittest --verbose tests
python runserver.py
runs in default port 8000python runserver.py --port 8888
to set the port numbergunicorn wsgi:app
runs the app via gunicorn webservergunicorn -b :5000 wsgi:app
set the port in gunicorn
Supervisor configuration file sudo vim /etc/supervisor/conf.d/personalwebapp.conf
command = /home/ubuntu/.virtualenvs/personalwebapp/bin/gunicorn wsgi:app -w 3
directory = /home/ubuntu/personalwebapp
user = ubuntu
stdout_logfile = /home/ubuntu/personalwebapp/logs/gunicorn/gunicorn_stdout.log
stderr_logfile = /home/ubuntu/personalwebapp/logs/gunicorn/gunicorn_stderr.log
redirect_stderr = True
Supervisor commands
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start personalwebapp
sudo supervisorctl stop personalwebapp
sudo supervisorctl restart personalwebapp
create ~/.ssh/config
file on development machine to establish ssh connections easier.
Host mywebserver
HostName IP_OF_EC2_INSTANCE
User ubuntu # or ec2-user depending on the choice of AMI
IdentityFile ~/.ssh/PRIVATE_KEY_FILE.pem