Problem with file permission, when I upload a file cannot upload the file? unless I do 777 file permission for folder upload, each time I do

Posted April 19, 2017 33.6k views

I am using virtual host. I created a website. I am uploading images to the specific folder. Te problem I am facing is:
1: Cannot upload.
2: The solution I am doing now, I enter using file zilla. I select the folder then I make the permission 777. I can upload for 5 or 6 photos then It back.
I really need help. I need to make it 777 for live. The problem I heard that 777 is problem for a website. Please give me an advice.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

SSH to the machine then cd to the directory and run the following.

sudo chmod -R 777 /path/to/dir


Using a chmod of 777 grants world read, write, and execute, so it’s not exactly secure and I would not recommend keeping those permissions.

With properly setup user and group permissions, you shouldn’t need such open access – generally all files are at least 644 and directories 755. Since you’re using Apache, the files and directories need to be owned by the user that Apache is running as.

In most cases, www-data is the user and group that Apache uses, unless you’ve configured it to use another user or the repository you’re using has done so.

So what you need to check is ownership. You can see what user and group owns a file or directory by using ls -al on a directory.

You’ll see something like:

drwx------  5 root root 4096 Apr 19 21:20 .
drwxr-xr-x 23 root root 4096 Apr 19 02:05 ..

If you’re seeing root on the third and fourth column in the directory where your files are located, then that’s probably the issue.

You can change ownership permissions using chown which also supports recursion, like chmod.

For example, to change ownership of files in /var/www/html to www-data, we’d use:

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

thank you so much I will try it now.