1

I've tried to use chmod function in php to change permissions to 777 temporarily, upload the file and then change it back to 755. But it didn't work, as it doesn't allow me to use the chmod function via php.

if(chmod($path, 0777) ) {
   if(!move_uploaded_file($oldfile, $newfileloc)) {
      return false;
   }
   chmod($path, 0755);
   return true;
}
else
   return false;

I had it working on my previous server with 755 permissions given to the folder.

I'm not sure how permissions work, so please help, thanks!

EDIT: What permissions should my /var/www folder have so that web-server can write files?

EDIT 2: Okay, I had this figured out. I just have to give permissions to www-data:www-data to make sure webserver has all the required permissions. But, the issue I'm getting is that when I have /var/www has chown www-data:www-data, the php functions are working fine but I'm getting permissions denied error when using FileZilla. So right now I have to change permissions to root:www-data everytime I need to transfer something via FileZilla and then back to www-data:www-data to make sure my webserver's working fine. Anyone got a fix for this?

Ketan Malhotra
  • 1,255
  • 3
  • 16
  • 44

1 Answers1

1

you can give 755 permission. But You have to change owner and group for /var/www/ folder. It should have www-data's ownership and group ownership. Check first which user has ownership and group ownership for this folder. run this below command.

ll /var/www/

if it has root access then it would look like this.

drwxr-xr-x. 2 root root 23 Mar 21 17:33 html

change the owner and group owner to www-data user using below command.

chown -R www-data:www.data /var/www

You can keep folder permission 755. -R option is use for giving permission recursively to its child folders and files.

Sanny Patel
  • 411
  • 3
  • 12
  • Thanks for your answer but I had this figured out. The issue I'm getting is that when I have /var/www has chown **www-data:www-data**, the php functions are working fine but I'm getting permissions denied error when using FileZilla. So right now I have to change permissions to **root:www-data** everytime I need to transfer something via FileZilla and then back to **www-data:www-data** to make sure my webserver's working fine. Do you have any solution to this? – Ketan Malhotra Sep 02 '16 at 19:01
  • Try to give acl permission. setfacl -m u:www-data:rwx /var/www. And keep actual ownership root:www-data. – Sanny Patel Sep 03 '16 at 15:40