$ git clone [email protected]:brandon-wallace/fstack-forum.git
$ cd fstack-forum/
$ vim .env
FLASK_ENV=development
FLASK_APP=run.py
DATABASE_URI='postgresql:https://<username>:<password>@<hostname>:<port>/<database_name>'
DEV_DATABASE_URI='postgresql:https://<username>:<password>@<hostname>:<port>/<dev_database_name>'
SECRET_KEY=<your_secret_key>
SECURITY_PASSWORD_SALT=<your_password_salt>
To connect to a local SMTP server add this to the .env file.
MAIL_SERVER='localhost'
MAIL_PORT=25
MAIL_USERNAME=""
MAIL_PASSWORD=""
MAIL_DEFAULT_SENDER="no-reply@<yourdomain.com>"
To use Gmail as an SMTP server add this to the .env file.
MAIL_SERVER='[email protected]'
MAIL_PORT=465
MAIL_USERNAME="<[email protected]>"
MAIL_PASSWORD="<your_gmail_password>"
MAIL_DEFAULT_SENDER=("<Your gmail username>", "<[email protected]>")
$ pipenv shell
$ pipenv install
$ pipenv install flask-debugtoolbar --dev
$ sudo su - postgres
$ psql
# CREATE DATABASE fstackforum.db
# CREATE DATABASE fstackforumdev.db
# \q
$ python3
>>> from application.models import User, Post, Comment
>>> from application import db, create_app
>>> app = create_app()
>>> app.app_context().push()
>>> db.create_all()
# Output
[...]
2020-07-05 13:50:21,831 INFO sqlalchemy.engine.Engine
CREATE TABLE "user" (
id SERIAL NOT NULL,
username VARCHAR(20) NOT NULL,
email VARCHAR(120) NOT NULL,
email_confirmed BOOLEAN NOT NULL,
email_confirmed_on TIMESTAMP WITHOUT TIME ZONE,
image_file VARCHAR(20) NOT NULL,
password VARCHAR(60) NOT NULL,
[...]
>>> exit()
$ flask run -h 127.0.0.1 -p 5000
Navigate to https://127.0.0.1:5000
$ vim /etc/systemd/system/fstackforum.service
[Unit]
Description=Use Guicorn to run fstackforum.
After=network.target
[Service]
User=<your_username>
Group=<group_name>
WorkingDirectory=/path/to/fstackforum
ExecStart=/path/to/gunicorn --workers 3 --bind unix:/path/to/fstackforum/fstackforum.sock wsgi:app
[Install]
WantedBy=multi-user.target
Start the service.
$ sudo systemctl enable fstackforum.service
$ sudo systemctl start fstackforum.service
Add logging to Gunicorn. Change the systemd file from this.
ExecStart=/path/to/gunicorn --workers 3 --bind unix:/path/to/fstackforum/fstackforum.sock wsgi:app
To this:
ExecStart=/path/to/gunicorn --workers 3 --bind unix:/path/to/fstackforum/fstackforum.sock wsgi:app --error-logfile /path/to/fstackforum/gunicorn-error.log --log-level debug
Check the systemd service.
$ sudo systemctl status fstackforum.service
$ journal -xe
This project is licensed under the GPL-3.0 License.