I realize there is some sort of problem with permissions on either my tmp folder or the images folder I created in the /var/www folder. I know that /var/www initially has root access. I have been following some online tutorials to try and fix this issue and have changed my permissions to who knows what over the last hour or so.
I receive this error when trying to upload a file from an HTML form using PHP/MySQL:
Warning: move_uploaded_file(images/verified-gw.gif): failed to open stream: Permission
denied in /var/www/addscore.php on line 40 Warning: move_uploaded_file(): Unable to move
'/tmp/phpla4QCP' to 'images/verified-gw.gif' in /var/www/addscore.php on line 40 cannot
move uploaded file or something beavis
So I think the permissions on either the /var/www/images folder are incorrect or the permissions on the tmp folder are root and the kernel of ubuntu is not letting the php script move from this root owned file to the images folder which has permissions of my user account to my knowledge and is in the group nobody.
I am pretty lost, any help is definitely appreciated.
Above you can see a picture of the permissions on the images folder I am trying to move the file from the tmp directory to.
Oh and here is the PHP script that fails:
if (!empty($screenshot)) {
move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)
or die (' cannot move uploaded file or something beavis');
Respectfully,
user
This solved my problem: http://ubuntuforums.org/showthread.php?t=1842090&s=8b97ec72fe7cd753910f488329a90f0f&p=11239688#post11239688
tl:dr - I typed this:
sudo chown -R www-data:www-data /var/www
I do not think it was a combination of trying to chmod the chown the tmp directory and this. I think it is just changing the permissions on the /var/www folder where all LAMP files are kept.
Now the PHP script works and tosses the image file in the directory I made. It would be easier if Ubuntu installed test servers like this LAMP stack in the user directory without having to learn file permissions like I am protecting my files from the nazis' submarines.
working with USER DIR mod
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.
working with Apache root dir
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. 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 terminal, type:
$ sudo groups www-data
You should get something like this below. Second column is group name.
www-data : www-data
3. Set RIGHT owner user and owner group for apache root dir:
$ sudo chown -R www-data:www-data /var/www/
4. Set 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. Add apache group to your user:
$ sudo usermod -a -G www-data {YOUR_USER_NAME}
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. 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 file7. Voila
$ sudo apache2ctl restart
Good luck!
try this:
sudo chown -R 777 /var/www/images
you need to give the file a public permission 777 OR 755 so the file can be uploaded to the specified directory its only a permission