I have an uploads directory on my server, php upload works fine when folder's permission is set to 755 but if I make new dir inside uploads (uploads/subuploaddir) upload fails and I need to set 755 permission for this folder manually, so my question is how can I set 755 permission for uploads dir and all of it's future created sub directories?
PS. chmod -R 755 ...mypath/uploads doesn't work
Thanks in advance.
All answers are very appreciated.
Peter
UPDATE:
Problem solved, my fault. PHP creates folders with permission 777 as default and I created folders for testing purposes through FTP manually, so it was created by another system user and with different permission.
Use
umask(022);
in PHP before creating a file (e.g. line 1 in index.php). Using that option, every files that PHP creates will have a permission that equals to 755. If that doesn't work, search your code for calls to umask and change them to the one above.
you can use this command
chmod -R 755 directorypath or file
Related
I am particularly new in CodeIgniter. I have a task that require me to upload multiple files into the server. Of all recents searches made, I found that all of them require me to change upload folder permission into 777. The question is how to change them?
Just make the directory and set the permission like that
mkdir("test", 0777);
Changing the permission of any dir/folder has no relation to any framework. It's specific to OS that you are using.
If Ubuntu in recursive
chmod -R 0777 folder_name/
without recursive
chmod 0777 folder_name/
For windows
Refer: https://superuser.com/questions/929023/chmod-777-in-windows-7
I want to know that if we set the 777 permission on a folder to upload filed, do we need to set the permission of internal folders as well or it will work inside the external folder for which we have set the permission
exp.
images/newfolder
if we set the permission of images, newfolder will allow uploading files automatically or not?
Actually the answer is no. Setting 777 permissions on a folder does not guarantee that all sub folders are also having the permission 777. Unless you do that recursively. So check which OS you use and do that recursively. I use linux (Ubuntu) and I can do this
sudo chmod -R 777 /path/to/dir/
I created a project with Laravel 4 but when I go to the folder localhost /my_project/public get some errors related to the permissions. I solved it setting to 777 all the permissions of the folder and files contained in my_project. Is there a way to solve this thing is not to make 777?
What's happen when you set 755 permission to my_project directory? Try to change permissions and check it. Your directory should be able to read all files in public directory.
I set my ownership to be owned by www-data:
chown -R auser:www-data /path/to/laravel/root
I also make all my subfolders and files read and write by group:
chmod -R g+rw /path/to/laravel/root
I also make my folders have a sticky bit so if you add a new file, it inherits:
chmod -R g+s /path/to/laravel/root
This has always worked for me. Perhaps Linux experts might have better ideas but this is what I use.
Please refer to Laravel's documentation about installation located at http://laravel.com/docs/installation. Under no circumstances you should run laravel on production with full permissions to the whole world. You must also remember that your "application" will be executed from the public directory so there is NO reason to allow read/write/execute for the whole world to the whole project directory unless you don't care about security at all.
Anyway, extracted from Laravel's documentation from the permissions section:
"Laravel may require one set of permissions to be configured: folders
within app/storage require write access by the web server."
This whould make your project run smooth.
I am trying to give 777 permissions to a folder on my hosting.
I use the following command: chmod("./test",0777);
I know it doesn't work because I execute a script which changes a file in the directory.
If I give the permissions manually (in the FTP) it works.
Why doesn't the chmod work?
I have created folders using PHP's mkdir command.
Now I want to delete these folders over FTP or SSH.
I get the error "permission denied".
I am on a managed server so I do not have root access.
What can I do so I will be able to delete these folders?
Do I need to change the file permissions (chmod) using PHP?
The folders would have been created with the ownership/permissions of whatever account PHP was running under (Apache's, if you're doing this from a web-based script).
You wouldn't be able to chown the directories to another account, as that requires root permissions. You could have the script that creates the directories set them to mode 0777, which'd give everyone read/write/delete access to them, but you might not want to open up things that wide.
you have to change the permissions first:
chmod("/somedir/somefile", 755);
or whatever you like
then you can remove with
rmdir("dir")
Yes, you must run chmod after directory or file creation with PHP. Its because PHP runs with Apache permissions.
After chmod to PHP/Apache user you can rename, move or delete folders and files.
Check your permission first if you got any problem. Some folder you only can delete or chmod if you are owner.
If you are owner, then you can use PHP chmod.
CHMOD("PATH_TO_FOLDER",0755);
Then use unlink to delete files in folder:
unlink("PATH_TO_FOLDER/*.*");
And then
rmdir("PATH_TO_FOLDER")