doucaishi0077 2015-11-19 04:49
浏览 42


I run a php-based web site (shopping mall) on nginx web server. recently I heard that phalcon is very fast and reliable framework, helping developer speed up the dev process.

So I wanted to implement it to my site, starting as a submodule for specific services for it's hard to start from the scratch.

I want to create a subfolder (let's say "phalcontest") under the /var/www .

I googled about this topic, but all(maybe?) the contents I found on the net were to set nginx server as a dedicated site for phalcon project (I mean, make "the project" folder as a web root), nothing about making phalcon project coexist with old non-phalcon pages.

I tried nginx configuration something like this, hoping it's ok:

 server {
     listen       80;
     root /var/www/;
     index index.html index.htm index.php;

     server_name localhost;

     access_log  /var/log/nginx/access.log main buffer=16k;
     error_log  /var/log/nginx/error.log;

 location @rewrite {
     rewrite ^(.*)$ phalcontest/index.php?_url=$1;

 location / { 
         try_files $uri $uri/ /index.php?q=$uri&$args;

 location ~ \.php$ {
  try_files      $uri = 404;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include        fastcgi_params;

  fastcgi_split_path_info  ^(.+\.php)(/.+)$;
  fastcgi_param PATH_INFO       $fastcgi_path_info;
  fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

location /phalcontest {
     try_files $uri $uri/ @rewrite;

 location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
     root /var/www/;


to make "phalcontest" folder to be a phalcon-enabled subfolder under webroot.

After that I created phalcontest with phalcon devtools,

and accessed http://localhost/phalcontest/public, it shows:

Congratulations! You're now flying with Phalcon. Great things are about to happen! This page is located at views/index/index.phtml

but when I accessed http://localhost/phalcontest, it shows:

Mod-Rewrite is not enabled

Please enable rewrite module on your web server to continue

this means that I've done something wrong and I can only access via public folders, not the folder itself.

Please help me how to let phalcon live with existing php-based site!

  • 写回答

1条回答 默认 最新

  • donglizuo8892 2015-11-19 06:14

    The way that Phalcon is supposed to work is that it rewrites all traffic aimed at your web root / to the /public/ directory. The point of this is that it enables you to essentially hide the /app/ directory from web view since the user's request would first be rewritten to /public/app/ thus encountering a 404 which gets rewritten to /public/index.php where it would look for the controller "App". If you're going to run Phalcon from a subdirectory, you'll need to change all / to /phalcontest/.

    I see you're using root /var/www/;.
    So in your case, you'll want a directory structure like so:


    Make sure to rewrite all requests aimed at phalcontest(/.*)? to phalcontest/public/$1 then from there rewrite them to index.php if the requested file or directory doesn't exist.

    Here's a tool for converting .htaccess to nginx if it's any help:

    Honestly, you don't need to follow their directory structure so perfectly. You only really need the rewrite logic to rewrite all traffic to your index.php file. The parts regarding Phalcon's proposed /public/ directory, you don't need a /public/ directory if you simply move your /app/ directory below the web root, then reference its location properly from your index.php file.

    Phalcon gives you a lot of information regarding how to setup the rewriting for nginx over here:

    But since you're working from your localhost, I'd suggest creating a subdomain on the localhost using your hosts file. Then you can work from the / web root and access your project from http://phalcontest.localhost/. Then you'd use server_name phalcontest.localhost; in your nginx configuration rather than server_name localhost; and aim its root at root /var/www/phalcontest; For your hosts file you'd add a line: phalcontest.localhost That will save you from a DNS look up so the subdomain gets tied to your localhost. See nginx subdomain configuration and How to test nginx subdomains on localhost.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题