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.