CodeIgniter CLI给出system_path错误“路径似乎没有正确设置”。

时间:2012-04-27 15:38:07

标签: php codeigniter cron

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

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

当我在我的生产服务器上运行它(通过MediaTemple dv4托管)时,ssh窗口上会出现以下错误:

  

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

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

据我所知,我的system_path设置正确..这是片段。

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

7 个答案:

答案 0 :(得分:4)

我想写一个评论,但我不能...... 我是新来的,我没有选择在这个问题上添加评论。

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

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

$system_path = '';

你可以试试这个:

$system_path = './system';

答案 1 :(得分:3)

问题与权限有关。我从来没有想过这个,但是当从github中提取时如果我以root身份登录显然所有权是root。因此,php无法正常执行。

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

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

答案 2 :(得分:3)

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

更改以下2行

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

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

答案 3 :(得分:0)

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

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

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

只是帮助^ _ ^希望这会

答案 4 :(得分:0)

您确定在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

答案 5 :(得分:0)

在index.php中

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

$system_path = '../system/';

$application_folder = '../application/';

答案 6 :(得分:0)

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

class comp
{
    int a,b;
public:
    comp()
{
    a=b=1;
}
    comp(int,int);
    comp(comp &);
    comp operator+(comp &);
    operator int();
    void show()
    {
        cout<<"a= "<<a<<"b= "<<b<<endl;
    }
    comp& operator=(comp &);
    friend ostream &operator<<(ostream &out, comp &c);
};


    comp::comp(comp & c)//copy constructor
    {
        a=c.a,b=c.b;
        cout<<"copy constructor called"<<endl;
    }
    comp comp::operator+(comp & c1)// overloaded '+' opreator
    {
        comp c;
        c.a=a+c1.a;
        c.b=b+c1.b;
        return c;
    }
    comp & comp::operator =(comp & c)// I tried with return type as void also
    {
         cout<<"in operator ="<<endl;
        a=c.a,b=c.b;
        return *this;
    }
int main()
{
    comp c1,c2(2,3),c3;
    c3=c2+c1;
    cout<<c3;
    comp c4=c3+c1;
    cout<<c4;
    int i=c4;
    cout<<i;
    return 0;
}

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

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

修复codeigniter 3.0.0 distributive plz!