I keep getting this error when trying to configure the upload directory with Apache 2.2 and PHP 5.3 on CentOS.
In php.ini:
upload_tmp_dir = /var/www/ht
It happens if SELinux
is enabled. Disable that in /etc/selinux/config
by setting SELINUX=disabled
and restart the server.
This worked for me.
sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rwX /var/www
Then logout or reboot.
If SELinux
complains, try the following
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www(/.*)?'
sudo restorecon -Rv '/var/www(/.*)?'
You can also run this script to find out the Apache process owner:
<?php echo exec('whoami'); ?>
And then change the owner of the destination directory to what you've got. Use the command:
chown user destination_dir
And then use the command
chmod 755 destination_dir
to change the destination directory permission.
This is because images
and tmp_file_upload
are only writable by root
user. For upload to work we need to make the owner of those folders same as httpd process owner OR make them globally writable (bad practice).
$ps aux | grep httpd
. The first column will be the owner typically it will be nobody
Change the owner of images
and tmp_file_upload
to be become nobody
or whatever the owner you found in step 1.
$sudo chown nobody /var/www/html/mysite/images/
$sudo chown nobody /var/www/html/mysite/tmp_file_upload/
Chmod images
and tmp_file_upload
now to be writable by the owner, if needed [Seems you already have this in place]. Mentioned in @Dmitry Teplyakov answer.
$ sudo chmod -R 0755 /var/www/html/mysite/images/
$ sudo chmod -R 0755 /var/www/html/mysite/tmp_file_upload/
For more details why this behavior happend, check the manual http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir , note that it also talking about open_basedir
directive.
Just change the permission of tmp_file_upload to 755 Following is the command chmod -R 755 tmp_file_upload
Change permissions for this folder
# chmod -R 0755 /var/www/html/mysite/images/