zoukankan      html  css  js  c++  java
  • Apache部署Django项目

    一、Python3.5.4安装

    1.1 下载地址

    
    
    https://www.python.org/downloads/windows/
    
    选择Windows x86-64 executable installer
    
    下载解压:python-3.5.4-amd64.exe
    
    问题:安装python-3.5.4-amd64.exe时报错:0x80240017
    解决:重装系统:Windows8.1-KB2919355-x64.msu
        下载Windows8.1-KB2919355-x64.msu:
    https://pan.baidu.com/s/1Iw8y-jsbnrLyzUncua1lSQ#list/path=%2F
    
    

     

    1.2 添加系统环境

    如:C:python35和C:python35Scripts

    1.3 更新pip3

    python -m pip install --upgrade pip --force-reinstall

     

    1.4 安装项目依赖

    先安装tornado:tornado-5.1.1-cp35-cp35m-win_amd64.whl
    
    下载网址:https://pypi.org/project/tornado/5.1.1/#files
    
    pip3 install tornado-5.1.1-cp35-cp35m-win_amd64.whl
    
    再安装项目依赖    
    pip3 install -r requirements.txt   注:这里会报错,执行1.6中的步骤进行安装

     

    1.5 手动下载并安装mod_wsgi

    下载网址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
    
    找到下载:mod_wsgi-4.5.24+ap24vc14-cp35-cp35m-win_amd64.whl
    
    pip3 install mod_wsgi-4.5.24+ap24vc14-cp35-cp35m-win_amd64.whl

     

    1.6 没网的情况下安装依赖包

    ①下载:(直接在pycharm上项目路径下)
    pip3 download -d C:UsershzxDesktoppackage -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
    
    注:C:UsershzxDesktoppackage  指的是桌面上新建的空文件夹为package的路径,
    
    ②安装:把package文件夹和requirements.txt放在C盘根目录下
      pip3 install --no-index --find-links=C:package -r requirements.txt
    
    ③问题:安装过项目依赖后,执行python manage.py runserver 192.168.1.67:8000后会报错,提示xxx模块没有安装,
    解决依次执行pip3 install 模块名==版本号 -i https://pypi.tuna.tsinghua.edu.cn/simple/

     

    1.7 oracle_client安装解决

    参考资料:https://www.cnblogs.com/mmz-tester/p/11122165.html
    下载安装包(注意下载对应的版本,python是32位的还是64位的):
    
    ①cx_Oracle-5.3-11g.win32-py3.5.exe   
    下载地址:https://pypi.org/project/cx-Oracle/5.3/ 
    
    ②instantclient-basic-win32-11.1.0.7.0.zip    
    下载地址:
    https://www.oracle.com/database/technologies/instant-client/microsoft-windows-32-downloads.html
    
    ③解压instantclient-basic-win32-11.1.0.7.0.zip  得到 instantclient_11_1
    复制oci.dll,oraocci11.dll,oraociei11.dll的3个文件粘贴到你的python目录的Libs/site-packages文件夹下面。
    
    ④测试
    import cx_Oracle
    用自己的实际数据库用户名、密码、主机ip地址 替换即可
    conn = cx_Oracle.connect('scott/tiger@192.168.100.211/oracle')
    curs = conn.cursor()
    sql = 'select * from DEPT' 
    rr = curs.execute(sql)
    row = curs.fetchone()
    print(row[0])
    curs.close()
    conn.close()

    二、MySQL5.6安装

    2.1 添加mysql的bin目录至系统环境

    C:Mysql56in

     

    2.2 配置my.ini

    创建my.ini文件,放在bin目录下面,配置内容:
    
    [mysql]
    default-character-set=utf8                  # 设置mysql客户端默认字符集
    [mysqld]
    port = 3306                                 # 设置3306端口
    basedir=E:/Mysql56                          #  设置mysql的安装目录
    datadir=E:/Mysql56/data                     # 设置mysql数据库的数据的存放目录
    max_connections=200                         # 允许最大连接数
    character-set-server=utf8                   # 服务端使用的字符集默认为8比特编码的latin1字符集
    default-storage-engine=INNODB               # 创建新表时将使用的默认存储引擎

     

    2.3 初始化数据库、安装并启动服务

    mysqld --initialize-insecure  
    mysqld -install    如果已存在,则删除:sc delete mysql  或者 mysql –remove
    net start mysql     

     

    2.4 初始化登录密码

    mysqladmin -u root -p password
    回车
    出现Enter password:直接回车,未设置密码时默认没有密码,
    接着出现“New password:”输入新的密码password,回车即可,
    接着出现“Confirm new password:”确认密码password,回车即可。
    登录mysql:mysql –uroot –ppassword

     

    2.5 删除无用配置

    delete from mysql.user where user='';  
    delete from mysql.user where host='::1';

     

    2.6 令所用用户可以访问

    update user set host='%' where user ='root';
    flush privileges;

     

    2.7 导入项目数据库

    ①先创建数据库
    mysql –uroot –ppassword
    create database tesudrm_adg charset=utf8;
    ②导入项目数据库 mysql
    -uroot -ppassword tesudrm_adg < tesudrm_adg.sql

    三、Redis3.2.1安装

    3.1 下载地址

    https://github.com/MSOpenTech/redis
    版本:Redis-x64-3.2.100

     

    3.2 解压安装

    https://www.cnblogs.com/zhangguosheng1121/p/11153548.html

     

    3.3 启动

    先修改配置文件redis.windows.conf: ①注释bind:172.0.0.1  ②requirepass redis密码(tesunet)

    redis-server redis.windows.conf 指定配置文件开启

     

    3.4 设置redis服务(开机自启)

    redis-server --service-install redis.windows.conf --loglevel verbose

     

    3.5 常用命令

    卸载服务:redis-server --service-uninstall
    开启服务:redis-server --service-start
    停止服务:redis-server --service-stop

     

    3.6 测试

    redis-cli -h 127.0.0.1 -p 6379或者redis-cli     注意:如果redis-windows.conf中设置了密码:requirepass:tesunet。则登录命令为:redis-cli -a tesunet
    127.0.0.1:6379>ping  
    PONG
    127.0.0.1:6379>select * from users
    注:检验服务端是否启动成功,登录客户端执行ping命令,结果出现PONG则服务端启动成功

    四、Apache安装

    4.1 解压下载的压缩包

    https://de.apachehaus.com/downloads/httpd-2.4.41-o102s-x64-vc14-r2.zip
    
    解压httpd-2.4.41-o102s-x64-vc14-r2.zip
    将解压出的Apache24移植指定位置C盘根路径:C:

     

    4.2 修改配置文件

    cd C: Apache24confhttpd.conf
    ①Apache24文件的路径,其余不用改:
    Define SRVROOT "C:Apache24"  
    ②此处为你要发布的网站ip地址,此处我用我电脑的ip和端口,你也可以用127.
    0.0.1:8000用于本地测试;80端口自己设置 Listen 192.168.1.67:80 ServerName 192.168.1.67:80

    ③注释: # Define ENABLE_TLS13 "Yes"

     

    4.3 创建apache服务(管理员权限开启终端)

    ①cd C:Apache24in
    ②创建服务:httpd.exe -k install -n "Apache24" 
    ③卸载服务:httpd.exe -k uninstall -n "Apache24"
    ④重启apache命令:httpd.exe -k restart    

     

    4.4 访问测试

    192.168.1.67:8000  出现页面,则Apache服务配置成功

     

    4.5 配置mod_wsgi

    ①查看mod_wsgi路径
    mod_wsgi-express module-config
    ②记录下来 LoadFile
    "C:/python35/python35.dll" LoadModule wsgi_module "C:/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd" WSGIPythonHome "C:/python35"

    五、项目TSDRM_ADG

    5.1 拷贝项目到C盘根目录下

    5.2 设置django静态文件路径

    ①settings.py文件中写入静态文件物理路径(已经写了)
    SITE_ROOT=os.path.join(os.path.abspath(os.path.dirname(__file__)),'..')
    STATIC_ROOT = os.path.join(SITE_ROOT,'static')
       
    ②添加静态文件访问逻辑路径 STATICFILES_DIRS
    = [ os.path.join(BASE_DIR, 'static') ]
    ③收集静态文件 python manage.py collectstatic
    ④注销掉物理路径
    # STATIC_ROOT #
    SITE_ROOT

     

    5.3 修改配置文件httpd.conf

    ①安装wsgi模块后,出来的三行字符,直接复制过来
    LoadFile "C:/python35/python35.dll"
    LoadModule wsgi_module "C:/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
    WSGIPythonHome "C:/python35"

    ②设置项目中的wsgi路径 WSGIScriptAlias / C:TSDRM_ADGTSDRMwsgi.py

    ③设置项目路径 WSGIPythonPath C:TSDRM_ADG

    ④设置wsgi路径
    <Directory C:TSDRM_ADGTSDRM> <Files wsgi.py> Require all granted </Files> </Directory>


    ⑤设置静态文件路径 Alias /static C:TSDRM_ADGstatic <Directory C:TSDRM_ADGstatic> AllowOverride None Options None Require all granted </Directory>

     

    5.4 访问项目:192.168.1.67:8000

    ①问题:Forbidden You don't have permission to access this resource.
      解决:
      找到 apache 配置文件 httpd.conf
      把里面的
        <Directory />
            AllowOverride none
            Require all denied
        </Directory>
      改为
        <Directory />
            AllowOverride none
            Require all granted
        </Directory>
        
    
    
    ②问题:
      Internal Server Error
      The server encountered an internal error or misconfiguration and was unable to complete your request.
    
      Please contact the server administrator, add.com@phpstudy and inform them of the time the error occurred, and anything you might have done that may have caused the error
    
    查看问题:进入到C:Apache24logs
    查看error.log,报错信息:
        File "C:\python35\lib\site-packages\django\__init__.py", line 17, in setup
        configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
        File "C:\python35\lib\importlib\__init__.py", line 126, in import_module
        cursor.execute(sql)
        File "C:\python35\lib\site-packages\pymysql\cursors.py", line 165, in execute
        result = self._query(query)
        File "C:\python35\lib\site-packages\pymysql\cursors.py", line 321, in _query
        conn.query(q)
        File "C:\python35\lib\site-packages\pymysql\connections.py", line 860, in query
        self._affected_rows = self._read_query_result(unbuffered=unbuffered)
        pymysql.err.InternalError: (1046, 'No database selected')
    解决:路径出错
      进入到项目settings.py中:
      注释:db_config_file = os.path.join(os.path.join(os.path.join(os.getcwd(), "faconstor"), "config"), "db_config.xml")
       改为:db_config_file = r'C:TSDRM_ADGfaconstorconfigdb_config.xml'

     

    5.5 下载wkhtmltopdf应用软件

    ①地址:https://github.com/wkhtmltopdf/wkhtmltopdf/releases/
    ②下载对应的应用软件:wkhtmltox-0.12.5-1.msvc2015-win64.exe
    ③将wkhtmltopdf应用软件拷贝至Apach24目录



    将wkhtmltopdf应用软件拷贝纸Apache24/faconstor目录下
      新建文件夹faconstor,将收集到的静态文件夹static拷贝一份至faconstor
  • 相关阅读:
    start tag, end tag issues in IE7, particularly in xslt transformation
    用SandCastle为注释生成chm文档
    Firebug
    架构的重点
    Linux Shell常用技巧(十) 管道组合
    Linux JDK升级
    Linux Shell常用技巧(十二) Shell编程
    Packet Tracer 5.0实验(一) 交换机的基本配置与管理
    Linux Shell常用技巧(六) sort uniq tar split
    Linux Shell常用技巧(二) grep
  • 原文地址:https://www.cnblogs.com/zhangguosheng1121/p/11891340.html
Copyright © 2011-2022 走看看