I have assign anyone the right to read and write.
chmod 777 -R /home/test
An error occurred When to remove it with php function:
rmdir('/home/test');
Warning: rmdir(/home/test): Permission denied
Having 777 permission to /home/test isn't enough, the process trying to remove it also needs to have permission to alter /home (since removing /home/test constitute a change to /home).
The answer is likely that you have an ownership issue. The directory is probably owned by another user and group.
You can change this by using the chown command which stands for change ownership.
chown user:group directory/file.extension
Related
Im getting denied running the following function (which is located in
/var/www/mysite/public_html/app/Controllers/Script.php)
$structure = '/var/www/mysite/public_html/app/Controllers/folder1/newfolder';
if (!mkdir($structure, 0755, true)) {
die();
}
I dont want to give to the web server general root permissions and also I want to keep folder1 in 755.
What I did is to edit the sudoers file trying to give to apache root permisions just in that specific path, I added this line:
www-data ALL=NOPASSWD:
/var/www/mysite/public_html/app/Controllers/Script.php
However Im still getting the same error, what is missing here?
I do not know anything about php but must likely you is running them scripts with the wrong user
check who’s the owner of the dir.
$ ls -lash
change ownership.
$ sudo chown -R $USER:$USER /path/to/dir
chown changes owner
‘-R’ change the ownership of subdirs and files
$USER current user
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?
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.
Having an issue with unlink() even when executing a script as root.
Getting this error:
Warning: unlink(/var/www/html/services/training/add.php): Permission denied in /var/www/html/sites/services/functions.php on line 228
The owner of the file is root and the file permissions are 775 so it should work.
Are there any further steps I can take to troubleshoot this? Not sure where to go from here...
Open your terminal .. I guess you are an ubuntu user
so just do this
sudo chmod 777 -R /var/www/html/services/
By Default your access is limited . So you have to extend your access using this chmod command :) .. that's it :)
$handle = fopen('/Applications/XAMPP/xamppfiles/htdocs/test/file.txt', 'w');
I tried doing the above and every time I try it, the following statement appeared on my browser:
Warning:fopen(/Applications/XAMPP/xamppfiles/htdocs/test/file.txt)
[function.fopen]: failed to open stream: Permission denied in
/Applications/XAMPP/xamppfiles/htdocs/test/index.php on line 26.
I tried looking through answered questions with the same type of questions but most of the things I tried did not work. For example, writing the full directory...
Maybe, you have no premissions to acces the file. One of the answet, is that, you must change CHMOD to e.g. 777. You can co it with your ftp explorer or with PHP.
chmod("/somedir/somefile", 777);
By default when XAMPP is installed, the htdocs folder does not have any read permissions. You can change the permissions through the terminal like this.
cd /Application/XAMPP/xamppfiles/htdocs/test/
sudo chmod 0664 file.txt
Alternatively, you can recursively set all the permission level of all files and folders
cd /Application/XAMPP/xamppfiles/
sudo chmod -R 0664 htdocs/
You could chmod to 777, but that is risky security. What I'm guessing you really want is change ownership of the file. You can do this using chown. PHP usually runs as user www-data, so you'd run a command something like this.
sudo chown www-data:root path/to/file.ext
If you're file permission on the file was something normal like 664, that'd give PHP the 6 permission (Read and Write) instead of the 4 (just Read).
When I use chmod() to change permissions at run time, it gives me the below message:
Warning: chmod() [function.chmod]: Operation not permitted in /home/loud/public_html/readalbum.php
How can I remove this error and make the chmod function work?
$ sudo chmod ...
You need to either be the owner of the file or be the superuser, i.e., user root. If you own the directory but not the file, you can copy the file, rm the original, then mv it back, and then you will be able to chown it.
The easy way to temporarily be root is to run the command via sudo. ($ man 8 sudo)
In order to perform chmod, you need to be owner of the file you are trying to modify, or the root user.
This is a tricky question.
There a set of problems about file permissions. If you can do this at the command line
$ sudo chown myaccount /path/to/file
then you have a standard permissions problem. Make sure you own the file and have permission to modify the directory.
If you cannnot get permissions, then you have probably mounted a FAT-32 filesystem. If you ls -l the file, and you find it is owned by root and a member of the "plugdev" group, then you are certain its the issue. FAT-32 permissions are set at the time of mounting, using the line of /etc/fstab file. You can set the uid/gid of all the files like this:
UUID=C14C-CE25 /big vfat utf8,umask=007,uid=1000,gid=1000 0 1
Also, note that the FAT-32 won't take symbolic links.
Wrote the whole thing up at http://www.charlesmerriam.com/blog/2009/12/operation-not-permitted-and-the-fat-32-system/
You, or most likely your sysadmin, will need to login as root and run the chown command:
http://www.computerhope.com/unix/uchown.htm
Through this command you will become the owner of the file.
Or, you can be a member of a group that owns this file and then you can use chmod.
But, talk with your sysadmin.