在同一台电脑上使用bottlepy和php [英] Use bottlepy and php in the same computer

查看:26
本文介绍了在同一台电脑上使用bottlepy和php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用安装了 apache2 和 mod_wsgi 的 ubuntu 12.04.我想在我的本地计算机上使用 Bottlepy 和 php.我知道其他人已经问过这样的问题,如 Apache mod_wsgi 和 php 在同一个域中.但是有人建议我提出一个新问题,因为我的问题可能有所不同.

I use ubuntu 12.04 with apache2 and mod_wsgi installed. I want to use bottlepy and php in my local computer. I know such an issue is already asked by someone else as in Apache mod_wsgi and php in the same domain. But someone suggest me to make a new question since my problem could be different.

我已将 /etc/apache2/sites-available/default 更改为:

<VirtualHost *:80>
    ServerAdmin webmaster@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>

</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.我将我的 Bottlepy 应用程序放在 /home/gofrendi/workspace/kokoropy 中.我在包含此脚本的同一目录中有 kokoro.wsgi:

The first virtual host is for PHP, and the second one is for bottlepy. I put my bottlepy application in /home/gofrendi/workspace/kokoropy. And I have kokoro.wsgi in the same directory which contains this script:

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)

我已经通过使用启用配置

I've do enable the configuration by using

sudo a2ensite default
sudo service apache2 restart

我的 PHP 脚本仍然按预期工作.但是,每当我不知道如何访问我的 Bottlepy 脚本时.

My PHP scripts are still work as expected. But, whenever I don't know how to access my bottlepy script.

我也尝试删除 /etc/apache2/sites-available/default 的 PHP 部分,以便它只包含

I've also try to remove the PHP part of /etc/apache2/sites-available/default, so that it only consists of

<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>

但我仍然无法完成工作.它只是简单地显示 404 not found.

But I still can't get bottlepy work. It just simply show 404 not found.

有人有同样的经历吗?如何使它工作?谢谢.

Do anybody has the same experience? How to make it work? Thanks.

推荐答案

问题已解决.首先,我将 httpd.conf 设置(或在我的情况下为 /etc/apache2/sites-available/default)更改为:

The problem has been solved. First I change httpd.conf setting (or in my case /etc/apache2/sites-available/default) nto this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    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处理.

This configuration say that localhost/kokoropy should be handled by the wsgi.

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

My wsgi script is located at /home/gofrendi/workspace/kokoropy/kokoro.wsgi. kokoro.wsgi content is as follow:

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时发现sever内部错误,而访问php时没有发现错误,那可能是你wsgi出错了.只需打开 apache 日志(就我而言,它在这里:/var/log/apache2/error.log)

If you found internal sever error, when accessing bottlepy, but find no error when accessing php, that is probably some mistake in you wsgi. Just open up the apache log (in my case it is here: /var/log/apache2/error.log)

这篇关于在同一台电脑上使用bottlepy和php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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