Deleting 'Locked' Folders on the server - php

I have an opencart folder on my server, and I want to delete it, however I can't because my FTP client simply say's:
550 shop_Opencart: Operation not permitted
I understand that some files have different permissions etc but why, as the server admin, can I not delete these files, or change the file permissions? Is there anything else that stops these files from being deleted or modified, other than file permissions?
Even using the control panel (in this case PLESK) I cannot delete them, I get a Permission denied error.
What can I do?

Try chmod the folder using your ftp client and then delete it.

Connect via SSH using Putty as the root user and make the changes via that.

Related

php unlink on windows fails (permission denied), rename works

I have iis8.5 and php 7.1 (fastcgi, says phpinfo). I'm trying to unlink (delete) a folder.
unlink(realpath($folder));
and get a permission denied. If I try
exec(sprintf("rd /s /q %s", escapeshellarg($folder)));
it still doesn't work, but I don't get a reason either. So its permissions then - ok.
If I do a get_current_user() in the script it returns IUSR.
In IIS I have the app pool identity of the site to a user who has FULL CONTROL on the parent of the folder I'm trying to remove. IUSR also has FULL CONTROL of the same folder (and read from the root down to there, obviously).
Not sure what the permissions have to be in order for php to have delete capability. Many many SO answers simply say "you have to have the correct permissions" or "make sure you set the correct permissions". grumble
What are the permissions I need to add and where do I do that to make unlink or rmdir work?
https://msdn.microsoft.com/en-us/library/bb727008.aspx
"Giving a user permission to write to a file but not to delete it doesn't prevent the user from deleting the file's contents. A user can still delete the contents." Write will let you empty the file but not remove it.
You'll need "Full Modify" or "Execute" to delete the file.

assign permission to the directly using root level access in php

I am developing an application which is having 2 servers. The first one is Web Server, where I save my PHP files and another one is File Server where I am storing all the files uploaded by the user.
I want to assign the write permission to directory at runtime so that I can upload the file and after uploading the file I need to change its permission to its previous state.
When I tried chomod(FILE_PATH, 0755). It shows me an error. Assign write permission as root. I have the administrator level credentials of File Server.
What I want is to "Grant permission 777 to the directory by logging in as root at runtime"
Kindly help if there is any code sample available. Thanks in Advance.
You do NOT want to have your server logging in as root. Let me say that again. You really do NOT want your webserver to be logged on as root. If you did that, anyone that got control of PHP could do anything at all on the server. It is seriously unadvisable.
What you want to do is change the owner of the folder to either be the webserver, or assign it into the same group so that the webserver can happily change your folder options and the like.
You can use sudo chown username somedir to change the owner. This article might also help clear up permissions for you.
Edit: Try this blog post for a fairly good broad-ranging article on linux permissions.

Permission Denied on move_uploaded_file to another server in IIS

I have a PHP web application running on IIS, which allows a user to upload a file from a simple html form. The uploaded file is then moved to a folder on another server. This is working correctly on Apache, but fails on IIS with the error:
function['move_uploaded_file']failed to open stream: Permission denied
in...
I've checked all the permissions on the directories. If I run a simple PHP script through the command line to copy a file from the server into the folder on the other server it works correctly, so I suspect the problem is with IIS.
if (move_uploaded_file($_FILES ["file"] ["tmp_name"], "\\\\000.00.0.00\\tia\\web\\upload\\" .$_FILES["file"]["name"])) {
This has been covered already here. Quoting the reason here:
You have mapped target directory to a share such as \server2\files. These mappings are only available to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\server\share\folder\file.ext', also remember that the IUSR account will need access to these shares/folders/files
From what I can see in your comment, you are using a \\ prefixed network share as the target for your move_uploaded_file() operation.
I'll bet a beer that PHP isn't allowed to access that share. Remember, PHP runs with IIS's permissions!
Try saving to a local, globally writable path first. If that works, you know you have to fix the share's permissions.

How to set file permission for linux host under windows?

For example, i want a file has permission of 644 automatically when i uploaded it to my linux host, before upload, it is under windows. How could i do this?
Btw, i use Filezilla for upload
Updated: Before post this question, actually, i ever thought it is impossible too. But, as i has many wordpress sites, i remembered that i never need to set permission for wordpress files. So i did an experiment,
dowload a new wordpress package, zip format (under windows)
uploaded it to my linux host,
unarchive
check permissions of these files
I saw all files had their permission naturely right, some 644, some 755, exactly as described in wordpress document
I think this is not possible in most cases.
Could you give more information on how you upload? FTP, SFTP, SMB? :-)
For example for FTP you could configure the FTP server in order to give all new files the 644 umask (see this example for ProFTPd).
For SFTP, the client might be able to change the permissions after the upload, because it has SSH access, after all.
You can't. The permission is not written in the file itself, but rather in the filesystem. So it has to be done once the file has being uploaded.
Assuming that you are using FTP to upload the files, better FTP clients (FileZilla) will allow you to set the permissions IF THE SERVER is setup to allow the FTP client to set it.
As far as "default settings", 644 is typically the default already for files. This again is set by the server. I would assume that there is an FTP client out there that will auto set it for every file, but I don't know for sure. If you go monkeying with permissions, remember that directories are 755, not 644, and it is possible that the server could let you remove your own access to the file.
First, what username owns the files? What username do you connect as when you upload?
What is that user's default umask setting?
So you could use the Windows FTP command "quote" which lets you send arbitrary commands to the FTP server.
Assuming your Linux FTP server supports SITE UMASK...
e.g. ftp> quote SITE UMASK 111
This would be equivalent to doing: chmod 666 * on the Linux command line but via FTP on Windows.

PHP and Permissions

I recently moved my website to a new host and now am experiencing some broken code..
I have an uploading script that is now returning this:
move_uploaded_file() failed to open
stream: Permission denied in *..
I've set the upload directory to 777 which worked fine, but my script is needed to have top level permissions..
(As the script itself sets permission to directories, does lots of copying etc)
Is there a way in apache I can set the PHP script to the owner of all the folders on my server?
Thanks
Also
When looking in phpInfo()
Under
apache2handler
User/Group nobody(99)/99
Is this related?
I wouldn't go that route, just give it permissions to the defined upload_tmp_dir, or define upload_tmp_dir to be a directory you have access to. If it is that directory you have problems with. If the target is the problem, and you've 777'ed it, something fishy is going on.
Do you have ssh access to your new host? The reason I ask is that it's probably not best to use the username/group as nobody, as most other services would use this too. I would change it to something like apache
You can then update httpd.conf, adding in these two lines (reloading the config after):
User apache
Group apache
Then, run chown apache:apache -R dir_name to make apache own it.
well,
When you are trying to set the permission like "0777", you must be running on same authority.
What I mean is.
For example, your script tells to change a folder/file permission to 0777, but the folder or file already has a permission and that is '0755' so you are not authorised to make that change. as the user have only 5 authority.
Either, you need to login to FTP and change the folder permission to 0777 and then you have full control over it or you have to stick with using 0755 or similar.

Categories