-
Notifications
You must be signed in to change notification settings - Fork 70
Deploy Flask App on Ubuntu(Virtualenv Gunicorn Nginx Supervisor)
shin edited this page Mar 2, 2015
·
1 revision
##Attention
In this paper, I deploy this project in my work directory(/home/xin/workspace/python/flaskblog).
You can chose another directory,so you should edit all the config file for the change.
##Env
- System:Ubuntu 14.04
- Web Server: Nginx
- Environment: Virtualenv
- WSGI Server: Gunicorn
- Database: MySQL
- Monitor: Supervisor
##Install
###Install software
$ sudo apt-get install python-pip
$ sudo apt-get install python-dev
$ sudo pip install virtualenv
$ sudo apt-get install mysql-server
$ sudo apt-get install libmysqlclient-dev
$ sudo apt-get install nginx
$ sudo apt-get install supervisor
###Download project and setup virtualenv
Clone the code
$ git clone https://github.com/defshine/flaskblog.git
$ cd flaskblog
setup venv and install python package
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install -r requirements.txt
exit venv
(venv)$ deactivate
###Database
Create schema named flaskblog in MySQL,edit the username and password in config.py
In flaskblog directory,run
(venv)$ python manage.py create_db
(venv)$ python manage.py create_user -u admin -p 123456
###Setup server and add monitor
Pay attention to all the port setting in each step
Copy supervisor config file:
$ sudo cp flaskblog.conf /etc/supervisor/conf.d/
Restart supervisor and start flaskblog:
$ sudo supervisorctl reload
$ sudo supervisorctl start flaskblog
Look status:
$ sudo supervisorctl status
##Nginx
###Config and restart
$ sudo cp flaskblog /etc/nginx/sites-available/
$ cd /etc/nginx/sites-enabled
$ sudo ln -s /etc/nginx/sites-avalaible/flaskblog .
$ sudo service nginx reload
$ sudo service nginx restart
Look nginx status
$ sudo service nginx status
Visit:
Access on http://127.0.0.1
Admin on http://127.0.0.1/admin
#Enjoy it!