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.
flaskas the web framework.
nginxas the HTTP server
guniconas the wsgi server.
MySQLfor our database
flask-sqlalchemyas our ORM.
bootstrap-journaltheme makes us beautiful.
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.
- threaded comments
- up voting
- user karma
- rate limiting
- ajax form posting
- user profiles
- Set up an instance of MySQL on your server. Note your username and password.
sudo apt-get update sudo apt-get upgrade sudo apt-get install mysql-server libmysqlclient-dev
- Set up an instance of nginx on your server. I've provided the .conf scripts needed for our
servers in the
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.
- Download the repository and install all of the required python modules which this server uses.
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.
- flask_reddit has tasks which must occur on regular time intervals. To make this
happen, we use the
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:
nginx is our
internet facing HTTP server on port 80 while
gunicorn is our wsgi server which
is serving up our flask python application locally.
nginx reads client
requests and decides which requests to foreward to our
gunicorn server. For example,
nginx serves 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
the server configs located in
server directory 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.