【问题标题】:Installing the Zend Framework 2 (Skeleton) on cPanel在 cPanel 上安装 Zend Framework 2 (Skeleton)
【发布时间】:2016-01-11 02:38:51
【问题描述】:

试图掌握并在 Zend 2 中创建一个非常基本的入门站点。首先,我通过 Softaculous 安装了 Zend 2,但它安装了一个非常基本的 shell。所以离开了,因为我不确定这是最好的选择。

其次,我从 Github 下载了 Zend 2 Skeleton。在我的服务器上提取了这个。但是,当我尝试转到 index.php 时,它给出了损坏的路径错误。

请问我在哪里可以更改 cPanel 文件管理器中的路径? (我无权访问作曲家的命令行,并且将路径放入 init 文件中不起作用)

致命错误: 未捕获异常“RuntimeException”,消息“无法加载 ZF2。运行 php composer.phar install 或定义 ZF2_PATH 环境变量。在 /home/****/public_html/zf2-tutorial/init_autoloader.php:51 堆栈跟踪:#0 /home/****/public_html/zf2-tutorial/public/index.php(18):需要( ) #1 {main} 在第 51 行的 /home/****/public_html/zf2-tutorial/init_autoloader.php 中抛出

【问题讨论】:

    标签: php zend-framework zend-framework2 cpanel


    【解决方案1】:

    检查应用程序基目录中的init_autoloader.php 文件。你可能有以下代码:

    if (file_exists('vendor/autoload.php')) {
        $loader = include 'vendor/autoload.php';
    }
    
    if (class_exists('Zend\Loader\AutoloaderFactory')) {
        return;
    }
    
    $zf2Path = false;
    
    if (is_dir('vendor/ZF2/library')) {
        $zf2Path = 'vendor/ZF2/library';
    } elseif (getenv('ZF2_PATH')) {      // Support for ZF2_PATH environment variable or git submodule
        $zf2Path = getenv('ZF2_PATH');
    } elseif (get_cfg_var('zf2_path')) { // Support for zf2_path directive value
        $zf2Path = get_cfg_var('zf2_path');
    }
    
    if ($zf2Path) {
        if (isset($loader)) {
            $loader->add('Zend', $zf2Path);
            $loader->add('ZendXml', $zf2Path);
        } else {
            include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
            Zend\Loader\AutoloaderFactory::factory(array(
                'Zend\Loader\StandardAutoloader' => array(
                    'autoregister_zf' => true
                )
            ));
        }
    }
    
    if (!class_exists('Zend\Loader\AutoloaderFactory')) {
        throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
    }
    

    所以,你必须设置ZF2_PATH env var。如果在服务器上的 Apache 中启用了 mod_env,那么只需在 .htaccess 文件中添加 SetEnv 指令。

    请参考以下链接:

    Zend Framework 2 installation

    Zend Framework 2 - Beginners Tutorial - Apache server config

    How to give zend library path in our application?

    【讨论】:

    • 谢谢。在骨架应用程序中,没有 lib 或库文件夹((只是 config/data/module/public),所以不确定在路径中放什么。我假设,包括 public,因为它是 public/index.php 我正在尝试访问并产生错误。
    猜你喜欢
    • 2015-09-22
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    相关资源
    最近更新 更多