Reputation: 63718
I'm trying to upload and save an image file. This has worked fine in the past, but is now returning an error.
Warning: move_uploaded_file(//home/bitnami/htdocs/lookgram/photos/1/22.jpeg): failed to open stream: Permission denied in /opt/bitnami/apache2/htdocs/lookgram/build/classes/Photo.php on line 138
Warning: move_uploaded_file(): Unable to move '/tmp/phpAyWyw4' to '//home/bitnami/htdocs/lookgram/photos/1/22.jpeg' in /opt/bitnami/apache2/htdocs/lookgram/build/classes/Photo.php on line 138
This looks like a file permssion error, so here is the permissions on the folder:
drwxrwxr-x 6 bitnami bitnami 4096 Mar 15 01:02 photos
Any ideas?
Upvotes: 1
Views: 2591
Reputation: 8179
This is because photos/1/
is only writable by root
user. For upload to work we need to make the owner of that folder same as httpd process owner OR make them globally writable (bad practice).
Check apache process owner: $ps aux | grep httpd
. The first column will be the owner typically it will be nobody
Change the owner of photos/1/
to be become nobody
or whatever the owner you found in step 1.
$sudo chown nobody /home/bitnami/htdocs/lookgram/photos/1/
Chmod photo/1/
now to be writable by the owner, if needed [Seems you already have this in place].
$ sudo chmod -R 0755 /home/bitnami/htdocs/lookgram/photos/1/
For more details why this behavior happen, check the manual http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir , note that it also talking about open_basedir directive.
Upvotes: 2