1

I developed a PHP script to add new files based on a template. I'm running it on localhost by now. I wondered what is the best chmod setting for the folder the script is in (and where the new files should go). 644 says permission denied, 622 works, 666 works (I can only choose 6, 4, 2 and 0 from the Info panel on my mac). By the way, I noticed the third number matters, how can I set it up to be the second or first?

EDIT
So how do you change chown on a Mac for localhost?

Agantacroxi
  • 81
  • 1
  • 10

2 Answers2

2

It's not about chmod it's about chown. The owner of that directory should be the web server. Usually the user is apache or www or www-data.
644 Is recommended for files.

Alex
  • 11,479
  • 6
  • 28
  • 50
1

The third number relates to Everyone (the first two are Owner and Group). 4 is read only which is why that does not work, 2 is write only and 6 is read/write (7 is read/write/execute).

In general, you should not be giving everyone write access to your server. The best approach where write access is required is to use chown to change the owner and/or group to match the user that your webserver is running as, then use 644 or 664.

For Mac, this thread: Correct owner/group/permissions for Apache 2 site files/folders under Mac OS X? provides some pointers on how to do this securely.

If you just want to change your upload folder, try:

sudo chgrp _www /path/to/upload/folder
sudo chmod 664 /path/to/upload/folder
Community
  • 1
  • 1
PassKit
  • 12,231
  • 5
  • 57
  • 75
  • It's not the php file. You need to match the directory owner to the webserver user. Usually apache, www or www-data depending on your server platfom. Syntax would be `chown www-data:www-data /var/www/myUploadFolder/` – PassKit Jan 13 '13 at 15:09
  • thank you, it worked :) just one thing: how do you change chown once it's online? and what would be the webserver user then (now it was _www)? – Agantacroxi Jan 13 '13 at 15:27
  • This depends on your what OS your web server is running and how Apache was installed and configured. If you are using a hosting provider then it could even be your username with that provider. Most likely on the web server, you will not need to worry about chown, Try 644 (default) first, and if that does not work, then 664 should do the trick. P.s. don't forget to accept answers if they work for you. – PassKit Jan 14 '13 at 01:06