php Smarty权限问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4588641/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:35:44  来源:igfitidea点击:

Smarty permissions problems

phptemplatessmarty

提问by hraesvelgr

Smarty is complaining about permissions. I've written a small mvc framework for a project I'm working on and I need to be able to render templates in each controller. I went ahead and followed the Smarty installation instructions, and set all of the configuration options in my "front controller", or the page that routes requests to the rest of the application. The testinstall function says everything is kosher, yet when I attempt to render templates in my controllers, I end up with this.

Smarty 抱怨权限问题。我为我正在处理的项目编写了一个小型 mvc 框架,我需要能够在每个控制器中呈现模板。我继续按照 Smarty 安装说明进行操作,并在我的“前端控制器”或将请求路由到应用程序其余部分的页面中设置所有配置选项。testinstall 函数说一切都是 kosher 的,但是当我尝试在我的控制器中渲染模板时,我最终得到了这个。

Warning: mkdir(): Permission denied in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php on line 28 Warning: rename(/tmp/wrt6piczo,./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php): No such file or directory in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php on line 48 Warning: chmod(): No such file or directory in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php on line 50 Warning: include(./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php): failed to open stream: No such file or directory in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php on line 423 Warning: include(): Failed opening './templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php on line 423

警告:mkdir():第 28 行 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php 中的权限被拒绝.poopy.tpl.php):第 48 行的 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php 中没有这样的文件或目录警告:chmod():没有这样的文件或目录在 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php 第 50 行警告:include(./templates_c/73b1662b4c376f493278f9873564df03430a0b430a0b430a0b43)。在第 423 行的 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php 中没有这样的文件或目录警告:include():打开失败。/templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php' 用于包含 (include_path='.:/usr/share/php:/usr/share/pear') 在 /var/www/HRRTL/includes/CallLogs Smarty/libs/sysplugins/smarty_internal_template.php 第 423 行

I have tested the rest of my framework independently and everything seems to work. My "front controller" routes requests properly to the correct controllers, and I seem to be able to render regular HTML just fine.

我已经独立测试了框架的其余部分,一切似乎都有效。我的“前端控制器”将请求正确路由到正确的控制器,而且我似乎能够很好地呈现常规 HTML。

Additionally, I have chmodded all of the Smarty library folders as well as the other required directories to 777 just for the sake of testing. I'm still receiving the same permissions errors.

此外,为了测试,我已将所有 Smarty 库文件夹以及其他所需目录修改为 777。我仍然收到相同的权限错误。

EDIT

编辑

These are the settings I've used for all the required smarty folders.

这些是我用于所有必需的 smarty 文件夹的设置。

$smarty->setTemplateDir('lib/smarty/templates');
$smarty->setCompileDir('lib/smarty/templates_c');
$smarty->setCacheDir('lib/smarty/cache');
$smarty->setConfigDir('lib/smarty/configs');

采纳答案by Nanne

Could it be a problem with relative paths? Could you add the complete paths for you set****Dir functions, so you'll be sure you're using the correct locations.

相对路径会不会有问题?你能不能为你的 set****Dir 函数添加完整的路径,这样你就可以确保你使用了正确的位置。

If you call this from a /specialdir/thisdirhasonlyaPHPfile/file.php location, you might get in trouble.

如果您从 /specialdir/thisdirhasonlyaPHPfile/file.php 位置调用它,您可能会遇到麻烦。

回答by Petrus Theron

Proper permissions solved it for me:

适当的权限为我解决了这个问题:

chown -R www-data /var/www/HRTRL

回答by supert3d

For anyone else dealing with permission issues with Smarty after following all of the above (Checking config/chown/chmod etc...) We came across an issue whilst running Smarty on SE(Security Enhanced)Linux.

对于在遵循上述所有内容(检查 config/chown/chmod 等...)后处理 Smarty 权限问题的任何其他人,我们在 SE(安全增强型)Linux 上运行 Smarty 时遇到了一个问题。

The compile/cache directories were sub-directories inside of a ~/tmp directory.

编译/缓存目录是 ~/tmp 目录内的子目录。

The default targeting policy prevents writes to tmp directories.

默认目标策略阻止写入 tmp 目录。

You can use semanage to update contexts/policies. You'll most likely need to create a new policy to assign the httpd_sys_rw_content_t context to the directory your web-app needs to write too.

您可以使用 semanage 更新上下文/策略。您很可能需要创建一个新策略来将 httpd_sys_rw_content_t 上下文分配给您的网络应用程序也需要写入的目录。

More information: http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/t

更多信息: http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/ŧ

回答by denu

You should check again access permission for write. I had the same errors, so I have set permissions to 777 for 'templates_c' folder and anything inside of it and now it works. However I had to repeat this operation for 3 times in Filezilla, don't know why it didn't change the permissions at once.

您应该再次检查写入的访问权限。我遇到了同样的错误,所以我已将“templates_c”文件夹及其内部任何内容的权限设置为 777,现在它可以工作了。但是我不得不在 Filezilla 中重复此操作 3 次,不知道为什么它没有立即更改权限。

回答by Mrid

According to the documentation, permission of 'template_c' folder should be 775. But it does not work sometime. You have to set its permission to 777.

根据文档,'template_c' 文件夹的权限应该是 775。但它有时不起作用。您必须将其权限设置为 777。

回答by Binu V Pillai

Simply comment the following line from the index.php file.

只需注释 index.php 文件中的以下行。

$smarty->caching = true;

This will solve your problem.

这将解决您的问题。