php CodeIgniter CLI 给出 system_path 错误“路径似乎设置不正确。”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10353611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CodeIgniter CLI giving system_path error "path does not appear to be set correctly."
提问by gorelative
I have a cron task setup to run the following:
我有一个 cron 任务设置来运行以下内容:
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:
当我在我的生产服务器(通过 MediaTemple dv4 托管)上运行它时,ssh 窗口上会出现以下错误:
Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php
您的系统文件夹路径似乎未正确设置。请打开以下文件并更正:index.php
When i run the php CLI command on my development mac, i dont get any errors at all.
当我在我的开发 Mac 上运行 php CLI 命令时,我根本没有收到任何错误。
As far as i can tell my system_path is set properly.. here is the snippet.
据我所知,我的 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';
Manual Testing
手动测试
I did some testing to go through the code that CI uses to determine system_pathand application_path. From what i can tell its working properly..
我做了一些测试来检查 CI 用来确定system_path和的代码application_path。据我所知,它的工作正常..
CodeIgniter Uses The Following Code For path validation
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));
}
As a result I made a test.php file and stuck it in my httproot..
结果我制作了一个 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);
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));
}
回答by pcsi
I`d like to write just a comment, but I couldn't.... I'm new in here and I don't have the option to add a comment on the question.
我只想写一条评论,但我不能......我是新来的,我没有选择对这个问题添加评论。
Well... I had the same problem 1 year ago with my dedicated server.
嗯... 1 年前我在我的专用服务器上遇到了同样的问题。
The solution was to leave the $system_path blank...
解决方案是将 $system_path 留空...
$system_path = '';
you can try this instead:
你可以试试这个:
$system_path = './system';
回答by gorelative
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.
问题与权限有关。我从没想过这一点,但是如果我以 root 身份登录,从 github 中提取时显然所有权是root. 结果 php 无法正常执行。
i ran: chown exampleuser:psacln index.phpand alls good now!
我跑了:chown exampleuser:psacln index.php现在一切都好!
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!
因此,作为对遇到此问题的其他人的教训.. 如果您遇到同样的问题,请确保所有权和文件权限正确!
回答by Rohan Kumar
Another better solution is to use dirname()like,
另一个更好的解决方案是使用dirname() 之类的,
Change the below 2 lines
更改以下 2 行
$system_path = 'system';
$application_folder = 'application';
By
经过
$system_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'system';
$application_folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'application';
回答by Jhonathan H.
/*
*---------------------------------------------------------------
* 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';
you can try this bro if dont work add another ../
如果不工作,你可以试试这个兄弟添加另一个../
definitely the error reporting will not say that so if the path is set correctly :)
如果路径设置正确,错误报告肯定不会这么说:)
just helping ^_^ hope thiss will
只是帮助^_^ 希望这会
回答by MikeCruz13
Are you sure that nothing got screwed around in FTP transfer? i.e. system is actually in the same directory as index.php?
您确定 FTP 传输没有任何问题吗?即系统实际上与index.php 在同一目录中?
Also, are you sure you are calling php from the right place? and is the path right?
另外,你确定你是从正确的地方调用 php 吗?路径对吗?
I had this problem recently: CodeIgniter + Command Line + Cron + Cpanel
我最近遇到了这个问题:CodeIgniter + Command Line + Cron + Cpanel
Try running it:
尝试运行它:
/usr/local/bin/php your/path/to/index.php <controller> <method>
For the path, it probably should be a full path? not the www.example.com/index.php? i.e. mine is something like:
对于路径,它可能应该是完整路径?不是 www.example.com/index.php?即我的是这样的:
/usr/local/bin/php /home/account_name/public_html/index.php <controller> <method> /dev/null 2>&1
回答by Alexander Pomaz
To change all the directories to 755 (-rwxr-xr-x):
将所有目录更改为 755 (-rwxr-xr-x):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--):
要将所有文件更改为 644 (-rw-r--r--):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
Fix codeigniter 3.0.0 distributive plz!
修复 codeigniter 3.0.0 分布式请!
回答by Harikrishnan
In index.php
在 index.php 中
I have made these changes and worked for me.
我已经做出了这些改变并为我工作。
$system_path = '../system/';
$application_folder = '../application/';

