sudo apt-get update && sudo apt-get upgrade
sudo apt-get install git
sudo apt-get install python-pip
sudo apt-get install libmysqld-dev
sudo apt-get install python-dev
sudo pip install virtualenv
在home主目录下创建文件夹:/home/www/wechat
cd到wechat文件夹,创建virtualenv文件夹:virtualenv venv
启动virtualenv:source venv/bin/activate ,启动后在命令行用户名前面会出现(venv)
deactivate退出虚拟环境
上传flask项目文件夹(nova_weixin为例)至wechat文件夹下
nova_weixin项目结构:https://github.com/imndszy/nova_weixin
启动虚拟环境,通过pip install -r requirements.txt
安装依赖库
安装uwsgi:pip install uwsgi
配置uwsgi,在wechat文件夹下创建config.ini:
[uwsgi]
# uwsgi 启动时所使用的地址与端口
socket = 127.0.0.1:8001
# 指向网站目录
chdir = /home/www/wechat/nova_weixin
# python 启动程序文件
wsgi-file = manage.py
# python 程序内用以启动的 application 变量名
callable = app
# 处理器数
processes = 4
# 线程数
threads = 2
#状态检测地址
stats = 127.0.0.1:9191
#修改代码后自动重启
py-autoreload = 1
daemonize = /home/www/wechat/uwsgi.log
安装supervisor,sudo apt-get install supervisor
配置supervisor,vim /etc/supervisor/conf.d/wechat.conf
:
[program:wechat]
# 启动命令入口
command=/home/www/wechat/venv/bin/uwsgi /home/www/wechat/config.ini
# 命令程序所在目录
directory=/home/www/wechat
#运行命令的用户名
user=root
autostart=true
autorestart=true
#日志地址
stdout_logfile=/home/www/wechat/wechat_uwsgi_supervisor.log
安装nginx,sudo apt-get install nginx
配置nginx,修改/etc/nginx/sites-available/default文件,使其内容为:
server {
listen 80;
server_name XXX.XXX.XXX; #公网地址
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001; # 指向uwsgi 所应用的内部地址,所有请求将转发给uwsgi 处理
uwsgi_param UWSGI_PYHOME /home/wwwwechat/venv; # 指向虚拟环境目录
uwsgi_param UWSGI_CHDIR /home/www/wechat/nova_weixin; # 指向网站根目录
uwsgi_param UWSGI_SCRIPT manage:app; # 指定启动程序
}
}
安装mysql:sudo apt-get install mysql-server mysql-client
并设置密码
修改mysql配置,参考:http://blog.csdn.net/imjtrszy/article/details/4697553,sudo vim /etc/mysql/my.cnf,在[client]和[mysqld]下分别添加default-character-set = utf8,character-set-server= utf8,然后修改max_allowed_packet=128M(防止导入数据库文件失败),保存退出
重启mysql服务:sudo service mysql restart
修改config文件中的相关配置
启动supervisor:sudo service supervisor start
启动nginx:sudo service nginx start