使用PHP的Django / mod_wsgi WAMP

时间:2013-12-10 21:36:38

标签: php django apache wamp wampserver

我跟着this guide并设法完美地使用Django安装工作,但它似乎已经使所有本地托管的PHP站点无法访问,返回404错误。

的httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so

#This is placed right after the rule for <Directory "f:/WAMP/www/">
<Directory "f:/WAMP/www/python">
    Options ExecCGI
    AddHandler wsgi-script .py
    Order allow,deny
    Allow from all
</Directory>

#This is placed at the end of the file
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

Include "f:/WAMP/alias/*"
Include "F:/WAMP/www/python/sandbox/apache/apache_django_wsgi.conf"

apache_django_wsgi.conf

Alias /python/images/ "F:/WAMP/www/python/sandbox/images"
<Directory "F:/WAMP/www/python/sandbox/images">
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias /python "F:/WAMP/www/python/sandbox/apache/django.wsgi"

<Directory "F:/WAMP/www/python/sandbox/apache">
Allow from all
</Directory>

<VirtualHost *:80>
DocumentRoot f:/WAMP/www/python/sandbox/
ServerName 127.0.0.1
</VirtualHost>

django.wsgi

import os, sys

sys.path.append('F:/WAMP/www/python/sandbox')
os.environ['DJANGO_SETTINGS_MODULE'] = 'sandbox.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

PHP仅在我从httpd.conf注释掉最后一行时才会呈现。

1 个答案:

答案 0 :(得分:0)

如果您要设置DocumentRoot

,则需要另一个虚拟主机
# This is for PHP
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/
ServerName local.php.dev
</VirtualHost>

# This is for your Django stuff
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/python/sandbox/
ServerName local.py.dev
</VirtualHost>

否则,就像现在一样,所有本地请求都被发送到python沙箱。

请注意,您需要有多个主机指向本地。