Smarty权限问题
Smarty 正在抱怨权限问题。我已经为我正在处理的项目编写了一个小型 mvc 框架,并且我需要能够在每个控制器中渲染模板。我继续按照 Smarty 安装说明进行操作,并在“前端控制器”或将请求路由到应用程序其余部分的页面中设置所有配置选项。 testinstall 函数表示一切都是正确的,但是当我尝试在控制器中渲染模板时,我最终得到了这个。
警告:mkdir():权限被拒绝 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php 第 28 行警告: 重命名(/tmp/wrt6piczo,./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php): 没有这样的文件或目录 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php 第 48 行警告:chmod():没有这样的 文件或目录在 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php 第 50 行警告: 包括(./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php): 无法打开流:没有这样的文件或 目录在 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php 第 423 行警告:include(): 失败 开幕 './templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php' 纳入 (include_path='.:/usr/share/php:/usr/share/pear') 在 /var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php 第 423 行
我独立测试了框架的其余部分,一切似乎都正常。我的“前端控制器”将请求正确路由到正确的控制器,并且我似乎能够很好地渲染常规 HTML。
此外,为了测试,我已将所有 Smarty 库文件夹以及其他所需目录更改为 777。我仍然收到相同的权限错误。
编辑
这些是我用于所有必需 smarty 文件夹的设置。
$smarty->setTemplateDir('lib/smarty/templates');
$smarty->setCompileDir('lib/smarty/templates_c');
$smarty->setCacheDir('lib/smarty/cache');
$smarty->setConfigDir('lib/smarty/configs');
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.
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
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.
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.
EDIT
These are the settings I've used for all the required smarty folders.
$smarty->setTemplateDir('lib/smarty/templates');
$smarty->setCompileDir('lib/smarty/templates_c');
$smarty->setCacheDir('lib/smarty/cache');
$smarty->setConfigDir('lib/smarty/configs');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
适当的权限为我解决了这个问题:
Proper permissions solved it for me:
会不会是相对路径的问题?您能否为您设置的****Dir 函数添加完整路径,以便您确保使用正确的位置。
如果您从 /specialdir/thisdirhasonlyaPHPfile/file.php 位置调用此函数,您可能会遇到麻烦。
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.
If you call this from a /specialdir/thisdirhasonlyaPHPfile/file.php location, you might get in trouble.
对于在执行上述所有操作后处理 Smarty 权限问题的其他人(检查 config/chown/chmod 等...),我们在 SE(安全增强型)Linux 上运行 Smarty 时遇到了一个问题。
编译/缓存目录是 ~/tmp 目录内的子目录。
默认目标策略阻止写入 tmp 目录。
您可以使用 semanage 来更新上下文/策略。您很可能需要创建一个新策略,将 httpd_sys_rw_content_t 上下文分配给您的 Web 应用程序也需要写入的目录。
更多信息:
http:// /www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/
t
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.
The compile/cache directories were sub-directories inside of a ~/tmp directory.
The default targeting policy prevents writes to tmp directories.
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.
More information:
http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/
t
只需注释 index.php 文件中的以下行即可。
这将解决您的问题。
Simply comment the following line from the index.php file.
This will solve your problem.
您应该再次检查写入的访问权限。
我遇到了同样的错误,因此我将“templates_c”文件夹及其内部任何内容的权限设置为 777,现在它可以工作了。
但是我必须在Filezilla中重复此操作3次,不知道为什么它没有立即更改权限。
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.
根据文档,'template_c'文件夹的权限应该是775。但有时它不起作用。您必须将其权限设置为 777。
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.