Deploying

I just upload my app to production web server and that's what I've got: ```log A dependency injection object is required to access internal services

0 /var/www/public/index.php(30): Phalcon\Mvc\Application->handle()

1 {main}

``` But on localhost everything is ok. Any ideas?

And also I wanna ask, maybe somebody knows how to translate .htaccess to lighttpd config? Maybe other production-related tricks?

This error means that u didn't initialize and pass into application DI object (Application requires it, Phalcon\Mvc\Application->setDI())

I finish up with updating Phalcon from 1.0.1 to 1.1.0 on the server.



18.0k

Hi, I have the same issue here with Ubuntu server 12.04 PHP 5.4.11 and apache 2.

My application works very fine in my own environment, but when I put it online I get this error :

A dependency injection object is required to access internal services

I can't see what is wrong. I installed Phalcon and it's appear correctly in my phpinfo() loaded module.

Here's my index.php code :

<?php

errorreporting(EALL);

try {

/**
 * Read the configuration
 */
$config = include __DIR__ . "/../app/config/config.php";

/**
 * Read auto-loader
 */
include __DIR__ . "/../app/config/loader.php";

/**
 * Read services
 */
include __DIR__ . "/../app/config/services.php";

/**
 * Handle the request
 */
$application = new \Phalcon\Mvc\Application($di);

echo $application->handle()->getContent();

} catch (\Exception $e) { echo $e->getMessage(); }

And where is $di var initialization ?



18.0k

In the services.php file :

<?php

use Phalcon\DI\FactoryDefault, Phalcon\Mvc\View, Phalcon\Mvc\Url as UrlResolver, Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter, Phalcon\Mvc\View\Engine\Volt as VoltEngine, Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter, Phalcon\Session\Adapter\Files as SessionAdapter;

/** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault();

/** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function() use ($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true);

/** * Setting up the view component */ $di->set('view', function() use ($config) {

$view = new View();

$view->setViewsDir($config->application->viewsDir);

$view->registerEngines(array(
    '.volt' => function($view, $di) use ($config) {

        $volt = new VoltEngine($view, $di);

        $volt->setOptions(array(
            'compiledPath' => $config->application->cacheDir,
            'compiledSeparator' => '_'
        ));

        return $volt;
    },
    '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
));

return $view;

}, true);

/** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function() use ($config) { return new DbAdapter(array( 'host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname )); });

/** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function() { return new MetaDataAdapter(); });

/** * Start the session the first time some component request the session service */ $di->set('session', function() { $session = new SessionAdapter(); $session->start(); return $session; });

Try change: ```php $di = new FactoryDefault(); ``` to: ```php $di = \Phalcon\DI::getDefault(); ```

But i didn't think, that this will help... Try to check full flow (with xdebug or trace output). Maybe you trying to reach DI in config.php or loader.php ?



18.0k

This the dump of my DependencyInjector. Is this normal that everything is null ?

object(Phalcon\DI\FactoryDefault)[5] protected 'services' => array (size=7) 'url' => object(Phalcon\DI\Service)[25] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null 'config' => object(Phalcon\DI\Service)[24] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null 'volt' => object(Phalcon\DI\Service)[23] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null 'view' => object(Phalcon\DI\Service)[22] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null 'db' => object(Phalcon\DI\Service)[21] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null 'modelsMetadata' => object(Phalcon\DI\Service)[20] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null 'session' => object(Phalcon\DI\Service)[19] protected 'name' => null protected 'definition' => null protected 'shared' => null protected 'sharedInstance' => null protected 'sharedInstances' => null protected '_freshInstance' => boolean false



18.0k

By the way the application is crashing there :

echo $application->handle()->getContent();

before this line everything is fine.



83.4k

@dlusignan what version are you using?



18.0k

PHP Version 5.4.11 Apache/2.2.22 (Ubuntu)

phalcon Phalcon Framework enabled Phalcon Version 1.2.3



83.4k

could you please compile from master again?



18.0k

The compilation I have done one the server is from 32 bits folder. The master gave me an error about lib tool.



18.0k

Yes, the server is 64 bits.



18.0k

Ha ! That was my problem, I recompiled in 64bits and "Now, I'm flying with Phalcon". Our first Phalcon tool in the company. We're migrating from Zend to Phalcon. :)



83.4k