Tuesday, 28 August 2012


I had a problem with my Ubuntu VM today (actually I've had a number of problems since upgrading it the other day). I think my problems mainly boil down to that during the upgrade it often asked if an existing configuration file should be replaced with a new one. In all cases I said yes, since I thought it would best to have the most up-to-date configuration options.

Today, I ran a php script that generates some HTML files, but got the error:

file_put_contents(filename.html) [function.file-put-contents]: failed to open stream: Permission denied

Doing some research (and my own initial thoughts), it seemed the problem was likely that apache didn't have write permissions for the folder. Looking in /etc/apache2/ at the .conf files, I found a backup of the old envvars file. In this I had set:

export APACHE_RUN_USER=myusername
export APACHE_RUN_GROUP=myusername

In the current envvars file, these were both set to www-data. So I just changed them both to my username and restarted apache (sudo /etc/init.d/apache2 restart). Now my file worked okay with no permission denied problems!

No comments: