Learn about Centmin Mod LEMP Stack today
Register Now

Grav - Flat File CMS

Discussion in 'Blogs & CMS usage' started by Alex, Dec 3, 2014.

  1. Alex

    Alex New Member

    24
    5
    3
    Jun 18, 2014
    Ratings:
    +5
    Local Time:
    1:05 AM
    1.4.6
    Hi all, I am trying to get Grav installed onto a Vhost, it needs rewrite rules and I can't seem to get it to work. It comes with an example nginx.conf:


    Code:
    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
    
        server {
            listen       80;
            server_name  localhost;
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
        location / {
                 root   html;
                     index  index.php;
            if (!-e $request_filename){ rewrite ^(.*)$ /index.php last; }
        }
    
        location /user {
            rewrite ^/user/accounts/(.*)$ /error redirect;
            rewrite ^/user/config/(.*)$ /error redirect;
            rewrite ^/user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        location /cache {
            rewrite ^/cache/(.*) /error redirect;
        }
    
        location /bin {
            rewrite ^/bin/(.*)$ /error redirect;
        }
    
        location /system {
            rewrite ^/system/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        location /vendor {
            rewrite ^/vendor/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        # Remember to change 127.0.0.1:9000 to the Ip/port
        # you configured php-cgi.exe to run from
    
            location ~ \.php$ {
            try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    
    
       }
    
    }
    
    Which I have adjusted to fit the vhostdomain.com.conf:
    Code:
        server {
            listen       80;
            server_name  domain.com.au www.domain.com.au;
              access_log /home/nginx/domains/domain.com.au/log/access.log combined buffer=32k;
              error_log /home/nginx/domains/domain.com.au/log/error.log;
              root /home/nginx/domains/domain.com.au/public;
              include /usr/local/nginx/conf/staticfiles.conf;
              include /usr/local/nginx/conf/php.conf;
              include /usr/local/nginx/conf/drop.conf;
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root /home/nginx/domains/domain.com.au/public;
                access_log /home/nginx/domains/domain.com.au/log/access.log combined buffer=32k;
                error_log /home/nginx/domains/domain.com.au/log/error.log;
            }
    
      location / {
            root /home/nginx/domains/domain.com.au/public;
                  index  index.php;
        if (!-e $request_filename){ rewrite ^(.*)$ /index.php last; }
      }
    
      location /user {
            rewrite ^/user/accounts/(.*)$ /error redirect;
            rewrite ^/user/config/(.*)$ /error redirect;
            rewrite ^/user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        location /cache {
            rewrite ^/cache/(.*) /error redirect;
        }
    
        location /bin {
            rewrite ^/bin/(.*)$ /error redirect;
        }
    
        location /system {
            rewrite ^/system/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        location /vendor {
            rewrite ^/vendor/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
      # Remember to change 127.0.0.1:9000 to the Ip/port
      # you configured php-cgi.exe to run from
    
            location ~ \.php$ {
          try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    
    
       }
    Anyone have any ideas?

    Cheers
     
    Last edited: Dec 3, 2014
  2. Alex

    Alex New Member

    24
    5
    3
    Jun 18, 2014
    Ratings:
    +5
    Local Time:
    1:05 AM
    1.4.6
    Currently I am getting a 502 Bad Gateway
     
  3. Alex

    Alex New Member

    24
    5
    3
    Jun 18, 2014
    Ratings:
    +5
    Local Time:
    1:05 AM
    1.4.6
    Currently using
    Code:
    server {
       listen 80;
       server_name mydomain.com.au www.mydomain.com.au;
       root /home/nginx/domains/mydomain.com.au/public;
       index index.php;
    
      access_log /home/nginx/domains/mydomain.com.au/log/access.log combined buffer=32k;
      error_log /home/nginx/domains/mydomain.com.au/log/error.log;
    
    
       location / {
           try_files $uri $uri/ /index.php?$query_string;
       }
    
       location ~* \.php$ {
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           fastcgi_index              index.php;
           fastcgi_pass               unix:/var/run/php5-fpm.sock;
           fastcgi_param              SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include                    fastcgi_params;
           fastcgi_param              SCRIPT_FILENAME $request_filename;
       }
    }
    Error log:

    Code:
    PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/nginx/domains/mydomain.com.au/public/logs/grav.log" could not be opened: failed to open stream: Permission denied' in /home/nginx/domains/mydomain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
    Stack trace:
    #0 /home/nginx/domains/mydomain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
    #1 /home/nginx/domains/mydomain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(263): Monolog\Handler\AbstractProcessingHandler->handle(Array)
    #2 /home/nginx/domains/mydomain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(339): Monolog\Logger->addRecord(500, 'Uncaught except...', Array)
    #3 /home/nginx/domains/mydomain.com.au/public/system/src/Grav/Common/Service/ErrorServiceProvider.php(34): Monolog\Logger->addCritical('Unc
    2014/12/03 14:29:01 [crit] 2344#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 27.32.149.231, server: mydomain.com.au, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.com.au"
    2014/12/03 14:29:03 [crit] 2344#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 27.32.149.231, server: mydomain.com.au, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.com.au"
    2014/12/03 14:29:40 [crit] 2344#0: *8 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 123.243.176.8, server: mydomain.com.au, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.mydomain.com.au"
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,250
    12,117
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,655
    Local Time:
    1:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    go back to Centmin Mod default nginx vhost template and reapply your customisations with exception of this part as php.conf include file in nginx vhost takes care of it

    remove
    Code:
      # Remember to change 127.0.0.1:9000 to the Ip/port
      # you configured php-cgi.exe to run from
    
            location ~ \.php$ {
          try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
     
  5. Alex

    Alex New Member

    24
    5
    3
    Jun 18, 2014
    Ratings:
    +5
    Local Time:
    1:05 AM
    1.4.6
    Ok I tried

    Code:
        server {
            listen       80;
            server_name  domain.com.au www.domain.com.au;
              access_log /home/nginx/domains/domain.com.au/log/access.log combined buffer=32k;
              error_log /home/nginx/domains/domain.com.au/log/error.log;
              root /home/nginx/domains/domain.com.au/public;
              include /usr/local/nginx/conf/staticfiles.conf;
              include /usr/local/nginx/conf/php.conf;
              include /usr/local/nginx/conf/drop.conf;
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root /home/nginx/domains/domain.com.au/public;
                access_log /home/nginx/domains/domain.com.au/log/access.log combined buffer=32k;
                error_log /home/nginx/domains/domain.com.au/log/error.log;
            }
    
      location / {
            root /home/nginx/domains/domain.com.au/public;
                  index  index.php;
        if (!-e $request_filename){ rewrite ^(.*)$ /index.php last; }
      }
    
      location /user {
            rewrite ^/user/accounts/(.*)$ /error redirect;
            rewrite ^/user/config/(.*)$ /error redirect;
            rewrite ^/user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        location /cache {
            rewrite ^/cache/(.*) /error redirect;
        }
    
        location /bin {
            rewrite ^/bin/(.*)$ /error redirect;
        }
    
        location /system {
            rewrite ^/system/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
        location /vendor {
            rewrite ^/vendor/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$ /error redirect;
        }
    
       }
    And got error log:

    Code:
    2014/12/03 15:09:55 [error] 3338#0: *12 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/nginx/domains/domain.com.au/public/logs/grav.log" could not be opened: failed to open stream: Permission denied' in /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
    Stack trace:
    #0 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
    #1 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(263): Monolog\Handler\AbstractProcessingHandler->handle(Array)
    #2 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(339): Monolog\Logger->addRecord(500, 'mkdir(): Permis...', Array)
    #3 /home/nginx/domains/domain.com.au/public/system/src/Grav/Common/Service/ErrorServiceProvider.php(34): Monolog\Logger->addCritical('mkdir(): Permis...')
    #4 [internal function]: Grav\Common\Service\E...
    PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/nginx/domains/domain.com.au/public/logs/grav.log" could not be opened: failed to open stream: Permission denied' in /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
    Stack trace:
    #0 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
    #1 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(263): Monolog\Handler\AbstractProcessingHandler->handle(Array)
    #2 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(339): Monolog\Logger->addRecord(500, 'Uncaught except...', Array)
    #3 /home/nginx/domains/domain.com.au/public/system/src/Grav/Common/Service/ErrorServiceProvider.php(34): Monolog\Logger->addCritical('Unca
     
  6. Alex

    Alex New Member

    24
    5
    3
    Jun 18, 2014
    Ratings:
    +5
    Local Time:
    1:05 AM
    1.4.6
    If I just use:

    Code:
    server {
       listen 80;
       server_name domain.com.au www.domain.com.au;
       root /home/nginx/domains/domain.com.au/public;
       index index.php;
    
      access_log /home/nginx/domains/domain.com.au/log/access.log combined buffer=32k;
      error_log /home/nginx/domains/domain.com.au/log/error.log;
    
    
       location / {
           try_files $uri $uri/ /index.php?$query_string;
       }
    }
    The page downloads the php file..

    and the error log is:
    Code:
    2014/12/03 15:15:16 [error] 3338#0: *38 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/nginx/domains/domain.com.au/public/logs/grav.log" could not be opened: failed to open stream: Permission denied' in /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
    Stack trace:
    #0 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
    #1 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(263): Monolog\Handler\AbstractProcessingHandler->handle(Array)
    #2 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(339): Monolog\Logger->addRecord(500, 'mkdir(): Permis...', Array)
    #3 /home/nginx/domains/domain.com.au/public/system/src/Grav/Common/Service/ErrorServiceProvider.php(34): Monolog\Logger->addCritical('mkdir(): Permis...')
    #4 [internal function]: Grav\Common\Service\E...
    PHP message: PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/nginx/domains/domain.com.au/public/logs/grav.log" could not be opened: failed to open stream: Permission denied' in /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84
    Stack trace:
    #0 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
    #1 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(263): Monolog\Handler\AbstractProcessingHandler->handle(Array)
    #2 /home/nginx/domains/domain.com.au/public/vendor/monolog/monolog/src/Monolog/Logger.php(339): Monolog\Logger->addRecord(500, 'Uncaught except...', Array)
    #3 /home/nginx/domains/domain.com.au/public/system/src/Grav/Common/Service/ErrorServiceProvider.php(34): Monolog\Logger->addCritical('Unca
     
  7. Alex

    Alex New Member

    24
    5
    3
    Jun 18, 2014
    Ratings:
    +5
    Local Time:
    1:05 AM
    1.4.6
    Ok so I used the conf in post #5

    and did

    sudo find /home/nginx/domains/mydomain.com.au/public -type d -exec chmod 0775 {} \;
    sudo find /home/nginx/domains/mydomain.com.au/public -type f -exec chmod 0664 {} \;

    and it seems to be working :)
     
  8. eva2000

    eva2000 Administrator Staff Member

    53,250
    12,117
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,655
    Local Time:
    1:05 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Good to hear !