-2

In my project I can't use move_uploaded_file PHP function because of:

Notice:  PHP Request Startup: file created in the system's temporary directory in Unknown on line 0
Warning:  move_uploaded_file(../Pictures/1n0): Failed to open stream: Permission denied in /var/www/backend/Controllers/News.controller.php on line 114
move_uploaded_file(): Unable to move "/tmp/phpSPAnSj" to "../Pictures/1n0" in /var/www/backend/Controllers/News.controller.php on line 114

I tried to fix this problem by changing owner of /var/www/backend/Pictures directory and permissions of this dir:

# ls -la /var/www/backend:

drwxr-xr-x. 10 root   root 4096 Oct 14 20:26 .
drwxr-xr-x.  8 root   root 4096 Oct 18 12:18 ..
...
drwxr-xr-x.  2 nobody root 4096 Oct 13 14:45 Pictures

and also, I saw the permissions of /tmp dir:

# ls -la /:

drwxr-xr-x.  19 root root  4096 Oct 16 14:43 .
drwxr-xr-x.  19 root root  4096 Oct 16 14:43 ..
...
drwxrwxrwt.  14 root root   280 Oct 18 12:28 tmp

(I tried to change the directory of temp uploads by modifing php.ini: upload_tmp_dir = /var/www/tmp_upload but apache still keeps tmp files in /tmp directory.)

So how can I give permissions to apache for moving temporary uploaded files?

6
  • What user is the PHP scripts running as? nobody?
    – vidarlo
    Oct 18 at 15:48
  • Im not sure. I saw this user in another forum and I tried to change the owner to this.
    – MHSarmadi
    Oct 18 at 15:54
  • The first step is probably to figure out what user it actually is, and set correct owner. However, Serverfault is probably not the correct site for this.
    – vidarlo
    Oct 18 at 16:19
  • which forum do you recommend for this? stackOverflow?
    – MHSarmadi
    Oct 18 at 17:25
  • I'd suggest either superuser.com or unix.stackexchange.com. It's not about development, so StackOverflow is not the correct one. Serverfault is geared towards professionals, and we generally require that people understand their setups.
    – vidarlo
    Oct 18 at 19:15

1 Answer 1

0

You didn't say what OS this is running on. If it were RHEL/Rocky/Alma/Debian/Ubuntu/Suse then MAC might be a consideration.

drwxr-xr-x.  2 nobody root 4096 Oct 13 14:45 Pictures

Your PHP is running as "nobody"? That's rather unusual - You should really be using a dedicated service account for your webserver - nobody is a service account but already has specific use-cases and semantics that don't quite fit here.

You error can mean that the permissions are wrong. But it it suggests that you're not moving it to a directory named "Pictures" you are trying to move it to a FILE named "..\Pictures\1n0" in the current directory (wrong slashes).

7
  • Im using Linux Fedora. I fixed the wrong slashes but nothing changed.
    – MHSarmadi
    Oct 18 at 15:54
  • Check the SELinux config - you need an exception for this path.
    – symcbean
    Oct 18 at 16:02
  • Explain more please.
    – MHSarmadi
    Oct 18 at 16:04
  • 1
    Use getenforce to find the initial state.
    – symcbean
    Oct 18 at 20:33
  • 1
    Wow it works! but what happened just now?
    – MHSarmadi
    Oct 18 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .