TL;DR: How to configure Phalcon if I don't want to run it under the root of the webserver?
I upgraded to version 4 and my websites stopped working. I have several websites running on the same host, as different instances of phalcon apps, under different directories. Let's say I want to create a new website:
$ cat /etc/issue
Ubuntu 18.04.3 LTS \n \l
$ cd /srv/www/html (this is the document root of https://172.18.0.90)
$ mkdir -p tools/foo/bar
$ cd tools/foo/bar
$ composer require phalcon/devtools
$ vendor/bin/phalcon -v
Phalcon DevTools (4.0.0)
Environment:
OS: Linux my.host.name 4.4.0-101-generic #124-Ubuntu SMP Fri Nov 10 18:29:59 UTC 2017 x86_64
PHP Version: 7.2.24-0ubuntu0.18.04.1
PHP SAPI: cli
PHP Bin: /usr/bin/php7.2
PHP Extension Dir: /usr/lib/php/20170718
PHP Bin Dir: /usr/bin
Loaded PHP config: /etc/php/7.2/cli/php.ini
Versions:
Phalcon DevTools Version: 4.0.0
Phalcon Version: 4.0.0
AdminLTE Version: 2.3.6
Now I create a new project:
$ vendor/bin/phalcon create-project example
When I go to https://172.18.0.90/tools/foo/bar/, I see:
Index of /tools/foo/bar
Name Last modified Size Description
Parent Directory -
composer.json 2019-12-27 10:02 62
composer.lock 2019-12-27 10:02 32K
example/ 2019-12-27 10:04 -
vendor/ 2019-12-27 10:02 -
Apache/2.4.29 (Ubuntu) Server at 172.18.0.90 Port 80
(Yes, indexing is enabled, just for debugging.) When I click into the 'example' directory, I see:
ToolsController handler class cannot be loaded
#0 [internal function]: Phalcon\Mvc\Dispatcher->throwDispatchException('ToolsController...', 2)
#1 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#2 /srv/www/html/tools/foo/bar/example/public/index.php(43): Phalcon\Mvc\Application->handle('/tools/foo/bar/...')
#3 {main}
So Phalcon is not aware that the root of the app is under tools/foo/bar/example. What is the proper way to configure this?
The 'baseUri' parameter must probably be set for the url service, but that doesn't affect the routing. Should I update .htrouter.php
? Or add a RewriteBase to .htaccess
? Or change the _url
somehow? Or should I set something in the router service, like a prefix?
I'm trying to understand how the routing/dispatching works, how the controller/action is selected, and I've been reading over the zep files but it's a lot of code and I'm not sure if I am looking in the right place. So instead of reverting to trial & error I thought it might be better to ask here. Can someone point me in the right direction?