Deploy Flask App on Ubuntu(Virtualenv Gunicorn Nginx Supervisor)

shin edited this page Mar 2, 2015 · 1 revision

Introduce how deploy this project on Ubuntu.

##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

  1. System:Ubuntu 14.04
  2. Web Server: Nginx
  3. Environment: Virtualenv
  4. WSGI Server: Gunicorn
  5. Database: MySQL
  6. 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!

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.