centos64-python27-mod_wsgi-apache2.4

原创 2016年06月02日 10:31:57
1、先安装openssl ,以及openssl-devel
2、python27编译
    ./configure --prefix=/usr/local/python27 --enable-shared --with-ssl --with-zlib
    
    make

    make install

    a、--with-ssl 由于openssl-devel版本问题,导致ssl加载不了,可以去掉这个选项编译一遍

    b、重命名 现有python 为python2.66
    c、设置/usr/bin/python 软连接到python27
        ln -s /usr/local/python27/bin/python /usr/bin/python
        
    d、libpython2.7.so.1.0的错误时的 解决办法:
        vi /etc/ld.so.conf 添加/usr/local/python27/lib/
        /sbin/ldconfig
        /sbin/ldconfig -v
    
3、安装apache
    源代码安装2.4
        3.1、安装apr-1.5.1
            ./configure --prefix=/usr/local/apr
            make
            make install
        3.2、安装apr-util-1.5.4
            ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
            make
            make install
            
        3.2、安装pcre-8.36
            ./configure --prefix=/usr/local/pcre
            make
            make install
        
        3.3、安装openssl
            ./config --prefix=/usr/local/openssl
            make
            make install
            
        3.4 缺少expat-2.0.1.tar.gz
            下载并安装
             ./configure
             make
             make install
            
        3.5 安装httpd-2.4.12
            ./configure --prefix=/usr/local/apache2 --with-ssl=/usr/local/openssl/ssl/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/  --with-pcre=/usr/local/pcre/
            make
            make install
        
        3.6 配置通过/etc/init.d/httpd 启动
            a、修改进程的ID号存储的路径
                vim /usr/local/apache2/conf/httpd.conf
                添加如下一条:
                PidFile /var/run/httpd/httpd.pid
            b、修改 启动进程的用户和组
                User apache
                Group apache
                
            c、修改apache可执行文件的路径
                apachectl=/usr/local/apache2/bin/apachectl
                httpd=${HTTPD-/usr/local/apache2/bin/httpd}
            d、启动时报错 说找不到 /usr/local/apache/conf/httpd.conf
               软连接一下/usr/local/apache2 目录到 /usr/local/apache
                ln -s /usr/local/apache2  /usr/local/apache
            
            
    a、禁止访问问题
    下述是 Apache 2.2 VS Apache 2.4 的設定檔有哪些變更差異
        Deny All
            2.2 configuration:
                Order deny,allow
                Deny from all
            2.4 configuration:
                Require all denied
        Allow All
            2.2 configuration:
                Order allow,deny
                Allow from all
            2.4 configuration:
                Require all granted
        Allow Host
            2.2 configuration:
                Order Deny,Allow
                Deny from all
                Allow from example.org
            2.4 configuration:
                Require host example.org
        Directory 用 Require all granted
    
            <Directory /var/>
            Options FollowSymLinks
            AllowOverride None
            Require all granted
            </Directory>
    
        FilesMatch 維持用 Order
    
            <FilesMatch ".+\.phps$">
            SetHandler application/x-httpd-php-source
            Order Deny,Allow
            Allow from all
            </FilesMatch>
            
            
    注释掉:
    #<Directory />
    #    AllowOverride none
    #    Require all denied
    #</Directory>
    
            
    WSGISocketPrefix run/wsgi
    
    <VirtualHost *:8000>
        DocumentRoot /var/www/test
        ErrorLog logs/test-error_log
        CustomLog logs/test-access_log common
        Alias /media/ /var/www/test/media/
        Alias /static/ /var/www/test/static/
        LimitRequestLine 65535
        WSGIDaemonProcess test processes=1 threads=25 display-name=%{GROUP}
        WSGIProcessGroup test
        WSGIChunkedRequest On
        WSGIScriptAlias / /var/www/test/mysite/wsgi.py
        <Directory "/var/www/test">
          Options -Indexes +FollowSymlinks
          AllowOverride All
          Require all granted
        </Directory>
    </VirtualHost>
    
    b、Couldn't bind unix domain socket '/usr/local/apache/run/wsgi.23685.0.1.sock'
            是因为缺少run目录
            cd /usr/local/apache/

            创建run目录

            重启apache就好了

 

            
            
    c、/home/apache/.python-eggs, change the cache directory by setting the PYTHON_EGG_CACHE environment
    创建 /home/apache/.python-eggs目录
    
    
    d、修改日志目录
        ErrorLog "/var/log/httpd/error_log"
        CustomLog "/var/log/httpd/access_log" common
        
    e、安装完报不能引入 django1.7.10+pthon2.7.9
        ==> /var/log/httpd/dx_anhui_hipi_game-error_log <==
        [Thu Oct 08 22:01:56.744233 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200] mod_wsgi (pid=5497): Target WSGI script '/var/www/dx_anhui_hipi_game/mysite/wsgi.py' cannot be loaded as Python module.
        [Thu Oct 08 22:01:56.744250 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200] mod_wsgi (pid=5497): Exception occurred processing WSGI script '/var/www/dx_anhui_hipi_game/mysite/wsgi.py'.
        [Thu Oct 08 22:01:56.744276 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200] Traceback (most recent call last):
        [Thu Oct 08 22:01:56.744303 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]   File "/var/www/dx_anhui_hipi_game/mysite/wsgi.py", line 16, in <module>
        [Thu Oct 08 22:01:56.744337 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]     application = get_wsgi_application()
        [Thu Oct 08 22:01:56.744407 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]   File "/usr/local/python27/lib/python2.7/site-packages/Django-1.7.10-py2.7.egg/django/core/wsgi.py", line 14, in get_wsgi_application
        [Thu Oct 08 22:01:56.744439 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]     django.setup()
        [Thu Oct 08 22:01:56.744459 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]   File "/usr/local/python27/lib/python2.7/site-packages/Django-1.7.10-py2.7.egg/django/__init__.py", line 21, in setup
        [Thu Oct 08 22:01:56.744488 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]     apps.populate(settings.INSTALLED_APPS)
        [Thu Oct 08 22:01:56.744507 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]   File "/usr/local/python27/lib/python2.7/site-packages/Django-1.7.10-py2.7.egg/django/apps/registry.py", line 78, in populate
        [Thu Oct 08 22:01:56.744538 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200]     raise RuntimeError("populate() isn't reentrant")
        [Thu Oct 08 22:01:56.744565 2015] [:error] [pid 5497:tid 140342038816512] [remote 58.60.159.119:30200] RuntimeError: populate() isn't reentrant
        
        [Thu Oct 08 22:42:27.438088 2015] [:error] [pid 5268:tid 139970325456640]
        [Thu Oct 08 22:42:27.438091 2015] [:error] [pid 5268:tid 139970325456640] The Python egg cache directory is currently set to:
        [Thu Oct 08 22:42:27.438094 2015] [:error] [pid 5268:tid 139970325456640]
        [Thu Oct 08 22:42:27.438097 2015] [:error] [pid 5268:tid 139970325456640]   /sbin/.python-eggs
        [Thu Oct 08 22:42:27.438101 2015] [:error] [pid 5268:tid 139970325456640]
        [Thu Oct 08 22:42:27.438105 2015] [:error] [pid 5268:tid 139970325456640] Perhaps your account does not have write access to this directory?  You can
        [Thu Oct 08 22:42:27.438109 2015] [:error] [pid 5268:tid 139970325456640] change the cache directory by setting the PYTHON_EGG_CACHE environment
        [Thu Oct 08 22:42:27.438113 2015] [:error] [pid 5268:tid 139970325456640] variable to point to an accessible directory.
        [Thu Oct 08 22:42:27.438116 2015] [:error] [pid 5268:tid 139970325456640]
        [Thu Oct 08 22:42:29.941013 2015] [:error] [pid 5268:tid 139970325456640] [remote 58.60.159.119:44288] mod_wsgi (pid=5268): Target WSGI script '/var/www/dx_anhui_hipi_game/mysite/wsgi.py' does not contain WSGI application 'application'.

        应该是要设置下环境变量PYTHON_EGG_CACHE=
        
        wsgi中修改application
        
        import time
        import traceback
        import signal

        try:
            application = get_wsgi_application()
            print 'WSGI without exception'
        except Exception:
            print 'handling WSGI exception'
            # Error loading applications
            if 'mod_wsgi' in sys.modules:
                traceback.print_exc()
                os.kill(os.getpid(), signal.SIGINT)
                time.sleep(2.5)
                
        重启 在查看apache日志
        修改完相应的错误后,还原回来就OK了。
        
        f、修改apache默认创建的权限以及删除的字符编码
            vim /etc/sysconfig/httpd
            
            umask 002
            
            export LANG='en_US.UTF-8'
            export LC_ALL='en_US.UTF-8'
            
        
        
    
4、编译mod_wsgi
    python重新安装之后,mod_wsgi需要重新装
    cd mod_wsgi-3.4/
        apxs的为apache安装后的目录
        ./configure --with-apxs=/usr/sbin/apxs   --with-python=/usr/bin/python
    
        make
        make install
        
        apache2.4
        ./configure --with-apxs=/usr/local/apache2/bin/apxs   --with-python=/usr/bin/python
        
        make clean
        make
        make install
        
        LoadModule wsgi_module    modules/mod_wsgi.so
    

    有时候,有些包是已经编译过的,要重新编译必须 make clean 否则会导致你怎么安装都安装不上你想要的包


     重启apache报错:

        undefined symbol: apr_atomic_cas

         找到

            #if (APR_MAJOR_VERSION < 1)

            #define apr_atomic_cas32 apr_atomic_cas
 
           #endif


        注释掉:

        /***

          #if (APR_MAJOR_VERSION < 1)

                #define apr_atomic_cas32 apr_atomic_cas
 
              #endif

         **



    
5、mod_wsgi的配置
    import sys
    import os
    p = os.path.abspath(os.path.dirname(__file__))
    sys.path.insert(0, os.path.split(p)[0])
    os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
    
6、安装subversion svn客户端

7、安装pysvn
    

8、安装PIL插件,如果遇到下面错误的处理方法

   不要去官方下载pil ,安装 Pillow-2.0.0.zip 就OK了,这个插件包封装了


python的pygame涉猎

开篇祭出pygame官方文档:http://www.pygame.org/docs/ref/pygame.html pygame的模块很多,例如:  pygame,顶级模块    pyg...
  • weixin_35640856
  • weixin_35640856
  • 2017-06-25 10:55:36
  • 158

64位 win7 安装pygame的问题(已解决)

一开始安装了64位Python2.7.5,上pygame官网竟然没有64位的,又找到一个网址有http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame 方案一...
  • qq_14961401
  • qq_14961401
  • 2017-02-28 10:48:38
  • 773

CentOS 7.1 升级Python2.7.10及编译mod_wsgi指南

最近,准备学习下Django的开发。下载了最新的CentOS7.1(安装的时候选的开发及生成工作站,然后右边全勾上了),打算开始配置及开发。当然,环境的配置实际上还是有点小棘手的。找了一下网上的配置教...
  • bnxf00000
  • bnxf00000
  • 2015-09-20 10:16:33
  • 1580

apache2.2和python2.7的mod_wsgi

  • 2013年10月26日 14:13
  • 31KB
  • 下载

apache2.4+python2.7+mod wsgi部署django1.10项目

apache 安装参考前一章 django 项目使用 python manager.py startproject  lfctestdjango 目录:(创建了2个app python manage...
  • Elvis_lfc
  • Elvis_lfc
  • 2016-10-31 16:59:12
  • 1018

Apache2.4+mod_wsgi+Flask搭建web站点时的中文unicode问题

问题 最近公司购买了阿里云,预装的ubuntu1404,上面自带Apache2.4,计划安装Flask,需要通过wsgi适配,于是看到了这篇文章,按照上面的方法搭建成功 进一步丰富业务逻辑时,发现如...
  • happen23
  • happen23
  • 2016-09-09 09:45:25
  • 845

CentOS7+Python3.4+Django1.6.5+Apache2.4+mod_wsgi4.2.7

CentOS7+Python3.4+Django1.6.5+Apache2.4+mod_wsgi4.2.7
  • xiluoduyu
  • xiluoduyu
  • 2014-08-18 17:25:34
  • 3741

CentOS 7.2 配置Apache服务(httpd)--上篇

一、Apache简介 Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器软件,可以在大多数电脑操作系统中运行,由于其跨平台和安全性(尽管不断有...
  • wh211212
  • wh211212
  • 2016-10-31 15:39:36
  • 28906

Celery 分发任务

一、简介 Celery是基于分布式消息传递的开源异步任务队列。它侧重实时操作,也可用于计划任务。它的执行组件叫tasks,可在一个或多个worker节点上进行并行运算,支持的方式有multiproc...
  • jazywoo123
  • jazywoo123
  • 2013-12-28 23:44:03
  • 4776

使用模板

Web框架把我们从WSGI中拯救出来了。现在,我们只需要不断地编写函数,带上URL,就可以继续Web App的开发了。 但是,Web App不仅仅是处理逻辑,展示给用户的页面也非常重要。在函数中返回一...
  • cabbage2008
  • cabbage2008
  • 2016-05-06 15:18:43
  • 294
收藏助手
不良信息举报
您举报文章:centos64-python27-mod_wsgi-apache2.4
举报原因:
原因补充:

(最多只允许输入30个字)