【问题标题】:CodeIgniter incorrect system path on private serverCodeIgniter 私有服务器上的系统路径不正确
【发布时间】:2014-02-03 08:52:09
【问题描述】:

上传到服务器时的codeigniter项目给我以下错误。

您的系统文件夹路径似乎设置不正确。请 打开以下文件并更正:index.php

在本地和在 000webhost.com 托管上运行良好。

当上传到并行的私人服务器时,它会出现上述错误。

我的index.php如下。

<?php
define('ENVIRONMENT', 'development');

if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(E_ALL);
    break;

    case 'testing':
    case 'production':
        error_reporting(0);
    break;

    default:
        exit('The application environment is not set correctly.');
}
 }
$system_path = 'system';
$application_folder = 'application';


if (defined('STDIN'))
{
    chdir(dirname(__FILE__));
}

if (realpath($system_path) !== FALSE)
{
    $system_path = realpath($system_path).'/';
}

$system_path = rtrim($system_path, '/').'/';

if ( ! is_dir($system_path))
{
    exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}

define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('EXT', '.php');

// Path to the system folder
define('BASEPATH', str_replace("\\", "/", $system_path));

// Path to the front controller (this file)
define('FCPATH', str_replace(SELF, '', __FILE__));

// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));


// The path to the "application" folder
if (is_dir($application_folder))
{
    define('APPPATH', $application_folder.'/');
}
else
{
    if ( ! is_dir(BASEPATH.$application_folder.'/'))
    {
        exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
    }

    define('APPPATH', BASEPATH.$application_folder.'/');
}
 require_once BASEPATH.'core/CodeIgniter.php';

【问题讨论】:

  • 你的文件/文件夹结构是什么?
  • 你能提供你使用的.htaccess吗?

标签: php xampp codeigniter-2


【解决方案1】:

我已更改我的define('ENVIRONMENT', 'development');

if ($_SERVER['SERVER_ADDR'] == '192.168.0.1' || $_SERVER['HTTP_HOST'] == 'localhost')
{
    define('ENVIRONMENT', 'development');
}
else
{
    define('ENVIRONMENT', 'production');
}

它对我有用。

来自here的参考

【讨论】:

    【解决方案2】:

    在我的情况下,我没有去弄乱 .htaccess, 实际上在这样做之前,正如上面帖子中所建议的那样, 我尝试了它的后半部分,它正在改变

    $config['index_page'] = 'index.php';
    

    到下面

    $config['index_page'] = '';
    

    它对我很有效!

    ~~~~~~~~~~~~~~~~~~ 编辑添加更多信息~~~~~~~~~~~~~~~~~~~~~

    我的 CodeIgniter 目录结构:

    htdocs /
           |_ CI /
                 |_ OnlineStoreApp /
                                   |_ online_store_ci  // This is the CodeIgniter folder
                                   |_ public_html /
                                                  |_ css
                                                  |_ js
                                                  |_ fonts
                                                  |_ .htaccess // see bellow for more details
                                                  |_ index.php // see bellow for more details
    

    我的 .htaccess 文件包含以下内容:

    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
    

    我的index.php 文件与 CodeIgniter 根文件夹提供的文件相同,但我必须更改其中的两行,因为我将其放在 public_html 目录中,而不是原来的位置:

    注意:index.php 中查找以下两行,
    - $system_path
    - $application_folder
    它们已经过编辑,以指向system 目录和application 目录所在的位置。

    <?php
    
    /*
     *---------------------------------------------------------------
     * APPLICATION ENVIRONMENT
     *---------------------------------------------------------------
     *
     * You can load different configurations depending on your
     * current environment. Setting the environment also influences
     * things like logging and error reporting.
     *
     * This can be set to anything, but default usage is:
     *
     *     development
     *     testing
     *     production
     *
     * NOTE: If you change these, also change the error_reporting() code below
     *
     */
        define('ENVIRONMENT', 'development');
    /*
     *---------------------------------------------------------------
     * ERROR REPORTING
     *---------------------------------------------------------------
     *
     * Different environments will require different levels of error reporting.
     * By default development will show errors but testing and live will hide them.
     */
    
    if (defined('ENVIRONMENT'))
    {
        switch (ENVIRONMENT)
        {
            case 'development':
                error_reporting(E_ALL);
            break;
    
            case 'testing':
            case 'production':
                error_reporting(0);
            break;
    
            default:
                exit('The application environment is not set correctly.');
        }
    }
    
    /*
     *---------------------------------------------------------------
     * SYSTEM FOLDER NAME
     *---------------------------------------------------------------
     *
     * This variable must contain the name of your "system" folder.
     * Include the path if the folder is not in the same  directory
     * as this file.
     *
     */
        $system_path = '../online_store_ci/system';
    
    /*
     *---------------------------------------------------------------
     * APPLICATION FOLDER NAME
     *---------------------------------------------------------------
     *
     * If you want this front controller to use a different "application"
     * folder then the default one you can set its name here. The folder
     * can also be renamed or relocated anywhere on your server.  If
     * you do, use a full server path. For more info please see the user guide:
     * http://codeigniter.com/user_guide/general/managing_apps.html
     *
     * NO TRAILING SLASH!
     *
     */
        $application_folder = '../online_store_ci/application';
    
    /*
     * --------------------------------------------------------------------
     * DEFAULT CONTROLLER
     * --------------------------------------------------------------------
     *
     * Normally you will set your default controller in the routes.php file.
     * You can, however, force a custom routing by hard-coding a
     * specific controller class/function here.  For most applications, you
     * WILL NOT set your routing here, but it's an option for those
     * special instances where you might want to override the standard
     * routing in a specific front controller that shares a common CI installation.
     *
     * IMPORTANT:  If you set the routing here, NO OTHER controller will be
     * callable. In essence, this preference limits your application to ONE
     * specific controller.  Leave the function name blank if you need
     * to call functions dynamically via the URI.
     *
     * Un-comment the $routing array below to use this feature
     *
     */
        // The directory name, relative to the "controllers" folder.  Leave blank
        // if your controller is not in a sub-folder within the "controllers" folder
        // $routing['directory'] = '';
    
        // The controller class file name.  Example:  Mycontroller
        // $routing['controller'] = '';
    
        // The controller function you wish to be called.
        // $routing['function'] = '';
    
    
    /*
     * -------------------------------------------------------------------
     *  CUSTOM CONFIG VALUES
     * -------------------------------------------------------------------
     *
     * The $assign_to_config array below will be passed dynamically to the
     * config class when initialized. This allows you to set custom config
     * items or override any default config values found in the config.php file.
     * This can be handy as it permits you to share one application between
     * multiple front controller files, with each file containing different
     * config values.
     *
     * Un-comment the $assign_to_config array below to use this feature
     *
     */
        // $assign_to_config['name_of_config_item'] = 'value of config item';
    
    
    
    // --------------------------------------------------------------------
    // END OF USER CONFIGURABLE SETTINGS.  DO NOT EDIT BELOW THIS LINE
    // --------------------------------------------------------------------
    
    /*
     * ---------------------------------------------------------------
     *  Resolve the system path for increased reliability
     * ---------------------------------------------------------------
     */
    
        // Set the current directory correctly for CLI requests
        if (defined('STDIN'))
        {
            chdir(dirname(__FILE__));
        }
    
        if (realpath($system_path) !== FALSE)
        {
            $system_path = realpath($system_path).'/';
        }
    
        // ensure there's a trailing slash
        $system_path = rtrim($system_path, '/').'/';
    
        // Is the system path correct?
        if ( ! is_dir($system_path))
        {
            exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
        }
    
    /*
     * -------------------------------------------------------------------
     *  Now that we know the path, set the main path constants
     * -------------------------------------------------------------------
     */
        // The name of THIS file
        define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
    
        // The PHP file extension
        // this global constant is deprecated.
        define('EXT', '.php');
    
        // Path to the system folder
        define('BASEPATH', str_replace("\\", "/", $system_path));
    
        // Path to the front controller (this file)
        define('FCPATH', str_replace(SELF, '', __FILE__));
    
        // Name of the "system folder"
        define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
    
    
        // The path to the "application" folder
        if (is_dir($application_folder))
        {
            define('APPPATH', $application_folder.'/');
        }
        else
        {
            if ( ! is_dir(BASEPATH.$application_folder.'/'))
            {
                exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
            }
    
            define('APPPATH', BASEPATH.$application_folder.'/');
        }
    
    /*
     * --------------------------------------------------------------------
     * LOAD THE BOOTSTRAP FILE
     * --------------------------------------------------------------------
     *
     * And away we go...
     *
     */
    require_once BASEPATH.'core/CodeIgniter.php';
    
    /* End of file index.php */
    /* Location: ./index.php */
    

    希望这可能对那里的人有所帮助!

    CodeIgniter 摇滚!

    【讨论】:

      【解决方案3】:

      我有同样的问题,然后我在里面创建了控制器,我已经创建了索引方法,然后用下面的命令调用 cron 文件,它对我有用。

      wget domain_name/google_script -O /dev/null
      
      google_script = "My controller class name"
      

      这个解决方案对我有用。

      【讨论】:

        【解决方案4】:

        如果您上传您的项目,请按照以下步骤操作

        1. 确保您已上传 applicationsystemindex.php.htaccess

        2. 使用您的托管数据库修改您的config/database.php

        3. 确保 URL 拼写,Cz LINUX Hosting 区分大小写。

        4. 确保所有资源都上传到服务器。 (CSS、JS、图像等...)

        希望这对你有帮助:)

        【讨论】:

        • 在哪里可以找到 config/database.php
        【解决方案5】:

        在根文件夹上试试这个 .htaccess

        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
        
            RewriteCond %{REQUEST_URI} ^system.*
            RewriteRule ^(.*)$ /index.php?/$1 [L]
        
            RewriteCond %{REQUEST_URI} ^application.*
            RewriteRule ^(.*)$ /index.php?/$1 [L]
        
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?/$1 [L]
        </IfModule>
        <IfModule !mod_rewrite.c>
            ErrorDocument 404 /index.php
        </IfModule>
        

        假设 index.php 是您的索引页面。

        并更改 config.php

        $config['index_page'] = '';
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-09-18
          • 1970-01-01
          • 1970-01-01
          • 2016-05-30
          • 1970-01-01
          相关资源
          最近更新 更多