Fix permission denied on LAMP when saving files or creating folders
Sunday, May 15, 2011 EDT
by: Eric Potvin
Tags:phpapacheubuntulinux
Have you ever got a warning when uploading files or creating folder in your PHP script? Such as:
Warning: mkdir(/home/user/public_html/folder): Permission denied in /home/user/public_html/folder/index.php on line 224
Or
Warning: DOMDocument::save(projects.xml) [function.DOMDocument-save]: failed to open stream: Permission denied in /home/user/public_html/folder/process.php on line 63
If so, there's a quick way to fix this. Simply edit the envvars located in the /etc/apache2/ folder.
sudo vi /etc/apache2/envvars
Change the APACHE_RUN_USER and APACHE_RUN_GROUP to add your username.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
to:
export APACHE_RUN_USER=myuser
export APACHE_RUN_GROUP=myuser
Restart apache:
sudo /etc/init.d/apache2 restart
Done!
Link to this Article
To link directly to this article from your web site, use one of the following snippets below.
Fix permission denied on LAMP when saving files or creating folders | Book Of Zeus<a href="http://www.bookofzeus.com/articles/fix-permission-denied-on-lamp-when-saving-files-or-creating-folders/" title="Fix permission denied on LAMP when saving files or creating folders">Fix permission denied on LAMP when saving files or creating folders | Book Of Zeus</a>
Short URL:
Fix permission denied on LAMP when saving files or creating folders | Book Of Zeus<a href="http://s.bookofzeus.com/U5Sfq" title="Fix permission denied on LAMP when saving files or creating folders Short URL">Fix permission denied on LAMP when saving files or creating folders | Book Of Zeus</a>