Centos+python3+nginx+uwsgi+flask
1、下载Python3
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
2、安装openssl
$ yum install openssl -y (-y 是遇到选择yes/no的时候默认提前yes了)
$ yum install openssl-devel -y
3、解压Python3
$ tar -zxf Python-3.6.3.tgz
$ cd Python-3.6.3
4、编译Python
$ ./configure
$ make & make install
5、安装虚拟环境
$ pip3 install virtualenv
$ virtualenv --no-site-packages -p python3 **_env (不关联系统库,使用python3)
$ source **_env/bin/activate(激活)
$ deactivate (退出虚拟环境)
6、安装nginx
$ yum install nginx
$ service nginx start
6.1、谁占用了80端口?kill掉
$ netstat -tln | grep 80
$ kill -9 'id'
7、安装uwsgi
$ pip install uwsgi
8、配置nginx与uwsgi之间
$ vim /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_param UWSGI_PYHOME /var/www/leefeng_env;
uwsgi_param UWSGI_CHDIR /var/www/leefeng;
uwsgi_param UWSGI_SCRIPT core:app;
}
}
$ vim /var/www/leefeng/uwsgi.ini
[uwsgi]
socket = 127.0.0.1:8000
plugins = python
chidir = /var/www/leefeng
virtualenv = /var/www/leefeng_env
wsgi-file = core.py
callable = app
threads = 2
processes = 4
9、编写代码
$ pip install flask
$ vim /var/www/leefeng/core.py
1
2
3
4
5
6
7
8
9
from flask import Flask
app=Flask(__name__)
@app.route('/')
def index():
return '<h2>Hello Word!</h2>'
if __name__ == '__main__':
app.run()
10、开启
$ uwsgi uwsgi.ini
$ nohup uwsgi uwsgi.ini & (断开终端依旧运行)
$ ps -ef|grep uwsgi (查询正在运行的uwsgi的进程,然后kill -9 id 后退出uwsgi)
错误解决
make时报错zipimport.ZipImportError: can't decompress data; zlib not available:#yum install zlib-devel
启动nginx报错:nginx: [emerg] socket() [::]:80 failed=需要在nginx.conf 注释掉#listen [::]:80 default_server;
pip报错:ssl module in Python is not available=(需要重新python :./configure make & make install )
yum install openssl -y (-y 是遇到选择yes/no的时候默认提前yes了)
yum install openssl-devel -y
安装python错误:Prior to installing Python in CentOS 7, let’s make sure our system has all the necessary development dependencies:
# yum -y groupinstall development
# yum -y install zlib-devel
1.查看数据库编码格式
mysql> show variables like 'character_set_database';
2.查看数据表的编码格式
mysql> show create table <表名>;
5.修改数据库的编码格式
mysql>alter database <数据库名> character set utf8;
6.修改数据表格编码格式
mysql>alter table <表名> character set utf8;