Django 开发笔记 将Django项目部署到阿里云服务器(CentOS7)环境配置

阿里云服务器ECS CentOS7.3+Python3.7+Django+SQlite

阿里云服务器,最低配ECS服务器,学生认证白菜价,很适合做项目练手。
第一次做项目,加上是Linux小白,所以这里记录一下,配置服务器环境的过程。

工具:FinalShell(Mac)

Django 开发笔记 将Django项目部署到阿里云服务器(CentOS7)环境配置_第1张图片
这个工具蛮良心的,35元升级专业版,但是免费版也完全够用。
Windows 应该是XShell+Xftp

1. 新建ssh连接

Django 开发笔记 将Django项目部署到阿里云服务器(CentOS7)环境配置_第2张图片
名称、主机
分别对应阿里云服务器控制台里的名称和公网IP
用户名、密码
是在购买服务器时设置的,一般用户名是root
Django 开发笔记 将Django项目部署到阿里云服务器(CentOS7)环境配置_第3张图片

2. 安装Python3.7

  1. 先更新一下 yum源,不然后面Python编译会报错
[root@******* ~]# cd /etc/yum.repos.d/
[root@*******  yum.repos.d]# mkdir bak
[root@*******  yum.repos.d]# mv * bak
[root@*******  yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@*******  yum.repos.d]# wget http://mirrors.aliyun.com/repo/epel-7.repo
  1. 然后安装一些Python3.7需要的依赖
[root@*******  ~]# yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
[root@*******  ~]# yum -y groupinstall "Development tools"
  1. 下载Python3.7安装包
[root@*******  ~]# cd /usr/local/src/
[root@*******  src]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
  1. 解压安装包
[root@*******  src]# tar xvf Python-3.7.0.tar.xz

[root@*******  src]# mv Python-3.7.0 /usr/local/python-3.7

[root@*******  src]# cd /usr/local/python-3.7/
  1. 编译
LD_RUN_PATH=/usr/local/lib ./configure LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/usr/local/include"  --prefix=/usr/local/sbin/python-3.7
LD_RUN_PATH=/usr/local/lib make
make && make install

然后出现

Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1

Python3.7安装成功

  1. 方便起见,建立python3.7的软连接
[root@*******  ~]# which python 
//找到系统自带老版本python绝对路径

/usr/bin/python

[root@*******  ~]# ll /usr/bin/ |grep python
//查看当前连接

-rwxr-xr-x. 1 root root 11312 Nov 14 00:00 abrt-action-analyze-python
lrwxrwxrwx. 1 root root 7 Mar 14 18:19 python -> python2
lrwxrwxrwx. 1 root root 9 Mar 14 18:19 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Oct 31 07:46 python2.7

//建立新的软连接
[root@*******  ~]# rm -rf /usr/bin/python

[root@*******  ~]# ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python

‘/usr/bin/python’ -> ‘/usr/local/sbin/python-3.7/bin/python3’

[root@*******  ~]# ll /usr/bin/ |grep python
//查看结果

-rwxr-xr-x. 1 root root 11312 Nov 14 00:00 abrt-action-analyze-python
lrwxrwxrwx. 1 root root 38 Mar 14 19:24 python -> /usr/local/sbin/python-3.7/bin/python3
lrwxrwxrwx. 1 root root 9 Mar 14 18:19 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Oct 31 07:46 python2.7

成功

3. 安装最新版本SQlite

服务器自带的sqlite版本很老 3.7.17
一步一步安装,然后让Python3.7能找到即可

  1. 下载SQlite
wget https://sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar zxvf sqlite-autoconf-3280000.tar.gz
cd sqlite-autoconf-3280000
./configure
make && make install
  1. 适配

之前Python编译安装的时候

LD_RUN_PATH=/usr/local/lib ./configure LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/usr/local/include"  --prefix=/usr/local/sbin/python-3.7
LD_RUN_PATH=/usr/local/lib make

目的就是让python3.7可以顺利找到新版本的sqlite

Python 3.7.0 (default, August 11 2019, 01:31:39)
[GCC 4.8.5 20150623 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.28.0'
>>> exit()

成功

4. 上传项目工程文件夹

直接将项目文件夹拖动到/home文件夹中,等待上传完成即可。

参考:
https://blog.csdn.net/u011798443/article/details/80881931
https://stackoverflow.com/questions/26261080/compile-python-3-4-with-sqlite3

你可能感兴趣的:(Django开发笔记,Django)