Php Warning: Failed To Open Stream: Permission Denied

(Garyw3058) #1


Downloaded Yii 1.1.13

created an app - helloworld

Un commented Gii section in /helloworld/protected/config/main.php

Navigated to ‘Controller Generator’ and entered the names for the controller and actions

Clicked ‘Generate’ and received an error message ‘do not have permission’. It states that the server permissions need to be changed.

I am using MAMP Pro 2.0.3 and changed the permissions (I think?) It seems that permissions in MAMP returns back to default setting, if I am not mistaking. The default settings, I have R W X for Folder and for Files I have R W only.

However instead of the original error message I now get this PHP Warning. (see below)

Not sure if this is a bug.

Running OSX 10.6.8



PHP warning

file_put_contents(/Users/me/WebRoot/helloworld/protected/runtime/gii-1.1.13/ControllerCode.php) [<a href=‘function.file-put-contents’>function.file-put-contents</a>]: failed to open stream: Permission denied


374 }

375 }

376 }

377 }


379 /**

380 * Saves sticky attributes into a file.

381 */

382 public function saveStickyAttributes()

383 {

384 $path=$this->getStickyFile();

385 @mkdir(dirname($path),0755,true);

386 file_put_contents($path,"<?php\nreturn ".var_export($this->_stickyAttributes,true).";\n");

387 }


389 /**

390 * @return string the file path that stores the sticky attribute values.

391 */

392 public function getStickyFile()

393 {

394 return Yii::app()->runtimePath.’/gii-’.Yii::getVersion().’/’.get_class($this).’.php’;

395 }


397 /**

398 * Converts a word to its plural form.

Stack Trace


/Users/me/YiiRoot/framework/gii/CCodeModel.php(386): file_put_contents("/Users/me/WebRoot/helloworld/protected/runtime/gii-1.1.13…", “<?php return array ( ‘template’ => ‘default’, ‘baseClass’ =>…”)


/Users/me/YiiRoot/framework/gii/CCodeGenerator.php(161): CCodeModel->saveStickyAttributes()


/Users/me/YiiRoot/framework/gii/CCodeGenerator.php(63): CCodeGenerator->prepare()


/Users/me/YiiRoot/framework/web/actions/CInlineAction.php(49): CCodeGenerator->actionIndex()


/Users/me/YiiRoot/framework/web/CController.php(308): CInlineAction->runWithParams(array("r" => "gii/controller"))


/Users/me/YiiRoot/framework/web/CController.php(286): CController->runAction(CInlineAction)


/Users/me/YiiRoot/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array())


/Users/me/YiiRoot/framework/web/CWebApplication.php(282): CController->run("")


/Users/me/YiiRoot/framework/web/CWebApplication.php(141): CWebApplication->runController("gii/controller")


/Users/me/YiiRoot/framework/base/CApplication.php(169): CWebApplication->processRequest()


/Users/me/WebRoot/helloworld/index.php(13): CApplication->run()

08 defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);

09 // specify how many levels of call stack should be shown in each log message

10 defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’,3);


12 require_once($yii);

13 Yii::createWebApplication($config)->run();

(Garyw3058) #2

Just an update:

I have made the below changes to my /helloworld/protected/config/main.php

file adding



to the ‘gii’=array see below.

This according to the documentation will allow Gii to write to the file structure. Unfortunately I still get the same PHP Warning as in my earlier post.

I have looked into the Command Line tool (Yii Interactive Tool) but I read that it has now been depreciated. Perhaps that is why when I run the command: $ ‘crud User’ it hangs part way through the command.

Any help will be appreciated. Thanks



	// uncomment the following to enable the Gii tool





		// If removed, Gii defaults to localhost only. Edit carefully to taste.







(Garyw3058) #3


In order solve this issue I started from scratch with a new project and Gii works until I go to Generate the code.

(no more PHP warnings!)

However I still have the following issues:

[i]Generating code using template "/users/gary/YiiRoot/framework/gii/generators/controller/templates/default"…

generating controllers/MessageController.php

       Unable to write the file '/Users/gary/WebRoot/test1/protected/controllers/MessageController.php'.

generating views/message/helloworld.php

       Unable to create the directory '/Users/gary/WebRoot/test1/protected/views/message'.


I have tried including



into the gii module array (../protected/config/main.php).

I have also tried altering the php.ini files ‘safe_mode = Off’ to ‘safe_mode = 0’. Still no change.

I have not found anything else on this forum that can help me with this problem.

This is perhaps the wrong section to post this question so I will re-post at a later time.

Yii version 1.1.13

Mac OSX 10.6.8

MAMP Pro 2.0.3

Apache 2.2.17

PHP 5.3.6

Firefox 17.0.1

Any thoughts or hints would be appreciated.



(Yugenekr) #4

Set higher write permissions on folders IN which new files and folders will be written.

Or add writing process to a group (or make it a user) that has permission to write in that directories (controllers, models, views) - this approach is better one.

This should solve your issue.

(Garyw3058) #5


Screen shot 2013-01-10 at 10.00.22 AM.png

Thanks Yugene for the advice.

For anyone else experiencing a similar problem it can be rectified by setting the file permissions in MAMP Pro to ‘_www’.

(refer to image)

Don’t know if this is advisable, but I guess for development purposes it should be fine.

This solution seems to have also eliminated the above PHP Warning.