PHP cli命令行safe_mode限制 [英] PHP cli command line safe_mode restriction

查看:231
本文介绍了PHP cli命令行safe_mode限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Kohana框架(3.0.9),它生成每日日志。我想邮寄日志文件,如果一个是在CRON运行脚本前一天,但在尝试后,我无法弄清楚如何推迟safe_mode在PHP CLI方式。



当我在网络上运行我的脚本时,没有问题。但我想在我的Plesk 9.5.2服务器(或作为root用户在命令行上)作为CRON任务运行脚本我收到以下错误:


ErrorException [2]:dir():SAFE MODE有效的限制。其uid为10001的脚本不允许访问由uid拥有的/var/www/vhosts/mydomain.com/subdomains/mysubdomain/httpdocs/application/logs/2011/01 48〜APPPATH / classes / controller / ajax.php [ 181]


我已经在我的Plesk控制面板中关闭了安全模式,这对Web请求很好,但不是在在命令行或CRON任务。



我使用下面的代码来测试它是否工作:

  $ d = dir(APPPATH.'logs / 2011/01 /'); 
echoHandle:。 $ d->句柄。 \\\
;
echoPath:。 $ d->路径。 \\\
;
while(false!==($ entry = $ d-> read())){
echo $ entry。\\\
;
}
$ d-> close();

我可以读取目录APPPATH.'logs /',还有目录APPPATH.'logs /

解决方案

现在,你可以安排php从UI执行脚本:



< img src =https://i.stack.imgur.com/FPYL4.gifalt =plesk schedule cron url php script>



如果你仍然需要通过命令行执行脚本注意Plesk的PHP二进制文件放在:

 #7.0 
/opt/plesk/php/7.0/bin/php
#5.6
/opt/plesk/php/5.6/bin/php
#5.5
/ opt / plesk / php /5.5/bin/php
#等等

原始答案: / em>



我知道这是几个月大,但对于下一个使用Plesk和cron和PHP时遇到问题的人,这里是答案。 / p>

虽然Plesk将cron作为ROOT运行,但默认情况下它也运行安全模式ON,这意味着当你在需要PHP的Plesk中设置cron时,有你从shell或从web没有体验。



所以你做的是使用CLI /etc/php.ini选项覆盖,像这样:

  / usr / bin / php -q -d safe_mode = Off / var / www / vhosts / path-to-your- php-file.php 


I'm using the Kohana framework (3.0.9), which generates daily logs. I want to mail the log file if one was made the day before CRON runs the script, but after days trying I can't figure out how to put off safe_mode in PHP CLI modus.

When I'm running my script on the web, there is no problem. But I want to run the script as a CRON task on my Plesk 9.5.2 server (or on the command line as root user) I'm getting the following error:

ErrorException [ 2 ]: dir(): SAFE MODE Restriction in effect. The script whose uid is 10001 is not allowed to access /var/www/vhosts/mydomain.com/subdomains/mysubdomain/httpdocs/application/logs/2011/01 owned by uid 48 ~ APPPATH/classes/controller/ajax.php [ 181 ]

I've allready put SAFE MODE off in my Plesk control panel, which works fine for the web request, but not in on the command line or as an CRON task.

I'm using the following code to test if its working:

$d = dir(APPPATH.'logs/2011/01/');
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();

I can read the directory APPPATH.'logs/', and also the directory APPPATH.'logs/2011', but the directory's representing each month with the daily log files always give an error.

解决方案

At nowadays you can schedule php script execution from UI like this:

In case you still need execute script via command line pay attention that Plesk's PHP binaries are placed in:

# 7.0
/opt/plesk/php/7.0/bin/php
# 5.6
/opt/plesk/php/5.6/bin/php
# 5.5
/opt/plesk/php/5.5/bin/php
# and so on

Original answer:

I know this is a few months old, but for the next person that comes across a problem while using Plesk and cron and PHP, here's the answer.

While Plesk does run cron as ROOT, it also runs PHP by default with safe mode ON, which means that when you setup a cron in Plesk that needs PHP, it's going to have restrictions that you do not experience from the shell or from the web.

So what you do is use the CLI /etc/php.ini option override, like so:

/usr/bin/php -q -d safe_mode=Off /var/www/vhosts/path-to-your-php-file.php

这篇关于PHP cli命令行safe_mode限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆