Apache给出"没有这样的文件或目录"尝试运行cgi时出错

时间:2015-08-14 18:48:50

标签: apache ubuntu cgi

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

我现在遇到的主要错误是什么。尝试运行自定义CGI,cgi目前在我拥有的另一台服务器上成功运行,但似乎我忽略了这台服务器上的一些配置选项。

我将cgi-bin目录设置为允许CGI执行:

root@jp:/usr/lib/cgi-bin# ls -lah

total 16K
drwxr-xr-x  2 root www-data 4.0K Aug 14 18:28 .
drwxr-xr-x 64 root root     4.0K Oct 28  2014 ..
-rwxrwxrwx  1 root www-data  505 Aug 14 18:20 haml.cgi

我已将haml.cgi的权限设置为777,只是为了消除任何权限问题:

root@jp:/etc/apache2# ls mods-enabled/
access_compat.load  alias.load       authz_core.load  autoindex.load  deflate.load  filter.load     mpm_event.load    setenvif.load
actions.conf        auth_basic.load  authz_host.load  cgid.conf       dir.conf      mime.conf       negotiation.conf  status.conf
actions.load        authn_core.load  authz_user.load  cgid.load       dir.load      mime.load       negotiation.load  status.load
alias.conf          authn_file.load  autoindex.conf   deflate.conf    env.load      mpm_event.conf  setenvif.conf

我启用了cgid:

DocumentRoot /home/j/web/
DirectoryIndex index.haml index.html
<Directory "/home/j/web">
    AllowOverride All
    Allow from All
    Options +ExecCGI
</Directory>

我的网站本身设置为exec cgi:

<?php
require_once('connection.php');

define( "APP_NAME", "Edarati");

session_start();

if(!isset($_SESSION['name'])) {
    require_once('controllers/login_controller.php');
    require_once('models/user.php');
    $login = new LoginController();

    $login->login();

    if (isset($_GET['action']) && $_GET['action'] == 'register') {
        $login->register();
    }
} else {

    // logging out
    if(isset($_GET['action'])) {
        if ($_GET['action'] == 'logout') {
            require_once('controllers/login_controller.php');
            require_once('models/user.php');
            $login = new LoginController();

            $login->logout();
            header('Location:index.php');
        }
    }

    if (isset($_GET['controller']) && isset($_GET['action'])) {
        $controller = $_GET['controller'];
        $action     = $_GET['action'];
    } else {
        $controller = 'pages';
        $action     = 'home';
    }

    require_once('views/layout.php');
    ?>
}

If you need to see any other file or bit of code let me know!

<b>login_controller.php</b>

    <?php
    class LoginController {
        public function login() {
            require_once('views/login/login.php');
            if(isset($_POST['login'])) {
                $usr = new User;
                $usr->storeFormValues( $_POST );

                if( $usr->userLogin() ) {
                    $_SESSION['name'] = $usr->username;
                    header('Location:index.php');

                } else {
                    // TODO error page
                    echo "error syntaxe page teet teet"; // didnt work idk why
                }
            }
        }

        public function register() {
            require_once('views/login/register.php');
            if(isset( $_POST['register'])) {
                $usr = new User;
                $usr->storeFormValues( $_POST );

                if( $_POST['password'] == $_POST['conpassword'] ) {
                    echo $usr->register($_POST);
                } else {
                    echo "Password and Confirm password not match";
                }
            }
        }
        public function logout() {
            session_start();
            session_unset();
            session_destroy();
        }
    }

我在这里遗漏了什么?知道为什么CGI没有运行吗?

1 个答案:

答案 0 :(得分:0)

结束实际上我的红宝石装置给了我一些问题。直接运行cgi向我展示了这个:

root@jp:/usr/lib/cgi-bin# ./haml.cgi
bash: ./haml.cgi: /usr/bin/ruby: bad interpreter: No such file or directory