We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Still can't use Phalcon from Class 'Phalcon\\Loader' Fatal Error

I had a little trouble installing Phalcon, but now I think I've got things up and running and it appears to all be installed right (I think). I checked and the phalcon.so extension is getting loaded. I was just testing out the first tutorial and copied the code for the bootstrap.php file and it throws a 500 http error, and when I look at the log file it just says.

mod_fcgid: stderr: PHP Fatal error: Class 'Phalcon\Loader' not found in /home/user/public_html/index.php on line 5

Here's the code for that file. (line 5 is $loader = new \Phalcon\Loader();)

<?php
        try {

            //Register an autoloader
            $loader = new \Phalcon\Loader();
            $loader->registerDirs(array(
                '../app/controllers/',
                '../app/models/'
            ))->register();

            //Create a DI
            $di = new Phalcon\DI\FactoryDefault();

            //Setting up the view component
            $di->set('view', function(){
                $view = new \Phalcon\Mvc\View();
                $view->setViewsDir('../app/views/');
                return $view;
            });

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

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

        } catch(\Phalcon\Exception $e) {
             echo "PhalconException: ", $e->getMessage();
        }
?>

There just isn't enough noobs like me posting these dumb questions. I'm really interested in testing out Phalcon as a framework, just need to get the dang thing to work.



98.9k

It seems the extension is not correctly loaded, can you try printing a phpinfo() and check if a section mentioning phalcon is in there?

Now I'm totally confused. After I installed Phalcon, I did phpinfo() and it didn't show up, but when I did get_loaded_extensions, phalcon was an entry that showed up. Now it's not showing in either of them. When I do a graceful restart of apache, I look through the error logs and it doesn't throw the error regarding anything of phalcon.so (or anything else really). It's not loading properly, but not setting off any red flags either.



18.6k
Accepted
answer

Phew! Got it. I had per-user php.ini config files and I finally found the right one. Now it loads up like a charm. I just needed to find the line in phpinfo() about where it was pulling the config from and I realized it was different....

Thanks for putting up with me. Flipping multiple php instances.....

Cool! Glad you got it sorted out



1.6k

I have also encounter the same problem. Can anyone help me to resolve this?

What you can do when you're on linux/mac os and you have phalcon "installed"..

  1. First locate the .so file: locate phalcon.so
  2. Copy the full path to that file
  3. open you're php.ini, and add the line extension="<path to phalcon.so>"
  4. Restart you're webserver