如何在一个Apache服务器上一起运行Django和PHP? [英] How do I run Django and PHP together on one Apache server?

查看:263
本文介绍了如何在一个Apache服务器上一起运行Django和PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过mod_wsgi或PHP在Apache服务器上运行Django。



我的Django项目运行于: http:// localhost ,源代码是C:/ django_proj



我的PHP项目运行于: http://php.localhost ,源代码是C:/ web



如果我转两个,php.localhost和localhost都去Django项目。我已经通过Apache虚拟主机进行了设置。



以下是httpd.conf中的一些相关行:

  DocumentRootC:/ web

< Directory />
选项FollowSymLinks
AllowOverride无
订单拒绝,允许
拒绝所有
< / Directory>

<目录C:/ web>
选项索引FollowSymLinks
AllowOverride无
订单允许,拒绝
允许从所有
< / Directory>

<目录C:/ django_proj>
订单允许,拒绝
允许从所有
< / Directory>

包含C:/django_proj/apache/apache_django_wsgi.conf

apache_django_wsgi.conf 中的相关行是:

  WSGIScriptAlias /C :/django_proj/apache/proj.wsgi
< DirectoryC:/ django_proj / apache>
订单允许,拒绝
允许从所有
< / Directory>

内部httpd-vhosts.conf:

 <目录C:/ web> 
订单拒绝,允许
允许从所有
< / Directory>

<目录C:/ django_proj>
订单拒绝,允许
允许从所有
< / Directory>

< VirtualHost *:80>
DocumentRootC:/ django_proj
ServerName localhost
< / VirtualHost>

< VirtualHost *:80>
DocumentRootC:/ web
ServerName php.localhost
< / VirtualHost>

我的PHP项目目前无法访问。有没有人有任何想法我失踪了?

解决方案

我运行了几十个mod_wsgi / Django网站,PHP网站和一个Rails网站使用单个Apache。



主要是使用虚拟主机完成,但我有一些在同一个域上运行。



您只需在其他位置/别名指令之后放入 WSGIScriptAlias /...



例如,我想在与Django网站相同的域上运行phpMyAdmin。配置将如下所示:

 别名/ phpmyadmin / full / path / to / phpmyadmin / 
<目录/ full / path / to / phpmyadmin>
选项-Indexes
...等...
< / Directory>

WSGIScriptAlias / /full/path/to/django/project/app.wsgi
< Directory / full / path / to / django / project>
选项+ ExecCGI
...等...
< / Directory>

修改



您的配置应该如下所示:

 < VirtualHost *:80& 
DocumentRootC:/ django_proj
ServerName localhost
WSGIScriptAlias /C:/django_proj/apache/proj.wsgi
< DirectoryC:/ django_proj / apache >
选项+ ExecCGI
订单允许,拒绝
允许从所有
< / Directory>
< / VirtualHost>

< VirtualHost *:80>
DocumentRootC:/ web
服务器名称php.localhost
别名/ C:/ web
<目录C:/ web>
选项索引FollowSymLinks
AllowOverride无
订单拒绝,允许
允许从所有
< / Directory>
< / VirtualHost>

您不需要这些< Directory> 指令 http.conf ...在虚拟主机中进行所有配置。



另外,完全摆脱< Directory /> 块。


I can currently run either Django through mod_wsgi or PHP on my Apache server.

My Django projects run at: http://localhost and source is at C:/django_proj

My PHP projects run at: http://php.localhost and source is at C:/web

If I turn both on, php.localhost and localhost go to the Django project. I've already set them up through Apache virtual hosts.

Here are some relevant lines in httpd.conf:

DocumentRoot "C:/web"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory "C:/web">
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<Directory "C:/django_proj">
    Order allow,deny
    Allow from all
</Directory>

Include "C:/django_proj/apache/apache_django_wsgi.conf"

The relevant lines in apache_django_wsgi.conf is:

WSGIScriptAlias / "C:/django_proj/apache/proj.wsgi"
<Directory "C:/django_proj/apache">
    Order allow,deny
    Allow from all
</Directory>

Inside httpd-vhosts.conf:

<Directory C:/web>
    Order Deny,Allow
    Allow from all
</Directory>

<Directory C:/django_proj>
    Order Deny,Allow
    Allow from all
</Directory>

<VirtualHost *:80>
    DocumentRoot "C:/django_proj"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/web"
    ServerName php.localhost
</VirtualHost>

My PHP project is current inaccessible. Does anyone have any ideas what I'm missing?

解决方案

I run dozens of mod_wsgi/Django sites, PHP sites, and a Rails site with a single Apache.

It's mostly done using virtual hosts but I have some that are running both on the same domain.

You just need to put your WSGIScriptAlias /... after any other Location/Alias directives.

Lets say, for example, I want to run phpMyAdmin on the same domain as a Django site. The config would look something like this:

Alias /phpmyadmin /full/path/to/phpmyadmin/
<Directory /full/path/to/phpmyadmin>
   Options -Indexes
   ...etc...
</Directory>

WSGIScriptAlias / /full/path/to/django/project/app.wsgi
<Directory /full/path/to/django/project>
    Options +ExecCGI
    ...etc...
</Directory>

Edit:

Your configuration should look something like this:

<VirtualHost *:80>
    DocumentRoot "C:/django_proj"
    ServerName localhost
    WSGIScriptAlias / "C:/django_proj/apache/proj.wsgi"
    <Directory "C:/django_proj/apache">
        Options +ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/web"
    ServerName php.localhost
    Alias / C:/web
    <Directory C:/web>
        Options Indexes FollowSymLinks
        AllowOverride None
        Order Deny,Allow
        Allow from all
    </Directory>
</VirtualHost>

You don't need those <Directory> directives in http.conf... do all your configuration in the Virtual hosts.

Also, completely get rid of the <Directory /> block.

这篇关于如何在一个Apache服务器上一起运行Django和PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆