I would like to know why when I clone my ZF2 project to a local machine to do some testing it completly stops working.
In my local machine I have two subfolders, one with a cakePHP project and the other with the ZF2 I've cloned.
The cakePHP project is working fine since it was there first, but the ZF2, when I try to access to the public folder it prints me:
{"error":"Something went wrong"}
A really generic error... I have no clue about what is going on.
I've tried some general debug attemps like
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
with no success at all, I've also checked the .htaccess RewriteBase directive to match my subfolder and the DB configuration is done too.
I have researched a bit in the project and the file which displays the error is module/RestfulV2_2/Module.php
(Reading the README.md
I've discovered is part of ZF2 Restful Module Skeleton):
/** * @param MvcEvent $e * @return null|\Zend\Http\PhpEnvironment\Response */ public function errorProcess(MvcEvent $e) { /** @var \Zend\Di\Di $di */ $di = $e->getApplication()->getServiceManager()->get('di'); $eventParams = $e->getParams(); /** @var array $configuration */ $configuration = $e->getApplication()->getConfig(); $vars = array(); if (isset($eventParams['exception'])) { /** @var \Exception $exception */ $exception = $eventParams['exception']; if ($configuration['errors']['show_exceptions']['message']) { $vars['error-message'] = $exception->getMessage(); } if ($configuration['errors']['show_exceptions']['trace']) { $vars['error-trace'] = $exception->getTrace(); } } if (empty($vars)) { $vars['error'] = 'Something went wrong'; } /** @var PostProcessor\AbstractPostProcessor $postProcessor */ $postProcessor = $di->get( $configuration['errors']['post_processor'], array('vars' => $vars, 'response' => $e->getResponse()) ); $postProcessor->process(); if ( $eventParams['error'] === \Zend\Mvc\Application::ERROR_CONTROLLER_NOT_FOUND || $eventParams['error'] === \Zend\Mvc\Application::ERROR_ROUTER_NO_MATCH ) { $e->getResponse()->setStatusCode(\Zend\Http\PhpEnvironment\Response::STATUS_CODE_501); } else { $e->getResponse()->setStatusCode(\Zend\Http\PhpEnvironment\Response::STATUS_CODE_500); } $e->stopPropagation(); return $postProcessor->getResponse(); }
The line which is calling the error in my index.php is:
Zend\Mvc\Application::init(require 'config/application.config.php')- run();
And the only line I found where the error function is called some way is this one in my modele.php
:
$sharedEvents->attach('Zend\Mvc\Application', MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'errorProcess'), 999);
Can you help me to solve this? I'm inexperienced with ZF2 but I know that with cakePHP to make it work you need to clear the cache folder. Is there any similar process in ZF2? Should I virtualize two servers to avoid conflics?
Thank you in advance.
EDIT : I've already made virtual hosts to avoid any possible conflict between my two frameworks but the error output is still the same.
EDIT2 : Here is my application.config.php file:
return array( // This should be an array of module namespaces used in the application. 'modules' => array( 'Restful', 'MvlabsSnappy', 'Qrcode', 'Application', 'RestfulV2', 'RestfulV2_2' ), // These are various options for the listeners attached to the ModuleManager 'module_listener_options' => array( // This should be an array of paths in which modules reside. // If a string key is provided, the listener will consider that a module // namespace, the value of that key the specific path to that module's // Module class. 'module_paths' => array( './module', './vendor', ), // An array of paths from which to glob configuration files after // modules are loaded. These effectively override configuration // provided by modules themselves. Paths may use GLOB_BRACE notation. 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), // Whether or not to enable a configuration cache. // If enabled, the merged configuration will be cached and used in // subsequent requests. //'config_cache_enabled' => $booleanValue, // The key used to create the configuration cache file name. //'config_cache_key' => $stringKey, // Whether or not to enable a module class map cache. // If enabled, creates a module class map cache which will be used // by in future requests, to reduce the autoloading process. //'module_map_cache_enabled' => $booleanValue, // The key used to create the class map cache file name. //'module_map_cache_key' => $stringKey, // The path in which to cache merged configuration. //'cache_dir' => $stringPath, // Whether or not to enable modules dependency checking. // Enabled by default, prevents usage of modules that depend on other modules // that weren't loaded. // 'check_dependencies' => true, ), // Used to create an own service manager. May contain one or more child arrays. //'service_listener_options' => array( // array( // 'service_manager' => $stringServiceManagerName, // 'config_key' => $stringConfigKey, // 'interface' => $stringOptionalInterface, // 'method' => $stringRequiredMethodName, // ), // ) // Initial configuration with which to seed the ServiceManager. // Should be compatible with Zend\ServiceManager\Config. // 'service_manager' => array(), );
2 Answers
Answers 1
First I would open index.php or whatever used as initial file (DirectoryIndex) and temporarily completely replace whole its content with something very base and simple, for example just these two lines:
<?php phpinfo();
And then make sure that it started to work after that - with that simple code which just displays your php configuration. So we'll find out that there is no error in server configurations, permissions and etc. and nothing prevents your script from run.
Then I would do the same at your old project location just to get phpinfo() from that place too and waste some time trying to compare them. Maybe you missed something important and you'll now see it.
If no - next step I would check your DB connectivity if your project uses any DB... also with some very simple commands like connect, bind, ....
And finally I'd try to restore original project content step by step from its begin, and look at which step it will fail. It doesn't matter that there maybe no any output - you may put echo __LINE__ . ' works!<br/>';
between blocks, so your index.php will look like:
<?php // original code block 1 echo __LINE__ . ' works!<br/>'; // original code block 2 echo __LINE__ . ' works!<br/>';
And you'll see in browser where it fails.
This is a very base description of my debug principals, but hope it will help.
Answers 2
The error could be anything. However, assuming the posted code is executed, it will suppress an error message without the correct configuration.
Try adding the following config to local.config.php
.
return [ 'errors'=> [ 'show_exceptions' => [ 'message' => true, 'trace' => true ], ], ];
If an exception is being thrown and that listener is catching it, then the $eventParams
is something you should debug.
0 comments:
Post a Comment