yii php 框架“应用程序运行时路径无效。” 例外

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

yii php framework "Application runtime path is not valid." exception

phpyii

提问by Hubert_J

I tried to make a yii project for testing by executing

我试图通过执行来制作一个 yii 项目进行测试

/var/www/html/yii/framework/yiic webapp demo

and when I go to localhost/demo I get en error:

当我转到 localhost/demo 时,出现错误:

Application runtime path "/var/www/html/demo/protected/runtime" is not valid. 
Please make sure it is a directory writable by the Web server process.

At first I thought that it really isn't writable so I did:

起初我认为它真的不可写,所以我做了:

chmod 777 /var/www/html/demo/protected/runtime

didn't work so as the last idea I executed:

没有奏效,因为我执行的最后一个想法是:

chmod 777 -R /var/www/html/demo/

and I still get the same exception. Any ideas on what might be wrong?

我仍然得到同样的例外。关于可能出什么问题的任何想法?

---EDIT---

- -编辑 - -

FFS this drives me nuts

FFS 这让我发疯

drwxrwxrwx. 4 apache apache 4096 Jun  5 00:06 commands
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 components
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 config
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 controllers
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 data
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 extensions
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 messages
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 migrations
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 models
drwxrwxrwx. 3 apache apache 4096 Jun  5 00:06 runtime
drwxrwxrwx. 7 apache apache 4096 Jun  5 00:06 tests
drwxrwxrwx. 5 apache apache 4096 Jun  5 00:06 views
-rwxrwxrwx. 1 apache apache   71 Jun  5 00:02 yiic
-rwxrwxrwx. 1 apache apache  380 Jun  5 00:02 yiic.bat
-rwxrwxrwx. 1 apache apache  178 Jun  5 00:02 yiic.php

and I still can't write files from within php script

我仍然无法从 php 脚本中写入文件

采纳答案by ldg

Looks like you might have SELinux turned on, which enforces it's own security policies and can be a real pain for web apps and very annoying when it ends up resulting in errors like this. Whenever you have funky permissions problems, it's a good idea to check if you have it set: /usr/sbin/getenforce(or similar, depending on what system you are on).

看起来您可能打开了 SELinux,这会强制执行自己的安全策略,这对于 Web 应用程序来说可能是一个真正的痛苦,并且当它最终导致这样的错误时非常烦人。每当您遇到奇怪的权限问题时,最好检查一下您是否设置了它:( /usr/sbin/getenforce或类似的,取决于您使用的系统)。

See: http://www.crypt.gen.nz/selinux/disable_selinux.htmlfor a good overview and how to turn it off (again, the details may vary depending on your OS/kernel version). If it's a test machine not publicly accessible, you can pretty safely turn it off, otherwise, you should read the site above to understand what it does. Most Linux package managers can install files to help you manage the policies for specific apps. On RH/CentOS, you can also use /usr/bin/system-config-securitylevel-tuito turn it on/off.

请参阅:http: //www.crypt.gen.nz/selinux/disable_selinux.html以获得一个很好的概述以及如何将其关闭(同样,详细信息可能因您的操作系统/内核版本而异)。如果它是一台不可公开访问的测试机器,您可以非常安全地将其关闭,否则,您应该阅读上面的站点以了解它的作用。大多数 Linux 包管理器可以安装文件来帮助您管理特定应用程序的策略。在 RH/CentOS 上,您也可以使用/usr/bin/system-config-securitylevel-tui来打开/关闭它。

回答by thaddeusmt

That shouldwork... so maybe also try setting your Apache user (usually 'www-data') as the owner of /runtime? Something like:

应该可行...所以也许也可以尝试将您的 Apache 用户(通常是“www-data”)设置为/runtime? 就像是:

 chown -R www-data:www-data /var/www/html/demo/protected/runtime

Could be an Apache umaskissue also. Check out the Yii forum, which has helpful posts like this one: http://www.yiiframework.com/forum/index.php?/topic/19400-question-about-directoryfile-permissions/

也可能是 Apacheumask问题。查看 Yii 论坛,其中有类似这样的有用帖子:http://www.yiiframework.com/forum/index.php?/topic/19400-question-about-directoryfile-permissions /

You should NOT have to set your whole project to 777, that is very insecure. I think /assetsand /protected/runtimeare the only directories that need write permissions (775).

您不必将整个项目设置为 777,这是非常不安全的。我认为/assets并且/protected/runtime是唯一需要写权限的目录(775)。

回答by Irfan

You have entered a wrong syntax for the chmodcommand. Try this:

您为chmod命令输入了错误的语法。尝试这个:

sudo chmod -R 777 ./var/www/*

Enter a password when you will be prompt.

提示时输入密码。

Important notice:

重要通知:

The asterisk at the end of command line is very important. It means all files in the current directory.

命令行末尾的星号非常重要。表示当前目录下的所有文件。

回答by Mohsen Beiranvand

you must config with semanage like this which allow php-fpm write access to directory

您必须像这样使用 semanage 进行配置,以允许 php-fpm 对目录进行写访问

# semanage fcontext -a -t httpd_sys_rw_content_t 'YOUR_PATH_HERE'
# restorecon -v 'YOUR_PATH_HERE'

回答by Abdur Rahman Warriach

When i check it on my server, the 'runtime' folder was missing, so i just upload it on the server and it works. Here is the path to 'runtime' folder yoursite\protected\runtime –

当我在我的服务器上检查它时,“运行时”文件夹丢失了,所以我只是将它上传到服务器上并且它可以工作。这是“运行时”文件夹 yoursite\protected\runtime 的路径 –

回答by Abdur Rahman Warriach

Try to upload 'runtime' folder again on your server, that works for me.

尝试在您的服务器上再次上传“运行时”文件夹,这对我有用。

回答by Karthik

Change access of the runtime folder. On my case changing rwx rwx rwx in plesk parallel panel for runtime folder works.

更改运行时文件夹的访问权限。在我的情况下,在 plesk 并行面板中更改 rwx rwx rwx 以运行运行时文件夹。

回答by sanju

Changed access of the entire folder of the site by using the following command

使用以下命令更改了对站点整个文件夹的访问权限

sudo chmod -R 777 'name of your website folder'

This will solve the issue.

这将解决问题。

回答by Dilushan

If u r sure file permissions set correctly for the folder and still u getting the error, disabling SElinux or add an exception for SElinux is working if u r using CentOS. edit /etc/selinux/config filefor disable SElinux or run this command for add an exception

如果您确定为文件夹正确设置了文件权限,但仍然出现错误,如果您使用 CentOS,禁用 SElinux 或为 SElinux 添加例外是有效的。编辑/etc/selinux/config file禁用 SElinux 或运行此命令以添加例外

sudo chcon -t httpd_sys_rw_content_t /path/to/ur/annoying/folder -R

sudo chcon -t httpd_sys_rw_content_t /path/to/ur/annoying/folder -R