centos64-python27-mod_wsgi-apache2.4

前端之家收集整理的这篇文章主要介绍了centos64-python27-mod_wsgi-apache2.4前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
1、先安装openssl ,以及openssl-devel
2、python27编译
./configure --prefix=/usr/local/python27 --enable-shared --with-ssl --with-zlib

make
make install
a、重命名 现有python 为python2.66
b、设置/usr/bin/python 软连接到python27
ln -s /usr/local/python27/bin/python /usr/bin/python

c、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目录


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 否则会导致你怎么安装都安装不上你想要的包

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了,这个插件包封装了

原文链接:https://www.f2er.com/centos/382161.html

猜你在找的CentOS相关文章