2
votes

Trying to get to grips and make a very basic starter site in Zend 2. Firstly, I installed Zend 2 via Softaculous, but that has installed a very basic shell. So have left that as I am not sure this is the best thing to go with first.

Secondly, I have downloaded the Zend 2 Skeleton from Github. Extracted this on my server. However when I try to go to index.php it gives broken path error.

Where can I change the path in cPanel File Manager please? (I don't have access to command line for composer and putting path in init file doesn't work)

Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run php composer.phar install or define a ZF2_PATH environment variable.' in /home/****/public_html/zf2-tutorial/init_autoloader.php:51 Stack trace: #0 /home/****/public_html/zf2-tutorial/public/index.php(18): require() #1 {main} thrown in /home/****/public_html/zf2-tutorial/init_autoloader.php on line 51

1

1 Answers

0
votes

Check init_autoloader.php file in application base directory. You may have the following code:

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.');
}

So, you have to set ZF2_PATH env var. If mod_env is enabled in Apache on the server then just add the SetEnv directive in your .htaccess file.

Please refer following links:

Zend Framework 2 installation

Zend Framework 2 - Beginners Tutorial - Apache server config

How to give zend library path in our application?