0

I have build a phalcon MVC project, it runs fine on my local machine which is Ubuntu 18.04, while deploying on the server, CentOS 7, it throws this error. It's Phalcon v4. #0 /var/www/html/gadgetsplash/ui/public/index.php(46): Phalcon\Di->__call() #1 {main}

Below is index.php

<?php

use Phalcon\Di\FactoryDefault;

ini_set("date.timezone", "Africa/Nairobi");
ini_set('default_socket_timeout', 160);
ini_set('max_execution_time', 120);

define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

try {

    $di = new FactoryDefault();

    $config = $di->getConfig();

} catch (Exception $exception){
    error_log("error config: ".$exception->getTraceAsString());
    echo $exception->getTraceAsString();
    return;
}

try {

    include APP_PATH . '/config/router.php';

    include APP_PATH . '/config/services.php';

    include APP_PATH . '/config/loader.php';

    include "../vendor/autoload.php";

    $application = new \Phalcon\Mvc\Application($di);

    echo $application->handle($_SERVER['REQUEST_URI'])->getContent();
} catch (\Exception $e) {
    echo $e->getMessage() . '<br>';
    echo '<pre>' . $e->getTraceAsString() . '</pre>';
}

The error is thrown on try...catch here: $config = $di->getConfig(); This is the last part of my config file:

$configs['application'] = [
    'controllersDir' => APP_PATH . '/controllers/',
    'modelsDir' => APP_PATH . '/models/',
    'viewsDir' => APP_PATH . '/views',
    'cacheDir' => APP_PATH . '/cache/',
    'baseUri' => $baseUrl,
    'appDir' => APP_PATH . '/',
    'vendorDir' => APP_PATH . '/vendor/',
    'utilsDir' => APP_PATH . '/Utils/',
];

return new \Phalcon\Config($configs);
asega
  • 33
  • 8
  • What is the error/exception message? Using `try/catch` like that usually does more harm than good because it hides things and makes it really hard to debug. – Chris Haas Mar 13 '23 at 11:57
  • @ChrisHaas, the error is `Call to undefined method or service 'getConfig'` – asega Mar 13 '23 at 13:47
  • Looking at the [docs](https://docs.phalcon.io/5.0/en/api/phalcon_di#di-factorydefault), I'm not seeing that method listed. What should it return? – Chris Haas Mar 13 '23 at 14:03
  • @ChrisHaas configs set up on config.php – asega Mar 13 '23 at 14:18

1 Answers1

0

The config service has not been defined in your app. Try this after defining the container:

$di->set(
     'config',
     function () {
        return require_once('config.php');
     }
 );
Arthur
  • 398
  • 2
  • 7
  • Your answer wont work. The function `Phalcon\Config()` expects paramter type array, `require_once('config.php')` will return an int. This will throw an error instead. – asega Mar 15 '23 at 07:34
  • It all depends on how you define the content of `config.php`. The point is that your code doesn't work because it has not define the config service. There are many ways to define it, like in https://docs.phalcon.io/3.4/en/config#injecting-configuration-dependency So first define `$di` and then `set` the config service. – Arthur Mar 15 '23 at 08:44
  • It would be convenient if you share the code of your config file. – Arthur Mar 15 '23 at 08:53
  • I have edited the question and added of my config file. See the question above – asega Mar 15 '23 at 17:24
  • I have modified my answer based on your config.php file. Remember to update the path to `config.php` and add the `config` service just after declaring `$di`. – Arthur Mar 16 '23 at 08:04
  • the error I get: `==> /var/log/httpd/error_log <== [Fri Mar 17 10:07:56.177230 2023] [core:notice] [pid 15433] AH00052: child pid 12868 exit signal Segmentation fault (11)` – asega Mar 17 '23 at 09:08
  • If you use `die();` after `$config = $di->getConfig();` what happens? – Arthur Mar 17 '23 at 09:18