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

2 phalcon projects on subdomain not working no mapping

I have one website, let's call it www.main.com, which is located on the server at /home4/username/public_html/. This site is running Phalcon PHP with no issues at all.

I have also made a subdomain, let's call it test.main.com, and used cPanel to set the route for the subdomain to /home4/username/testsite/. This is where the problem is.

Both /public_html and /testsite have their own .htaccess files, and in each directory there is a phalcon project, the /public_html directory containing the project folder /public_html/main and the /testsite containing the project folder /testsite/test.

The file structure of the server with the two projects is as follows:

home4/
|---- username/
       |---- public_html/
       |       |---- .htaccess
       |       |---- main/
       |              |---- app/
       |              |     |---- controllers/
       |              |     |      |---- indexController.php
       |              |     |---- views/
       |              |     |      |---- index.phtml
       |              |     |---- models/
       |              |---- public/
       |                     |---- .htaccess
       |                     |---- index.php
       |---- testsite/
              |---- .htaccess
              |---- test/
                     |---- app/
                     |     |---- controllers/
                     |     |      |---- indexController.php
                     |     |---- views/
                     |     |      |---- index.phtml
                     |     |---- models/
                     |---- public/
                            |---- .htaccess
                            |---- index.php

The .htaccess files are as follows:

test site:

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteRule  ^$ test/public/    [L]
        RewriteRule  ((?s).*) test/public/$1 [L]
</IfModule>

main site:

<IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteRule  ^$ main/public/    [L]
        RewriteRule  ((?s).*) main/public/$1 [L]
</IfModule>

And testing the test site locally via XAMPP it works fine (currently just a very VERY simple Phalcon test page). But when I upload the exact same site to the server phalcon errors with: PhalconException: IndexController handler class cannot be loaded

And the stack trace for the error is: #0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2) #1 [internal function]: Phalcon\Dispatcher->_dispatch() #2 [internal function]: Phalcon\Dispatcher->dispatch() #3 /home/username/testsite/test/public/index.php(31): Phalcon\Mvc\Application->handle() #4 {main}

The dispatch index.php file for the (non-working) test subdomain site contains the following (but note, this file works perfectly on a local XAMPP server, only on the remote shared server does it not work):

<?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();

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

      //Setup a base URI
      $di->set('url', function(){
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/test/');
        return $url;
      });

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

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

    } catch(\Phalcon\Exception $e) {
      echo "PhalconException: ", $e->getMessage();
      echo "<br /><br /><strong>Trace Stack</strong>: ", $e->getTraceAsString();
    }

Now this is baffling, as I said, there's no reason code wise the Phalcon project is wrong, as it works fine locally. So the only thing I can think of is somehow the routing of the subdomain is screwing things up. However I have also tried putting a simple <?php phpinfo() ?> inside /test/public/php_info.php which works perfectly fine when accessing via test.main.com/php_info.php so the .htaccess file is routing as it should.

Is there something wrong with the way things are being routed in phalcon, seen as the test site can't seem to find the controllers folder. Or can phalcon only run one project on one server? I honestly have no idea why it doesn't work.

Thanks, although whilst this is currently a subdomain I also have a seperate domain (e.g. www.other.com) which maps to a /other on this shared server which is the real purpose of hosting this. So I'm not sure I want to host multiple modules in one phalcon projects... Is it not possible to run 2 sites from 2 different directories on the server as 2 seperate phalcon projects??

no idea if this would help you

https://forum.phalcon.io/discussion/52/subdomain-routing-and-link-generation

https://stackoverflow.com/questions/30320879/phalcon-subdomain-routing



85.5k

well i dont know the story ( and the target ) but i am 90% sure what you have in mind is wrong. And you should not be doing it. I guess the router is depending on the domain, but i am not sure.

do the 2n project on complatly different domain and proxy pass it with apache / nginx



5.1k
edited Jun '17

I had the same worries i solved it in index.php


define('BASE_PATH', dirname(__DIR__));
$loader->registerDirs(array(
      BASE_PATH .  '/../app/controllers/',
       BASE_PATH . '/../app/models/'
      ))->register();

Dump BASE_PATH to see and complete the path



3.0k
Accepted
answer

So it turned out to be something really simply stupid. For some reason using phalcon locally via XAMPP on Windows allowed me to use indexController.php as a controller name. However, when uploaded to the Apache server the name needed to be capitalised in full camel case to IndexController.php to work.

edited Jun '17

One more Windows fu## up. Well, not to blame Windows directly but rather (mis)understanding of the basics. And we do have containers and stuff these days with one main goal - to simulate production environment and to avoid this kind of issues.



9.7k

Windows file names are semantic, therefore case insensitive. indexController.php and indexController.php mean the same thing, as you would expect from them having the same spelling. Linux does not have that feature in the default file system.

This is one of the really difficult things to explain to Web site owners. Most of the URL is defined as case insensitive but the path part depends on the file system used. Whoever defined URLs forgot to define the whole URL as case insensitive.