【问题标题】:CodeIgniter CLI giving system_path error "path does not appear to be set correctly."CodeIgniter CLI 给出 ​​system_path 错误“路径似乎设置不正确。”
【发布时间】:2012-05-08 09:03:44
【问题描述】:

我有一个 cron 任务设置来运行以下内容:

php /var/www/vhosts/examplesite.com/index.php cron processCategoryItemCount

当我在我的生产服务器(通过 MediaTemple dv4 托管)上运行此程序时,ssh 窗口上会闪烁以下错误:

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

当我在我的开发 mac 上运行 php CLI 命令时,我根本没有收到任何错误。

据我所知,我的 system_path 设置正确.. 这是 sn-p。

/*
 *---------------------------------------------------------------
 * 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 = 'system';

手动测试

我做了一些测试来检查 CI 用来确定 system_pathapplication_path 的代码。据我所知,它工作正常..

CodeIgniter 使用以下代码进行路径验证

// 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));
}

因此,我制作了一个 test.php 文件并将其粘贴到我的 httproot..

<?php
$system_path = 'system';
echo "index.php dir is: ".dirname(__FILE__)."\n";
chdir(dirname(__FILE__));
echo "System Dir is: ".realpath($system_path)."\n";
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));
}else{
    echo "System Path Set Properly\n";
}
sleep(30);

我用这个命令通过命令行运行这个:

/usr/bin/php /var/www/vhosts/examplesite.com/client/stage/test.php`

这是我得到的回报:

index.php dir is: /var/www/vhosts/examplesite.com/client/stage
System Dir is: /var/www/vhosts/examplesite.com/client/stage/system
System Path Set Properly

所以,再进行一些测试,我发现问题出在这部分:

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));
}

【问题讨论】:

  • 如果您通过浏览器运行 cron 文件,是否会出现该错误?
  • 不,它没有,如果我设置了一个安全的控制器来运行它不会吓坏的任务。仅适用于 CLI 和 cron 任务。
  • 那么,如果您使用 wget shell 命令来运行您的 cron 作业,这应该可以解决问题,因为它基本上就像有人通过浏览器访问该页面。
  • 我很欣赏您的评论,但我更愿意解决问题而不是绕过它。
  • 好的,但我不明白,“cron”是你的控制器之一,还是命令?你试过写一个“|”在 index.php 和 cron 之间?还是在第一种情况下是“/”?

标签: php codeigniter cron


【解决方案1】:

我只想写评论,但我不能.... 我是新来的,我无法选择对问题添加评论。

嗯...一年前我的专用服务器也遇到了同样的问题。

解决方案是将 $system_path 留空...

$system_path = '';

你可以试试这个:

$system_path = './system';

【讨论】:

  • 我将 system_path 留为空白,然后它对 application_path 报错,将其留为空白,CLI 运行良好,但现在 http 不行!
【解决方案2】:

问题与权限有关。我从来没有想过这一点,但是当我从 github 拉出时,如果我以 root 身份登录,显然所有权是root。结果php无法正常执行。

我跑了:chown exampleuser:psacln index.php 现在一切都好!

因此,作为遇到此问题的其他人的一个教训.. 如果您遇到同样的问题,请确保所有权和文件权限是正确的!

【讨论】:

  • 我在服务器上运行它(虽然我不能使用 CLI 除了来自 cPanel 的 cron 作业,但我只能通过 crons 通过电子邮件报告),我已将 index.php 设置为 755,我关注将 sys 路径更改为空或 ./system,但没有任何变化。你还有别的选择吗?
【解决方案3】:

另一个更好的解决方案是使用dirname()like,

改变下面两行

$system_path = 'system';
$application_folder = 'application';

$system_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'system';
$application_folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'application';

【讨论】:

    【解决方案4】:
    /*
     *---------------------------------------------------------------
     * 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 = '../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 = '../application';
    

    如果不工作,你可以试试这个兄弟添加另一个../

    如果路径设置正确,错误报告肯定不会这么说:)

    只是帮助^_^希望这会

    【讨论】:

    • @taiar 很高兴能帮到你:)
    【解决方案5】:

    您确定在 FTP 传输中没有任何问题吗?即系统实际上与index.php在同一目录中?

    另外,你确定你是从正确的地方调用 php 吗?路径对吗?

    我最近遇到了这个问题:CodeIgniter + Command Line + Cron + Cpanel

    尝试运行它:

    /usr/local/bin/php your/path/to/index.php <controller> <method>
    

    对于路径,它可能应该是完整路径?不是 www.example.com/index.php? 即我的类似于:

    /usr/local/bin/php /home/account_name/public_html/index.php <controller> <method> /dev/null 2>&1
    

    【讨论】:

      【解决方案6】:

      在 index.php 中

      我已经做出了这些改变并为我工作。

      $system_path = '../system/';
      
      $application_folder = '../application/';
      

      【讨论】:

        【解决方案7】:

        要将所有目录更改为 755 (-rwxr-xr-x):

        find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
        

        要将所有文件更改为 644 (-rw-r--r--):

        find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
        

        请修复 codeigniter 3.0.0 分发版!

        【讨论】:

          猜你喜欢
          • 2016-07-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-22
          • 1970-01-01
          • 2018-09-02
          • 1970-01-01
          相关资源
          最近更新 更多