How do I run Django and PHP together on one Apache server?

戏子无情 提交于 2019-11-27 05:59:54

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.

Your WSGIScriptAlias / ... directive is telling Apache that everything request starting with "/" should get fed through Django's WSGI handler. If you changed that to read WSGIScriptAlias /django-proj/ ... instead, only requests starting with "/django-proj" would get passed into Django.

An alternative would be to start setting up virtual hosts for each project. This way you could configure Apache to put each project at the / of it's own domain, and you wouldn't need to worry about the configuration for one project affecting one of your other projects.

I had the same problem. Try removing this block <Directory /> in httpd-conf.

Include httpd-vhost.conf and and try puting my WSGIScriptAlias / "/somewhere/file.wsgi" in virtual host section of httpd-vhosts which listens to port 80.

I would like to add that if you are using Apache ProxyPass, it's possible to deny certain URL patterns so that it falls to mod_php.

ProxyPass /wordpress !
<Location /wordpress>
    Require all granted
</Location>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!