Reddit clone in flask + python + nginx + https. View site:
flask_reddit is an extendable + minimalist Reddit clone.
This was built so beginners who want a standard CRUD + reddit-like application can quickly get to work.
We utilize: -
flaskas the web framework. -
nginxas the HTTP server
guniconas the wsgi server. -
MySQLfor our database -
flask-sqlalchemyas our ORM. -
bootstrap-journaltheme makes us beautiful. -
virtualenvemcompasses everything. -
supervisordmakes sure our service never crashes.
And thats pretty much it!
All of the configutations are in this repository. Deployment instructions will be out soon.
sudo apt-get update sudo apt-get upgrade sudo apt-get install mysql-server libmysqlclient-dev
sudo apt-get install nginx
Configure your nginx settings located in
Add your settings into your global conf file located in
Restart nginx to recognize your settings
sudo service nginx restart
Set up supervisord to monitor your project to make sure it never crashes. Supervisor is also convenient for simply restarting/starting your project with ease.
sudo apt-get install supervisor
When Supervisor is installed you can give it programs to start and watch by creating config files in the
/etc/supervisor/conf.ddirectory. I've provided the conf file which we use in the root directory of this repo as
supervisor.conf. An example supervisor command would be running
supervisorctl restart YOUR_APP_NAMEto restart gunicorn and bring up new changes.
Install virtualenv and set up a project root where ever you want.
sudo apt-get install python-virtualenv; cd /path/to/project; virtualenv reddit-env; cd reddit-env; source bin/activate; # viola, you are now in an enclosed python workspace.
git clone https://github.com/codelucas/flask_reddit.git; cd flask_reddit; pip install -r requirements.txt
Due to sensitive configuration information, I have hidden my personal
config.pyfile in the gitignore. But, I have provided a clean and easy to use config template in this repo named
Fill out the
flask_reddit/app_config.pyfile with your own information and then rename it to
config.pyso flask recognizes it by using
mv app_config.py config.py. Please be sure to fill out the mysql db settings similarly to how you set it up!, username, pass, etc
kickstart.pyscript to build the first user and subreddits.
crontab, which is present on UNIX systems.
A crontab is a dash which allows you to specify what programs to run and how often. I've provided flask_reddit's example crontab in the root directory as
To view your current crontab, run
crontab -l. To edit your crontab, run
Paste the contents of
jobs.croninto your crontab by running
crontab -eand pasting! More directions are present in the
Run the gunicorn server. You won't have to do this ever again if
supervisoris set up properly.
sudo sh run_gunicorn.sh
Note that we have now deployed two servers:
nginxis our internet facing HTTP server on port 80 while
gunicornis our wsgi server which is serving up our flask python application locally.
nginxreads client requests and decides which requests to foreward to our
gunicornserver. For example,
nginxserves static content like images very well but it forwards url routes to the homepage to gunicorn.
For a full list of details, view our configs at
Note, for this build to work there are paths that you must change in the
wsgi.pyfile, the server configs located in
serverdirectory and the
Refer to the flask project configuration options to understand what to put in your own config.py file.
Do not hesiate to contact me for help or concerns.