I know this has been a head ache for many people. I dicided to write this little peace to make sure concentrate to the point give you what you need to get ride of this akwnoing problem of failed to open stream, access denied, permission denied while trying to write or upload a file into your apache server or php application. Just follow the steps down one by one and all shall be well.
If this is developer machine, and I think it is, dont try to use /var/www (there will be always permission problem) Try to use user dir
you will keep all your files and projects in your home and there will be no permission problems.
Ok, so if you cant work with user dir, you have to set up file system like this:
1. Find out apache owner user name. If you use Ubuntu, it should be www-data. Go to terminal and type:
$ ps aux | grep apache
You should get something like this below or in many lines. First column is username.
www-data 2070 0.0 0.0 463244 7788 ? S sty25 0:00 /usr/sbin/apache2 -k start
2. Find out apache user group. Again in the terminal, type:
$ sudo groups www-data
You should get something like this below. Second column is group name.
www-data : www-data
3. Set the right owner user and owner group for apache root dir:
$ sudo chown -R www-data:www-data /var/www/
4. Set the right privileges for apache root dir:
$ sudo chmod -R 775 /var/www/
Now you have your system cleaned up, and we try to fix your user to have access to /var/www directory.
5. Now, add apache group to your user:
$ sudo usermod -a -G www-data {YOUR_USER_NAME}
(without curly braces in our case here the user_name is www-data)
WARNING! dont forget -a switch! this way you append new group to existing list and not replace old groups list with new one.
Now you have read/write access to files located in apache root dir /var/www. And we need to tell apache that new files should be readable/writable to group members
6. Add umask command to apache enviroment config:
$ sudo echo umask 002 >> /etc/apache2/envvars
or with graphic editor:
$ gksudo gedit /etc/apache2/envvars
and place umask 002
as last line in this file
7. Great! you can restart apache now
$ sudo apache2ctl restart
or sudo service apache2 restart
Good luck!
Hope This Help...
By receiving free stock articles and smart tutorials to advance your career...