SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast mildfoam's Avatar
    Join Date
    May 2010
    Location
    Australia.
    Posts
    56
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    codeigniter show `welcome to nginx` page when requset controller page

    hi all,


    I'm new with codeigniter, usually i just write native php code but today i got one request project from someone that need to use codeigniter. but, a problem just occur when i start code with CI (codeigniter).

    i am usually use, nginx - php - mysql and i have read CI user_guide properly and i just understand how to use that framework. ok, let's face the problem:

    I've create a controller just like this:

    PHP Code:
    <?php

        
    class post extends CI_Controller
        
    {
            
            public function 
    __construct() {
                
    parent::__construct();
                
                
    // load site_model
                
    $this->load->model('site_model');
            }
            
            public function 
    index()
            {
                
    $data['posts'] = $this->Site_model->getPosts();            
                
    $data['title'] = 'Index Page!';
                
                
    // load view
                
    $this->load->view('template/header'$data);
                
    $this->load->view('post/index'$data);
                
    $this->load->view('template/footer');
            }
            
            public function 
    view($id)
            {
                
    $data['post'] = $this->Site_model->getPosts($id);
                
                
    /*
                 * show 404 page error if the requested ID
                 * is not found in the database.
                 */
                
    if (empty($data['post']))
                {
                    
    show_404();
                }
                
                
    $data['title'] = $data['post']['post_title'];
                
                
    // load the needed view
                
    $this->load->view('template/header'$data);
                
    $this->load->view('post/view'$data);
                
    $this->load->view('template/footer');
            }
        }
    i think this is very basic CI code, but when try to access this url: http://localhost/cif/post and the server just show `welcome to nginx` page

    fyi, http://localhost/cif is my base project and i was set permission both of dir and files properly
    Object Oriented Programming Fans Boy ?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    How is your NGiNX virtual host defined?

    It should have something like try_files $uri $uri/ /index.php?$query_string; in it somewhere.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast mildfoam's Avatar
    Join Date
    May 2010
    Location
    Australia.
    Posts
    56
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    How is your NGiNX virtual host defined?

    It should have something like try_files $uri $uri/ /index.php?$query_string; in it somewhere.
    this is my nginx config (/etc/nginx/sites-available/default):

    PHP Code:
    # You may add here your

    # statements for each of your virtual hosts to this file

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##

    server {
            
    listen   80## listen for ipv4; this line is default and implied
            
    listen   [::]:80 default ipv6only=on## listen for ipv6

            
    root /var/www;
            
    index index.php index.html index.htm;

            
    # Make site accessible from http://localhost/
            
    server_name localhost;

            
    location / {
                    
    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    
    try_files $uri $uri/ /index.html;
                    
    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            
    }

            
    location /doc/ {
                    
    alias /usr/share/doc/;
                    
    autoindex on;
                    
    allow 127.0.0.1;
                    
    deny all;
            }

        
    # Only for nginx-naxsi : process denied requests
            #location /RequestDenied {
                    # For example, return an error code
                    #return 418;
            #}

            #error_page 404 /404.html;

            # redirect server error pages to the static page /50x.html
            #
            
    error_page 500 502 503 504 /50x.html;
            
    location = /50x.html {
                    
    root /var/www;
            }

            
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            
    location ~ \.php$ {
                    
    try_files $uri =404;
                    
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    
    fastcgi_pass 127.0.0.1:9000;
                    
    fastcgi_index index.php;
                    include 
    fastcgi_params;
            }

            
    # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            
    location ~ /\.ht {
                    
    deny all;
            }
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen 8000;
    #    listen somename:8080;
    #    server_name somename alias another.alias;
    #    root html;
    #    index index.html index.htm;
    #
    #    location / {
    #        try_files $uri $uri/ /index.html;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen 443;
    #    server_name localhost;
    #
    #    root html;
    #    index index.html index.htm;
    #
    #    ssl on;
    #    ssl_certificate cert.pem;
    #    ssl_certificate_key cert.key;
    #
    #    ssl_session_timeout 5m;
    #
    #    ssl_protocols SSLv3 TLSv1;
    #    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    #    ssl_prefer_server_ciphers on;
    #
    #    location / {
    #        try_files $uri $uri/ /index.html;
    #    }
    #} 
    Object Oriented Programming Fans Boy ?

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Hi @mildfoam,

    To use CodeIgniter it is advisable to make sure that the initial installation is correct and the 'Welcome to CodeIgniter' default view is appearing with no errors.

    Once that is running then investigate:

    1. config/config.php and play about with the log file settings. $config['log_threshold'] = 0; // 1,2,3, 4; and check differences in log file output
    2. config/config.php removal of index.php along with .htaccess file settings

    This is your modified file which I have tested locally using:

    http://localhost/index.php/post

    PHP Code:
    <?php
    class Post extends CI_Controller
    {
    public function 
    __construct()
    {
      
    parent::__construct();
      
      
    // load site_model
      #$this->load->model('site_model'); // unremm once "Welcome to CodeIgniter" is working
    }
            
    public function 
    index()
    {
      
    $view_file 'welcome_message.php';
      
      if(
    file_existsVIEWPATH .$view_file ) )
      {
        
    $this->load->view($view_file);
      }
      else
      {
        echo 
    'Missing file: ' .$view_file;
      }
    }
    #

    public function OLD_index()
    {
      
    $this->load->model('site_model');
      
      
    $data['posts'] = $this->Site_model->getPosts();            
      
    $data['title'] = 'Index Page!';
      
      
    // load view
      
    $this->load->view('template/header'$data);
      
    $this->load->view('post/index'$data);
      
    $this->load->view('template/footer');
    }
    #
            
    public function view($id)
    {
      
    $data['post'] = $this->Site_model->getPosts($id);
      
      
    /*
       * show 404 page error if the requested ID
       * is not found in the database.
       */
      
    if (empty($data['post']))
      {
          
    show_404();
      }
      
      
    $data['title'] = $data['post']['post_title'];
      
      
    // load the needed view
      
    $this->load->view('template/header'$data);
      
    $this->load->view('post/view'$data);
      
    $this->load->view('template/footer');
    }
    #

    }
    Last edited by John_Betong; Nov 9, 2012 at 02:36. Reason: spelling: not my fortay

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Change the first server section to this and then restart NGiNX:

    Code:
    server {
            listen   80; ## listen for ipv4; this line is default and implied
            listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
            root /var/www;
            index index.php index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name localhost;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    try_files $uri $uri/ /index.html;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
    
            location /doc/ {
                    alias /usr/share/doc/;
                    autoindex on;
                    allow 127.0.0.1;
                    deny all;
            }
    
            location /cif/ {
                 try_files $uri $uri/ /cif/index.php$uri?$query_string;
            }
    
        # Only for nginx-naxsi : process denied requests
            #location /RequestDenied {
                    # For example, return an error code
                    #return 418;
            #}
    
            #error_page 404 /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                    root /var/www;
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                    deny all;
            }
    }
    (I added the location /cif/ part)
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Enthusiast mildfoam's Avatar
    Join Date
    May 2010
    Location
    Australia.
    Posts
    56
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    Hi @mildfoam,

    To use CodeIgniter it is advisable to make sure that the initial installation is correct and the 'Welcome to CodeIgniter' default view is appearing with no errors.

    Once that is running then investigate:

    1. config/config.php and play about with the log file settings. $config['log_threshold'] = 0; // 1,2,3, 4; and check differences in log file output
    2. config/config.php removal of index.php along with .htaccess file settings

    This is your modified file which I have tested locally using:

    http://localhost/index.php/post

    PHP Code:
    <?php
    class Post extends CI_Controller
    {
    public function 
    __construct()
    {
      
    parent::__construct();
      
      
    // load site_model
      #$this->load->model('site_model'); // unremm once "Welcome to CodeIgniter" is working
    }
            
    public function 
    index()
    {
      
    $view_file 'welcome_message.php';
      
      if(
    file_existsVIEWPATH .$view_file ) )
      {
        
    $this->load->view($view_file);
      }
      else
      {
        echo 
    'Missing file: ' .$view_file;
      }
    }
    #

    public function OLD_index()
    {
      
    $this->load->model('site_model');
      
      
    $data['posts'] = $this->Site_model->getPosts();            
      
    $data['title'] = 'Index Page!';
      
      
    // load view
      
    $this->load->view('template/header'$data);
      
    $this->load->view('post/index'$data);
      
    $this->load->view('template/footer');
    }
    #
            
    public function view($id)
    {
      
    $data['post'] = $this->Site_model->getPosts($id);
      
      
    /*
       * show 404 page error if the requested ID
       * is not found in the database.
       */
      
    if (empty($data['post']))
      {
          
    show_404();
      }
      
      
    $data['title'] = $data['post']['post_title'];
      
      
    // load the needed view
      
    $this->load->view('template/header'$data);
      
    $this->load->view('post/view'$data);
      
    $this->load->view('template/footer');
    }
    #

    }
    hi

    i've change the error log configuration to `4` then i open the error log file but there is no any error message i got.

    Quote Originally Posted by ScallioXTX View Post
    Change the first server section to this and then restart NGiNX:

    Code:
    server {
            listen   80; ## listen for ipv4; this line is default and implied
            listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
            root /var/www;
            index index.php index.html index.htm;
    
            # Make site accessible from http://localhost/
            server_name localhost;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to index.html
                    try_files $uri $uri/ /index.html;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }
    
            location /doc/ {
                    alias /usr/share/doc/;
                    autoindex on;
                    allow 127.0.0.1;
                    deny all;
            }
    
            location /cif/ {
                 try_files $uri $uri/ /cif/index.php$uri?$query_string;
            }
    
        # Only for nginx-naxsi : process denied requests
            #location /RequestDenied {
                    # For example, return an error code
                    #return 418;
            #}
    
            #error_page 404 /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                    root /var/www;
            }
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                    deny all;
            }
    }
    (I added the location /cif/ part)
    hi ScallioXTX,

    i've change the nginx configuration then restart the server so i am try to open my CI project and the result is:

    500 Internal Server Error


    nginx/1.1.19

    what should i do?
    Object Oriented Programming Fans Boy ?

  7. #7
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    @mildfoam ;
    Did you get the default "welcome to CodeIgniter" view working?

    You need to find index.php and make sure that is being called.

  8. #8
    SitePoint Enthusiast mildfoam's Avatar
    Join Date
    May 2010
    Location
    Australia.
    Posts
    56
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    @mildfoam ;
    Did you get the default "welcome to CodeIgniter" view working?
    yes, i did
    Object Oriented Programming Fans Boy ?

  9. #9
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Ok change the config.php log file path setting to = FCPATH: run the welcome message again and check your log file.

    I am typing on my tablet and waiting for a virus check to finish on my desktop

    Edit: after FCPATH it should be ; and not :

  10. #10
    SitePoint Enthusiast mildfoam's Avatar
    Join Date
    May 2010
    Location
    Australia.
    Posts
    56
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    John_Betong

    @@John_Betong

    thanks for your answer but still error and display:

    500 Internal Server Error

    here is my /var/log/nginx

    2012/11/10 17:40:23 [error] 14539#0: *1 rewrite or internal redirection cycle while internally redirecting to "/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/index.php/cif/post", client: 127.0.0.1, server: localhost, request: "GET /cif/post HTTP/1.1", host: "localhost"
    ----------------
    btw, hope you can fix your computer (desktop) system.
    Object Oriented Programming Fans Boy ?

  11. #11
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by mildfoam View Post
    John_Betong

    @@John_Betong

    thanks for your answer but still error and display:

    500 Internal Server Error

    here is my /var/log/nginx

    ----------------
    btw, hope you can fix your computer (desktop) system.
    From the error it looks like there is a loop and index.php is being called repeatedly.

    Ensire your error reporting is set to 4 and run the default "Welcome to CodeIgniter".
    Check your error_log and it should be similar to the results from my error log below.
    Next, delete the error log and run your http://localhost/index.php/post then check your error log again.


    PHP Code:
    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>

    DEBUG - 18:53:02 --> Config Class Initialized
    DEBUG - 18:53:02 --> Hooks Class Initialized
    DEBUG - 18:53:02 --> Utf8 Class Initialized
    DEBUG - 18:53:02 --> UTF-8 Support Enabled
    DEBUG - 18:53:02 --> URI Class Initialized
    DEBUG - 18:53:02 --> Router Class Initialized
    DEBUG - 18:53:02 --> Output Class Initialized
    DEBUG - 18:53:02 --> Security Class Initialized
    DEBUG - 18:53:02 --> Input Class Initialized
    DEBUG - 18:53:02 --> Global POST and COOKIE data sanitized
    DEBUG - 18:53:02 --> Language Class Initialized
    DEBUG - 18:53:02 --> Loader Class Initialized
    DEBUG - 18:53:02 --> Config file loaded: ci_test/config/config_ci_jokes.php
    DEBUG - 18:53:02 --> Config file loaded: ci_test/config/config_max_sess.php
    DEBUG - 18:53:02 --> Helper loaded: url_helper
    DEBUG - 18:53:02 --> Helper loaded: string_helper
    DEBUG - 18:53:02 --> Helper loaded: inflector_helper
    DEBUG - 18:53:02 --> Helper loaded: html_helper
    DEBUG - 18:53:02 --> Helper loaded: text_helper
    DEBUG - 18:53:02 --> Helper loaded: form_helper
    DEBUG - 18:53:02 --> Database Driver Class Initialized
    DEBUG - 18:53:02 --> User Agent Class Initialized
    DEBUG - 18:53:02 --> Model Class Initialized
    DEBUG - 18:53:02 --> Model Class Initialized
    DEBUG - 18:53:02 --> Controller Class Initialized
    DEBUG - 18:53:02 --> File loaded: ci_test/views/welcome_message.php
    DEBUG - 18:53:02 --> Final output sent to browser
    DEBUG - 18:53:02 --> Total execution time: 0.1855
    You could also try inserting the following into your post.php
    controllers/post.php
    PHP Code:
    <?php

      
    // DEBUG - HALT TO ENSURE THIS CLASS IS CALLED
      
    echo __FILE__;die 


    class 
    Post extends CI_Controller
    {
    public function 
    __construct()
    {
      
    parent::__construct();
      
      
    // load site_model
      #$this->load->model('site_model');
    }
    Also check to ensure:

    config/routes.php
    PHP Code:
    <?php

      $route
    ["default_controller"] = "welcome"// DEFAULT

      
    $route["post"]    = "post";
    >>> btw, hope you can fix your computer (desktop) system.
    Thanks but Opera is still refusing to load Gmail and I am having to use another browser.

  12. #12
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by mildfoam View Post
    John_Betong

    @@John_Betong

    thanks for your answer but still error and display:

    500 Internal Server Error

    here is my /var/log/nginx



    ----------------
    btw, hope you can fix your computer (desktop) system.
    That looks like it can't find cif/index.php. Does that file exist?
    If so, try

    location /cif/ {
    try_files $uri $uri/ /index.php$uri?$query_string;
    }

    (I would try if it works, but I'm on my mobile phone and don't have access to a desktop here, so... )
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •