2013-05-14 46 views
0

我使用安装了apache2和mod_wsgi的Ubuntu 12.04。 我想在我的本地计算机中使用bottlepy和php。 我知道这样的问题已被其他人问到,如Apache mod_wsgi and php in the same domain。 但有人建议我提出一个新的问题,因为我的问题可能会有所不同。在同一台计算机上使用瓶装和php

我已经改变/etc/apache2/sites-available/default到这一点:

<VirtualHost *:80> 
    ServerAdmin [email protected] 

    DocumentRoot /var/www 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
    </Directory> 
    <Directory /var/www/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog ${APACHE_LOG_DIR}/access.log combined 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 

</VirtualHost> 

<VirtualHost *> 
    DocumentRoot /home/gofrendi/workspace/kokoropy 
    ServerName oraiso 
    WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5 
    WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi 
    <Directory /home/gofrendi/workspace/kokoropy> 
     WSGIProcessGroup kokoropy 
     WSGIApplicationGroup %{GLOBAL} 
     Order deny,allow 
     Allow from all 
    </Directory> 
</VirtualHost> 

第一个虚拟主机是PHP,而第二个是bottlepy。 我把我的瓶装申请/home/gofrendi/workspace/kokoropy。通过使用

sudo a2ensite default 
sudo service apache2 restart 

我的PHP脚本预期仍在工作

import os 
sys.path = [os.path.dirname(__file__)] + sys.path 

from kokoropy import kokoro_init 
PWD = os.path.dirname(os.path.abspath(__file__)) 
APP_DIRECTORY = 'applications' 
APPLICATION_PATH = os.path.join(PWD, APP_DIRECTORY)  
application = kokoro_init(application_path = APPLICATION_PATH, run = False) 

我已经做到使配置生效:我有kokoro.wsgi其中包含此脚本的同一目录下。但是,每当我不知道如何访问我的瓶颈脚本。

我也尝试删除的/etc/apache2/sites-available/default PHP的一部分,所以它仅由

<VirtualHost *> 
    DocumentRoot /home/gofrendi/workspace/kokoropy 
    ServerName oraiso 
    WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5 
    WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi 
    <Directory /home/gofrendi/workspace/kokoropy> 
     WSGIProcessGroup kokoropy 
     WSGIApplicationGroup %{GLOBAL} 
     Order deny,allow 
     Allow from all 
    </Directory> 
</VirtualHost> 

但我仍然不能得到bottlepy工作。它只是简单地显示404没有找到。

任何人都有相同的经历吗?如何使它工作? 谢谢。

+0

您使用什么URL访问PHP站点以及Python站点的内容?根据你所显示的,Python站点应该被访问为'http:// oraiso/kokoropy'。那是你正在使用的? 'oraiso'是否为主机解决,或者您是否应该使用ServerName的FQDN。 – 2013-05-15 00:41:02

+0

我想php和oraiso python的本地主机 – goFrendiAsgard 2013-05-15 02:47:59

+0

但是你使用Python网站的确切URL是什么?你没有回答这个问题。 – 2013-05-15 06:54:44

回答

0

问题已解决。 首先,我改变httpd.conf中设置(或在我的情况/etc/apache2/sites-available/default)n要这样:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName localhost 

    DocumentRoot /var/www 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
    </Directory> 
    <Directory /var/www/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog ${APACHE_LOG_DIR}/access.log combined 

    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 


    # THIS IS WHERE I START TO EDIT IT: 
    # It tells apache about wsgi existance 
    WSGIDaemonProcess kokoropy user=www-data group=www-data processes=1 threads=5 
    WSGIScriptAlias /kokoropy /home/gofrendi/workspace/kokoropy/kokoro.wsgi 
    <Directory /home/gofrendi/workspace/kokoropy> 
     WSGIProcessGroup kokoropy 
     WSGIApplicationGroup %{GLOBAL} 
     Options ExecCGI 
     Order deny,allow 
     Allow from all 
    </Directory> 

</VirtualHost> 

此配置说localhost/kokoropy应该由WSGI处理。

我的wsgi脚本位于/home/gofrendi/workspace/kokoropy/kokoro.wsgi。 kokoro.wsgi内容如下:

import os, sys 
os.chdir(os.path.dirname(__file__)) 
sys.path = [os.path.dirname(__file__)] + sys.path 

from bottle import default_app 
@route('/') 
def index(): 
    return 'run with apache' 
application = default_app() 

如果您发现内部服务器错误,访问bottlepy的时候,但访问PHP时发现没有错误,这可能是一些错误在你WSGI。只需打开apache日志(在我的情况下,它在这里:/var/log/apache2/error.log

相关问题