Hi guys,
I got an issue putting online a Multi Module Phalcon App on my Debian Wheezy VPS using Nginx 1.2.1, php-fpm and Mariadb. When I try to access my website, i got an "This webpage has a redirect loop" error.
This is my nginx conf file properly symlink in site-enabled:
server {
listen 80;
server_name l-huitre-pedagogique.com www.l-huitre-pedagogique.com;
root /var/www/l-huitre-pedagogique.com/public;
set $root_path '/var/www/l-huitre-pedagogique.com/public';
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/$1;
}
index index.php;
location ~ \.php$ {
try_files $uri =404;
root /var/www/l-huitre-pedagogique.com/public;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
error_log /var/log/nginx/test.lan-error.log;
}
this is my public/index.php:
<?php
use Phalcon\Mvc\Router,
Phalcon\Mvc\Application,
Phalcon\DI\FactoryDefault;
$environment = getenv("APPLICATION_ENV");
define("SITE_NAME", "L'Huître Pédagogique");
define("SEND_MAIL", true);
if ($environment == "development")
{
define("DOMAIN_NAME", "https://hp.local");
define("MAIL_ADMIN", "[email protected]");
define("MAIL_FROM_MAIL", "[email protected]");
define("MAIL_FROM_NAME", "Thanatos");
}
else
{
define("DOMAIN_NAME", "https://www.l-huitre-pedagogique.com");
define("MAIL_ADMIN", "[email protected]");
define("MAIL_FROM_MAIL", "[email protected]");
define("MAIL_FROM_NAME", "L'Huître Pédagogique");
}
$di = new FactoryDefault();
//Specify routes for modules
$di->set('router', function () {
$router = new \Phalcon\Mvc\Router\Annotations(\FALSE);
$router->removeExtraSlashes(\TRUE);
$router->setUriSource(
\Phalcon\Mvc\Router\Annotations::URI_SOURCE_SERVER_REQUEST_URI);
$router->setDefaultModule("www");
$router->addModuleResource("www", "Multiple\Apps\WWW\Controllers\Index", "/");
$router->add("/", array(
'module' => 'www',
'controller' => 'index',
'action' => 'index',
));
$router->notFound(array(
"controller" => "index",
"action" => "index"
));
$router->add("/admin/", array(
'module' => 'admin',
'controller' => 'index',
'action' => 'index',
));
$router->add("/admin/:controller", array(
'module' => 'admin',
'controller' => 1,
));
$router->add("/admin/:controller/:action", array(
'module' => 'admin',
'controller' => 1,
'action' => 2,
));
$router->add("/admin/:controller/:action/:params", array(
'module' => 'admin',
'controller' => 1,
'action' => 2,
'params' => 3,
));
$router->add("/admin/page/{page:[0-9]+}", array(
'module' => 'admin',
"controller" => "page",
"action" => "index",
));
$router->add("/admin/mailbox/{page:[0-9]+}", array(
'module' => 'admin',
"controller" => "mailbox",
"action" => "index",
));
$router->add("/admin/image/{page:[0-9]+}", array(
'module' => 'admin',
"controller" => "image",
"action" => "index",
));
$router->add("/admin/album/{page:[0-9]+}", array(
'module' => 'admin',
"controller" => "album",
"action" => "index",
));
$router->add("/page", array(
'module' => 'www',
"controller" => "index",
"action" => "list",
));
$router->add("/page/{page}", array(
'module' => 'www',
"controller" => "index",
"action" => "page",
));
$router->add("/album", array(
'module' => 'www',
"controller" => "index",
"action" => "album",
));
$router->add("/album/{album}", array(
'module' => 'www',
"controller" => "index",
"action" => "albumpage",
));
$router->add("/category/{category}", array(
'module' => 'www',
"controller" => "index",
"action" => "category",
));
$router->add("/category/{category}/{page}", array(
'module' => 'www',
"controller" => "index",
"action" => "categorypage",
));
$router->add("/about", array(
'module' => 'www',
"controller" => "index",
"action" => "about",
));
$router->add("/sitemap", array(
'module' => 'www',
"controller" => "index",
"action" => "sitemap",
));
$router->add("/bulletin", array(
'module' => 'www',
"controller" => "index",
"action" => "bulletin",
));
$router->add("/calendar/{year:[0-9]+}/{month:[0-9]+}", array(
'module' => 'www',
"controller" => "calendar",
"action" => "index",
));
$router->add("/calendar", array(
'module' => 'www',
"controller" => "calendar",
"action" => "index",
"year" => date('Y'),
"month" => date('m')
));
$router->add("/calendar/", array(
'module' => 'www',
"controller" => "calendar",
"action" => "index",
"year" => date('Y'),
"month" => date('m')
));
$router->add("/calendar/{year:[0-9]+}/{month:[0-9]+}/{day:[0-9]+}", array(
'module' => 'www',
"controller" => "calendar",
"action" => "event",
));
return $router;
});
//Set the database service
$di->set('db', function() {
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => "localhost",
"username" => "epi",
"password" => "secret",
"dbname" => "hp",
"options" => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
)
));
});
//Start the session the first time when some component request the session service
$di->setShared('session', function() {
$session = new Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
//Set up the flash service
$di->set('flashSession', function() {
return new \Phalcon\Flash\Session(array(
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'warning' => 'alert alert-warning',
'notice' => 'alert alert-info',
));
});
//Set up a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function() {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
Phalcon\Tag::setDocType(Phalcon\Tag::HTML5);
try {
//Create an application
$application = new Application($di);
// Register the installed modules
$application->registerModules(
array(
'www' => array(
'className' => 'Multiple\WWW\Module',
'path' => '../apps/www/Module.php',
),
'admin' => array(
'className' => 'Multiple\Admin\Module',
'path' => '../apps/admin/Module.php',
)
)
);
//Handle the request
echo $application->handle()->getContent();
} catch (\Exception $e) {
if ($environment == "development")
echo $e->getMessage();
else
header("Location: /");
}
and my apps/www/Module.php (frontend)
<?php
namespace Multiple\WWW;
use Phalcon\Loader,
Phalcon\Mvc\Dispatcher,
Phalcon\Mvc\View,
Phalcon\Mvc\ModuleDefinitionInterface;
class Module implements ModuleDefinitionInterface {
/**
* Register a specific autoloader for the module
*/
public function registerAutoloaders() {
$loader = new Loader();
$loader->registerNamespaces(
array(
'Multiple\WWW\Controllers' => '../apps/www/controllers/',
'Multiple\WWW\Models' => '../apps/www/models/',
'Multiple\WWW\Forms' => '../apps/www/forms/',
'Multiple\WWW\Helpers' => '../apps/www/helpers/',
)
);
$loader->register();
}
/**
* Register specific services for the module
*/
public function registerServices($di) {
//Registering a dispatcher
$di->set('dispatcher', function() {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Multiple\WWW\Controllers");
return $dispatcher;
});
//Registering the view component
$di->set('view', function() {
$view = new View();
$view->setViewsDir('../apps/www/views/');
return $view;
});
}
}
my apps/admin/Module.php is similar
thanks in advance for considering my request and thanks for give us this excellent framework!