问题描述
我有一个cron任务设置运行以下操作:
php /var/www/vhosts/examplesite.com/ index.php cron processCategoryItemCount
当我在我的生产服务器(通过MediaTemple dv4托管) ssh窗口上的错误闪烁:
当我在我的开发mac上运行php CLI命令,我根本没有得到任何错误。
至于我可以告诉我的system_path设置正确..这里是代码片段。
/ *
* --------------------------- ------------------------------------
*系统文件夹名称
* - -------------------------------------------------- ------------
*
*此变量必须包含system文件夹的名称。
*如果文件夹不在与此文件相同的目录
*中,则包含路径。
*
* /
$ system_path ='system';
手动测试
通过CI用于确定 system_path
和 application_path
的代码。
$ b
//为CLI请求正确设置当前目录
if(defined('STDIN'))
{
chdir(dirname __文件__));
}
if(realpath($ system_path)!== FALSE)
{
$ system_path = realpath($ system_path)。
}
//确保有斜杠
$ system_path = rtrim($ system_path,'/').'/';
//系统路径是否正确?
if(!is_dir($ system_path))
{
exit(您的系统文件夹路径似乎未正确设置,请打开以下文件并更正:.pathinfo __FILE__,PATHINFO_BASENAME));
}
结果我做了一个test.php文件, strong> httproot ..
<?php
$ system_path ='system'
echoindex.php dir is:.dirname(__ FILE __)。\\\
;
chdir(dirname(__ FILE__));
echoSystem Dir is:.realpath($ system_path)。\\\
;
if(!is_dir($ system_path)){
exit(您的系统文件夹路径似乎未正确设置,请打开以下文件并更正:.pathinfo(__ FILE__,PATHINFO_BASENAME) );
} else {
echo系统路径设置正确\\\
;
}
sleep(30);
我使用此命令通过命令行运行:
/ usr / bin / php / var / www / vhosts / examplesite.com / client / stage / test.php`
这是我回来的:
php dir is:/var/www/vhosts/examplesite.com/client/stage
系统目录是:/var/www/vhosts/examplesite.com/client/stage/system
系统路径设置正确
所以,多一点测试,我发现问题在这部分:
if(!is_dir($ system_path))
{
exit(您的系统文件夹路径似乎未设置请打开以下文件并更正此问题:.pathinfo(__ FILE__,PATHINFO_BASENAME));
}
问题是权限相关。我从来没有想过这个,但是当从github拉时,如果im登录为根显然所有权是 root
。因此,PHP无法正常执行。
我跑: chown exampleuser:psacln index.php
!
因此,如果你遇到同样的问题,请确保所有权和文件权限是正确的!
I have a cron task setup to run the following:
php /var/www/vhosts/examplesite.com/index.php cron processCategoryItemCount
When i run this on my production server (hosted via MediaTemple dv4) the following error flashes on the ssh window:
When i run the php CLI command on my development mac, i dont get any errors at all.
As far as i can tell my system_path is set properly.. here is the snippet.
/*
*---------------------------------------------------------------
* 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';
Manual Testing
I did some testing to go through the code that CI uses to determine system_path
and application_path
. From what i can tell its working properly..
CodeIgniter Uses The Following Code For path validation
// 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));
}
As a result I made a test.php file and stuck it in my 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);
I ran this via command line with this command:
/usr/bin/php /var/www/vhosts/examplesite.com/client/stage/test.php`
This is what i get back:
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
So, a bit more testing and i discover the problem is in this part:
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));
}
The problem was permissions related. I never thought of this, but when pulling from github if im logged in as root obviously the ownership is root
. As a result php cannot execute properly.
i ran: chown exampleuser:psacln index.php
and alls good now!
So as a lesson to others running into this issue.. if you're getting the same problem make sure ownership and file permissions are right!
这篇关于CodeIgniter CLI给出system_path错误“路径似乎未正确设置”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!