mikegioia / phalcon-boilerplate

Phalcon Boilerplate is a template for building large-scale PhalconPHP applications. It contains the structure and configuration for managing a big project.
Other
71 stars 19 forks source link

Nginx Rewrite rules #3

Closed Abhinav1217 closed 9 years ago

Abhinav1217 commented 9 years ago

I can't get it to run on nginx, Here is my server file :

server {
    listen 80;

    server_name l.pb;
    root /var/www/Phalcon-BoilerPlate;
    rewrite  ^/$ public/;
    rewrite  ^(.*) public/$1;

    location / {
        try_files $uri $uri/ /index.php;
    }

       ## Images and static content is treated different
       location ~* ^.+.(jpg|jpeg|svg|gif|css|png|js|ico|xml)$ {
         access_log        off;
         expires           360d;
     }

     location ~ /\.ht {
         deny  all;
     }

     # Pass the PHP scripts to FastCGI server
     location ~ \.php$ {

        fastcgi_pass   unix:/run/php-fpm/www.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        # fastcgi_param HTTPS on;
        fastcgi_param  HTTPS off;
    }

}

It works fine on Apache though. Any suggestion for nginx rewrite rule? I followed this guide for converting apache rewrite rules into nginx one. The guide worked for both laravel and codeignighter. I can't figure out what I missed in the rewrite rule.

mikegioia commented 9 years ago

I would change the root line to look like:

root /var/www/Phalcon-BoilerPlate/public;

And then remove those two rewrite lines. Also, try changing the location / line to look like this:

try_files $uri $uri/ @rewrite;

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

With those changes, your entire nginx config would look like:

server {
    listen 80;

    server_name l.pb;
    root /var/www/Phalcon-BoilerPlate/public;

    try_files $uri $uri/ @rewrite;

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

    ## Images and static content is treated different
    location ~* ^.+.(jpg|jpeg|svg|gif|css|png|js|ico|xml)$ {
        access_log        off;
        expires           360d;
    }

    location ~ /\.ht {
        deny  all;
    }

    # Pass the PHP scripts to FastCGI server
    location ~ \.php$ {
        fastcgi_pass   unix:/run/php-fpm/www.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        # fastcgi_param HTTPS on;
        fastcgi_param  HTTPS off;
    }
}
Abhinav1217 commented 9 years ago

I think it is working. I am bit doubtful as it is now showing a blank page with blank head and body in view-source. I was expecting something like "It is all set up, add your modules here".

The index page is running because when I added echo "welcome" it was echoed on browser. but nothing else worked so far. Any other documentation resource on available on this?

mikegioia commented 9 years ago

Hmm, have you read through the README and run the database scripts? You also need composer to download all packages first, both of those could throw a PHP error.

I just updated the default config to have "responseMode" = "view" for now. This will show you the HTML version of the app. If that config item is set to "API" you will only see a JSON response. This can be found in app/etc/config.php and overridden in app/etc/config.local.php.

Pull down or make those config changes to see the HTML view.

Abhinav1217 commented 9 years ago

Nothing changed with the new settings. So I re-started from the scratch. Cloned the new repo, modified config for my URL and DB username and password, did composer install, run the install script and then the database script. It is same as before.

I even gave 777 permission on the entire directory. Honestly speaking I am confused. I cant figure out what is wrong.

mikegioia commented 9 years ago

I'm not really going to be able to debug this without seeing all of the moving pieces. If you started from scratch, and set the root to /path/to/Phalcon-Boilerplate/public in your nginx, then you should be good to go.

What exactly is the problem that you're encountering? Is it a white screen? Do you have PHP error_reporting set to On? Do you have all errors displaying? What OS/environment are you running and what version of cphalcon do you have installed?

This is an example of what the welcome screen looks like: phalcon-bp-welcome

Abhinav1217 commented 9 years ago

Root points to the public folder. It is a blank white screen.

[Abhinav@abhinav-fed22 etc] $ php -v
PHP 5.6.10 (cli) (built: Jun 11 2015 05:56:38) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
phalcon
Web framework delivered as a C-extension for PHP
phalcon enabled
Author  Phalcon Team and contributors
Version     2.0.3
Build Date  Jun 11 2015 18:26:46
Powered by Zephir   Version 0.6.3a 
mikegioia commented 9 years ago

If you're seeing a white screen, then something is throwing an error somewhere in the chain. Do you have an nginx log that is catching these errors? It could be an error.log in your nginx logs directory, or you could set the error log in the nginx config specifically.

I would bet it has something to do with file permissions, but I'm just guessing. I've never run this on Fedora but I can certainly try installing this in a Fedora VM later today or tomorrow, but the answers are probably in the nginx log.

Abhinav1217 commented 9 years ago

Hi, Sorry for delay. I corrected the PHP.ini file, uncommented the display error line. I found article on stackoverflow which pointed out a fact that changing ini setting inside programs, the file must be error free. Since the error is generated in the index.php file, which meant it will not execute, ergo, ini_set will not have any effect.

Anyways, After changes in php settings, and a clean install of Phalcon-Blolerplate, this is the error which is being showed.

Catchable fatal error: Argument 1 passed to Phalcon\Config::merge() must be an instance of Phalcon\Config, array given, called in /var/www/Phalcon-BoilerPlate/app/library/Bootstrap/App.php on line 59 and defined in /var/www/Phalcon-BoilerPlate/app/library/Bootstrap/Base.php on line 80

I hope Phalcon 2.0.3 is not an issue since I already converted few helper functions into server module using zephir.

mikegioia commented 9 years ago

Ok, interesting. I'm going to have to install this in 2.0.3 and test it out. I unfortunately only have it running in 1.3.5. It might take me a few days, but I'll test it on a Debian VM and see if I can fix it quickly. It's probably just the type of the $config variable being returned. If you change it to return a \Phalcon\Config object it might work for you locally.

Abhinav1217 commented 9 years ago

Sure. Let me try. If it works I will send you a pull request.

Abhinav1217 commented 9 years ago

I created a pull request and now it is working with Phalcon 2.0 . I am starting to like this boilerplate. Thanks.