cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

nginx config

Open white87332 opened this issue 14 years ago • 3 comments

Hello, how can i setup phalcon app in nginx environment?Thank you

I get the message : PhalconController handler class cannot be loaded

My nginx config:

user nobody;

(max_clients = worker_processes * worker_connections)

worker_processes 1;

error_log logs/error.log;

pid logs/nginx.pid;

events { worker_connections 1024; }

http { index index.php index.html index.htm; include mime.types; include fastcgi.conf; default_type application/octet-stream; server_tokens off;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

log_format download  '$remote_addr - $remote_user [$time_local]  '
  '"$request" $status $bytes_sent '
  '"$http_referer" "$http_user_agent" '
  '"$http_range" "$sent_http_content_range"';

access_log  logs/access.log  main;

client_header_timeout  60;
client_body_timeout    60;
send_timeout           60;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  60;

#gzip  on;

server {
    listen       80;
    server_name  localhost;
    #autoindex on;


    location / {
        root html;
        index index.php index.htm index.html; 
            }   

    location ~ ^/phalcon/(.*\.php)$ {
        alias html/phalcon/public/$1;

        fastcgi_pass   127.0.0.1:9000;
                    fastcgi_index  index.php;
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include        fastcgi_params;
    }

    location /phalcon/ {        
        alias html/phalcon/public/;
        index index.php;

        if (!-e $request_filename) {
            rewrite ^(.+)$ /phalcon/index.php?_url=$1 last;
            break;
        }
    }

    # redirect server error pages to the static page /404.html
    error_page  404   http://localhost/error/404.html;

    # redirect server error pages to the static page /50x.html
     error_page   500 502 503 504  error/50x.html;

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }


}

}

white87332 avatar Oct 26 '12 09:10 white87332

The setup I use is as follows:

server {
    listen                      80;
    server_name                 my.site.com;
    access_log                  /var/log/nginx/my.site.com.access.log main buffer=32k;
    error_log                   /var/log/nginx/my.site.com.error.log  error;

    root                        /var/www/my.site.com/public;
    index                       index.php index.html;

    fastcgi_index               index.php;
    fastcgi_pass_header         Set-Cookie;
    fastcgi_buffer_size         256k;
    fastcgi_buffers             256 32k;
    fastcgi_busy_buffers_size   256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_connect_timeout     30;
    fastcgi_read_timeout        120;
    fastcgi_send_timeout        120;
    fastcgi_intercept_errors    on;

    error_page 404              = /404.html;
    error_page 500 502 503 504  = /50x.html;

    location / {
        # if file exists return it right away
        if (-f $request_filename) {
            break;
        }

    # otherwise rewrite it
        if (!-e $request_filename) {
            rewrite ^(.+)$ /index.php?_url=$1 last;
            break;
        }
    }

    location ~ \.php$ {
        fastcgi_pass            127.0.0.1:9000;
        include                 fastcgi.conf;
    }

    location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
        access_log              off;
        expires                 30d;
        break;
    }
}

For subfolder setup you will have to do what you did with the /phalcon in a location element.

As for the PhalconController handler class cannot be loaded, could you ensure that Phalcon is installed and working in your installation.

The easiest way to do this is to create a simple php file with the following settings:

<?php
   echo \Phalcon\Version::get();

If this prints out the version, then you are set to go, if not, then there is an issue with your installation/compilation of your extension

niden avatar Oct 26 '12 17:10 niden

Ok,thank you very much!

white87332 avatar Oct 26 '12 23:10 white87332

I got this same message:

"UsersController handler class cannot be loaded"

I created this controller by using the phalcon devtools and typing:

phalcon create-controller --name users

First it didn't want to do this, because my config.ini had this line:

controllersDir = /../app/controllers/

After I remove the leading / like this, it works:

controllersDir = ../app/controllers/

So I can create the UsersController with phalcon devtools. But when I open the /users I get the warning about the handler class cannot be loaded. When I put the leading / back, it works. This is inconsistent usage of the configuration file. I hope this gets fixed. I'm using 0.9.1.

awesselius avatar Mar 01 '13 14:03 awesselius