1

I'm trying to have ZF2 installed for all my subdomains at once (Ubuntu 12.04).

ZF2 just launched its first stable version, so I wanted to install it on my development server and finally get my hands dirty with it.

I downloaded ZF2 and unzipped the files in /var/ZF2/ (which now contains Zend/[all components]).

I then edited /etc/php5/apache2/php.ini and added the path to the ZF2 files:

include_path = ".:/var/ZF2"

I then downloaded the ZendSkeletonApplication and unzipped it in /var/www/skeleton.

I know it is suggested to composer.phar to install ZF2 application, but:

  • I don't want to make a local installation of ZF2... I want to make a server-wide installation be able to use my Zend components on all my domains/subdomains on my development server.

  • Before using any automatic installation process, I'd really like to understand that process by doing it manually at first.

Obviously, something goes wrong when I fire ZendSkeletonApplication, and I get the following when hit the following URL:

http://www.myDevServer.com/skeleton/public/

Fatal error: Uncaught exception 'RuntimeException' with message
'Unable to load ZF2. Run `php composer.phar install` or define 
a ZF2_PATH environment variable.' 
in /var/www/skeleton/init_autoloader.php:48 Stack trace: #0 
/var/www/skeleton/public/index.php(9): include() #1 {main} 
thrown in /var/www/skeleton/init_autoloader.php on line 48

I have skimmed through the docs, tutorials and the like, but there are no straight forward answer to this kind of configuration.

In the official doc, in the (very short) installation chapter, I see a reference to adding an include path in PHP. But no example...

http://zf2.readthedocs.org/en/latest/ref/installation.html

Once you have a copy of Zend Framework available, your application needs to be able to access the framework classes found in the library folder. Though there are several ways to achieve this, your PHP include_path needs to contain the path to Zend Framework’s library.

But then, when I get to the "Getting Started" chapter, it's all composer.phar and nothing else...

http://zf2.readthedocs.org/en/latest/user-guide/skeleton-application.html

I'm no sysAdmin, just a Zend enthusiast. I'm pretty sure this PEBKAC problem might be obvious for those who already got in ZF2 previous betas. Thanks for helping my out.


EDIT:

Problem was resolved, thanks to Daniel M.

Just setting up ZF2_PATH in httpd.conf was all that was needed.

SetEnv ZF2_PATH /var/ZF2

I also removed the include_path reference in php.ini and everything works just fine. So I have no idea why Zend suggested to include it there in their official docs.

2 Answers 2

1

Check init_autoloader.php in your application's base directory:

// Support for ZF2_PATH environment variable or git submodule
if (($zf2Path = getenv('ZF2_PATH') ?: (is_dir('vendor/ZF2/library') ? 'vendor/ZF2/library' : false)) !== false) {
    if (isset($loader)) {
        $loader->add('Zend', $zf2Path . '/Zend');
    } else {
        include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
        Zend\Loader\AutoloaderFactory::factory(array(
            'Zend\Loader\StandardAutoloader' => array(
                'autoregister_zf' => true
            )
        ));
    }
}

The simplest way is to set the ZF2_PATH env var. If you're running an apache web server, all you need to do this is mod_env. You can create a .htaccess file that sets the variable.

In case it still won't run, you can debug the init_autoloader.php file pretty easily.

2
  • Thank you for your answer. Is both PHP include_path and Apache environment variables necessary? Also, not being incredibly familiar with Apache2 mod_env, how do I go around to setting this up server-wide? I assume .htaccess is a good for individual vhost configuration, is it? (It's the only way I've used .htaccess before...).
    – kinologik
    Sep 14, 2012 at 15:57
  • Problem was resolved by setting up ZF2_PATH in httpd.conf. Thanks!
    – kinologik
    Sep 17, 2012 at 19:23
1

You could also use pyrus.phar to install. Read the info at http://packages.zendframework.com/ for a system wide install.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .