Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

securityPlugin problem on ubuntu

Hi Guys i used invo securityplugin in my project and it works fine when i run it on xampp but after uploading code on linux ubuntu i get this error

Fatal error: Uncaught Error: Class 'SecurityPlugin' not found in /var/www/html/master/app/config/services.php:24 Stack trace: #0 [internal function]: Closure->{closure}() #1 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault)) #2 [internal function]: Phalcon\Di->get('dispatcher', NULL) #3 [internal function]: Phalcon\Di->getShared('dispatcher') #4 /var/www/html/master/public/index.php(42): Phalcon\Mvc\Application->handle() #5 {main} thrown in /var/www/html/master/app/config/services.php on line 24

and it's not permision problem, projects witout securityplugin work fine

all folder and files are 777

services.php

<?php

use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Engine\Php as PhpEngine;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Flash\Direct as Flash;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Events\Manager as EventManager;
/**
 * Assign Plugins To Dispatcher
 */
$di->setShared('config', function () {
    return include APP_PATH . "/config/config.php";
});
$di->set(
    "dispatcher",
    function () {
        $eventManager = new EventManager();
        $eventManager->attach(
            "dispatch:beforeDispatch",
            new SecurityPlugin()
        );
        $dispatcher = new Dispatcher();
        $dispatcher->setEventsManager($eventManager);
        return $dispatcher;
    }
);

/**
 * Shared configuration service
 */
$di->setShared('config', function () {
    return include APP_PATH . "/config/config.php";
});

.
.
.

loader.php

<?php

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(
    [
        $config->application->controllersDir,
        $config->application->modelsDir,
        $config->application->libraryDir,
        $config->application->pluginsDir,
    ]
)->register();

config.php

<?php

defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');

return new \Phalcon\Config([
    'database' => [
        'adapter'     => 'Mysql',
        'host'        => 'localhost',
        'username'    => 'root',
        'password'    => '',
        'dbname'      => 'master',
        'charset'     => 'utf8',
    ],
    'application' => [
        'appDir'         => APP_PATH . '/',
        'controllersDir' => APP_PATH . '/controllers/',
        'modelsDir'      => APP_PATH . '/models/',
        'migrationsDir'  => APP_PATH . '/migrations/',
        'viewsDir'       => APP_PATH . '/views/',
        'pluginsDir'     => APP_PATH . '/plugins/',
        'libraryDir'     => APP_PATH . '/library/',
        'cacheDir'       => BASE_PATH . '/cache/',
        'baseUri'        => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),
    ]
]);


9.0k
Accepted
answer

Hi @MohammadRz check please if your SecurityPlugin class is in SecurityPlugin.php file be careful with uppercases. Is very common miss some uppercase in windows and then in linux don't find the file because linux is case sensitive.

Other posible problem your namespaces, check if SecurityPlugin have one or not.

Docs loader and namespaces

Good luck

Thank you!! SecurityPlugin was all in lowercase