美文网首页
CentOS 6.9 升级 Python 到 2.7.13 以及

CentOS 6.9 升级 Python 到 2.7.13 以及

作者: w也不知道 | 来源:发表于2017-05-30 23:56 被阅读0次
    1. 下载 Python 2.7.13 源码
    wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
    
    1. 安装编译依赖包
    yum groupinstall "Development tools"
    yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
    
    1. 编译安装
    tar -xf Python-2.7.13.tgz -C /usr/src
    cd /usr/src/Python-2.7.13
    ./configure --prefix=/usr/local/python27 --enable-shared
    make && make install
    
    1. 解决 yum 使用以及静态库共享问题
    mv /usr/bin/python /usr/bin/python2 /tmp
    sed -i '/python$/s/python/python2.6/' /usr/bin/yum
    ln -s /usr/local/python27/bin/python /usr/bin/python
    # 解决 error while loading shared libraries: libpython2.7.so.1.0
    cp libpython2.7.so.1.0 /usr/local/lib
    ln -s /usr/local/lib/libpython2.7.so.1.0 /usr/local/lib/libpython2.7.so
    # vi /etc/ld.so.conf
            include ld.so.conf.d/*.conf
            /usr/local/lib/
    ldconfig
    
    1. 安装 pip
    wget https://bootstrap.pypa.io/ez_setup.py
    python ez_setup.py
    easy_install-2.7 pip
    ln -s /usr/local/bin/pip /usr/bin/pip
    pip install django
    
    1. 安装 Apache 2.4.25
    cd /usr/src
    wget -c http://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.gz
    wget -c http://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.gz
    wget -c http://mirrors.aliyun.com/apache/httpd/httpd-2.4.25.tar.gz
    # 解压软件包
    # 安装 apr
    cd apr-1.5.2
    ./configure --prefix=/usr/local/apr-1.5.2
    make && make install
    # 安装 apr-utils
    cd ../apr-util-1.5.4
    ./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2
    make && make install 
    # 安装 httpd
    # 安装依赖包
    yum install pcre-devel zlib-devel openssl-devel python-devel -y
    cd ../httpd-2.4.25 
    ./configure --prefix=/usr/local/apache2.4.25 --with-apr=/usr/local/apr-1.5.2\
    --with-apr-util=/usr/local/apr-util-1.5.4\
    --enable-so --enable-deflate\
    --enable-expires\
    --enable-headers\
    --enable-ssl\
    --enable-rewrite\
    --enable-mpms-shared=all\
    --with-mpm=prefork\
    --enable-mods-shared=most
    

    安装成功


    1. 安装 mod_wsgi
    # mod_wsgi 历史版本:http://modwsgi.readthedocs.io/en/develop/release-notes.html
    wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.2.5.tar.gz
    tar -xf 4.2.5.tar.gz
    cd mod_wsgi-4.2.5
    ./configure --with-apxs=/usr/local/apache2.4.25/bin/apxs    --with-python=/usr/local/python27/bin/python2.7
    make && make install
    
    1. 修改 httpd.conf
    LoadModule wsgi_module modules/mod_wsgi.so
    Include conf/extra/httpd-vhosts.conf
    # vi /etc/httpd/conf/extra/httpd-vhosts.conf
    <VirtualHost *:80>
        ServerName www.imlcs.top
        Alias /media/ /web/mysite/media/
        Alias /static/ /web/mysite/static/
        <Directory /web/mysite/media>
            Require all granted
        </Directory>
        <Directory /web/mysite/static>
            Require all granted
        </Directory>
        WSGIScriptAlias / /web/mysite/mysite/wsgi.py
        <Directory /web/mysite/mysite>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    ErrorLog "logs/django-error_log"
    CustomLog "logs/django-access_log" common
    </VirtualHost>
    
    1. 修改 wsig.py
    import os,sys
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    sys.path.append(r'/web/mysite/')
    sys.path.append('/usr/local/lib/python2.7/site-packages')
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
    1. 启动服务,开始测试


      配置成功

    相关文章

      网友评论

          本文标题:CentOS 6.9 升级 Python 到 2.7.13 以及

          本文链接:https://www.haomeiwen.com/subject/mxnrfxtx.html