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

public/index/index not found

I've always developed using a WAMP stack and am in the process of learning how to do the same thing in Linux (Ubuntu 14.04). So I suspect my problem is related to how I've set up Apache and/or virtual hosts.

Here's my virutal host file located at /etc/apache2/sites-available/mysite.conf:

<VirtualHost *:80>
    ServerName mysite

    ServerAdmin [email protected]
    DocumentRoot /var/www/mysite

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/mysite/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

Whenever I go to https://mysite/index, https://mysite/index/index or https://mysite/index/login I get a 404 error, but not when I go to https://mysite or https://mysite/articles. I verified that both mod_rewrite and Phalcon are enabled, and I made sure 127.0.0.1 mysite was in my hosts file. I have an IndexController and an ArticleController in app/controllers.

Here's the file at /var/www/mysite/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ public/ [L]
    RewriteCond %{REQUEST_URI} !^/forums.*
    RewriteRule (.*) public/$1 [L]
</IfModule>

/var/www/mysite/public/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

/var/www/mysite/public/index.php:

<?php

try {

    $config = new Phalcon\Config\Adapter\Ini('../app/config/config.ini');

    $loader = new Phalcon\Loader();

    $loader->registerDirs(array(
        $config->application->controllersDir,
        $config->application->modelsDir
    ))->register();

    $di = new Phalcon\DI\FactoryDefault();

    $di->set('config', $config);

    $di->set('db', function () use ($config) {
        return new Phalcon\Db\Adapter\Pdo\Mysql(array(
            'host' => $config->database->host,
            'username' => $config->database->username,
            'password' => $config->database->password,
            'dbname' => $config->database->dbname,
            'charset' => 'utf8'
        ));
    });

    $di->set('session', function() {
        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });

    $di->set('url', function () use ($config) {
        $url = new Phalcon\Mvc\Url();
        $url->setBaseUri($config->application->baseUri);
        return $url;
    });

    $di->set('view', function () use ($config) {
        $view = new Phalcon\Mvc\View();
        $view->setViewsDir($config->application->viewsDir);
        return $view;
    });

    $application = new Phalcon\Mvc\Application($di);

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

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

/var/www/mysite/app/controllers/IndexController.php

<?php

use Phalcon\Mvc\Controller;

class IndexController extends Controller
{

    public function indexAction()
    {}

    public function loginAction()
    {}

}

/var/www/mysite/app/config/config.ini:

[database]
host     = localhost
username = root
password = 
dbname   = mysite

[application]
baseUri        = /
controllersDir = ../app/controllers/
modelsDir      = ../app/models/
viewsDir       = ../app/views/