Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...