当我在服务器上运行我的YII项目时,我收到了这个错误.
CException
CAssetManager.basePath "/var/www/html/v2/assets" is invalid. Please make sure the directory exists and is writable by the Web server process.
/var/www/html/v2/yii/framework/web/CAssetManager.php(116)
104 }
105
106 /**
107 * Sets the root directory storing published asset files.
108 * @param string $value the root directory storing published asset files
109 * @throws CException if the base path is invalid
110 */
111 public function setBasePath($value)
112 {
113 if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath))
114 $this->_basePath=$basePath;
115 else
116 throw new CException(Yii::t('yii','CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.',
117 array('{path}'=>$value)));
118 }
119
120 /**
121 * @return string the base url that the published asset files can be accessed.
122 * Note, the ending slashes are stripped off. Defaults to '/AppBaseUrl/assets'.
123 */
124 public function getBaseUrl()
125 {
126 if($this->_baseUrl===null)
127 {
128 $request=Yii::app()->getRequest();
Run Code Online (Sandbox Code Playgroud)
我不知道,如何解决呢?请解释一下解决方案吗?
这是我的项目结构
assets
protected <-- Yii app
js
css
yii
Run Code Online (Sandbox Code Playgroud)
资产文件夹应该可由您的 Web 服务器进程写入。如果在默认配置的 apache 上,通常它是 www-data。您可以通过“+w”权限修改将用户添加到文件夹组
或者只需将权限修改为 777,因为资产文件夹将仅包含您的 js 和 css 文件,这些文件无论如何都会从您的根目录公开给公众
chmod 777 -R ./assets
Run Code Online (Sandbox Code Playgroud)
您还将面临与运行时和 data/auth.php 相同的问题(如果应用程序配置为使用 Yii auth 角色),您也可以在那里进行类似的适当修改
更新::如果设置了安全模式标志(这在 5.4 中已被弃用),则需要 PHP < 5.4 的附加设置,请参阅http://php.net/manual/en/ini.sect.safe-mode.php了解如何在 php.ini 文件中配置安全模式设置。您可以完全关闭标志或排除有问题的目录。(如果您已将 www-data(您的 web-process )添加到您的组中,则不需要此步骤,因为 gid 将自动匹配