一、web项目的部署
本质三件事:
租个服务器(含公网ip)+配置环境
代码放在服务器
程序运行起来
使用xshell不太方便,在企业中大部分使用的都是git
二、git的安装与gitee代码仓库的基础操作
git官方地址:https://git-scm.com/downloads
如果进不去的话,就可能需要“科学上网”
根据你使用的操作系统进行选择 :
git代码仓库:gitHub,gitee,gitlab 我这里使用gitee
1.进入界面,点击+创建仓库
2.填写项目名称等信息后点击创建
3.基于git的命令,使本地项目与仓库产生连接
说明:本地项目中,并不是所有的文件都需要上传,运行产生的文件就没必要上传,所以先配置一下git文件 .gitignore 配置不想上传的文件
python中gitignore文件模板
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
# Mac
.DS_Store
# sqlite
*.db
# profile dir
profile/
# logs
logs/
三、git的常用命令
1.一次性执行:
git config --global user.name "朱大强"
git config --global user.email "zhudaqiang@live.com"
2.经常执行:
cd reception_master
git init
git remote add origin https://gitee.com/SunChen985/reception_master.gitgit add .
git commit -m 'init'
git push origin master
将项目push到git仓库,服务器上就相当于我们本地主机一样,下载个git,通过git clone下载项目
第一次: cd /data/
mkdirs www
cd /data/www
git clone https://gitee.com/SunChen985/reception_master.git
账号,密码
--之后
cd /data/www/program/
git pull origin master
在服务器上安装git
yum install git -y
yum,系统安装软件
pip,为python安装依赖包
npm,为node.js安装依赖包
四、在服务器上安装依赖(需要哪些依赖)
需要使用uwsgi来处理视图接口,使用nginx做反向代理来处理前端页面
安装python3.9
1.安装gcc yum install gcc -y
2.安装python依赖
yum install zlib zlib-devel -y
yum install bzip2 bzip2-devel -y
yum install ncurses ncurses-devel -y
yum install readline readline-devel -y
yum install openssl openssl-devel -y
yum install xz lzma xz-devel -y
yum install sqlite sqlite-devel -y
yum install gdbm gdbm-devel -y
yum install tk tk-devel -y
yum install mysql-devel -y
yum install python-devel -y
yum install libffi-devel -y
3.下载源码 python3.12
yum install wget -y
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
4.解压&编译&安装
tar -xvf Python-3.12.0.tgz
cd python-3.12.0
./configure
make all
make install
5.python解释器配置豆瓣源
pip3 config set global.index-url https://pypi.douban.com/simple
6. 安装 virtualenv
pip3 install virtualenv
7.创建虚拟环境
代码:
/data/pro/reception
环境:
/envs/nb
virtualenv /envs/nb --python=python3
8.激活虚拟环境
source /envs/nb/bin/activate
9.假设(这种启动方式性能较低)
python app.py