I'm trying to troubleshoot this error, but I have had no luck.
Warning: mkdir() [function.mkdir]: Permission denied in Users/myuser/Sites/mysite.me/git/framework/libs/smarty/sysplugins/smarty_internal_write_file.php
I keep getting the mkdir() [function.mkdir]: permission denied error in one particular folder. I have made sure to chmod 777 foldername through linux and it still hasn't worked. I am doing this on a local machine through XAMPP. I've also made sure to make sure it is read and write for everyone from a GUI standpoint. I'm still having no luck. Thoughts?
I'm getting a warning for mkdir, chmod, touch, rename, and include.
For anybody who ends up here from there:
https://stackoverflow.com/questions/12801733/php-upload-outside-web-root-permission-denied-to-mkdir was marked as an exact duplicate of this thread. That thread was also cross-posted to the AWS forums where it received an answer.
That said, the accepted answer here is actually wrong. (Maybe not wrong wrong, but still somewhat wrong.) The better way to approach this is to have the owner/group of the Apache process match the owner/group of the directory that you want Apache (and in-turn, PHP) to be able to write to.
This way, you're granting access to specific, managed users instead of opening up your file system permissions too broadly.
Add write permissions for all users (or at least webserver user eg. www-data for apache) in which mkdir is creating the directory.
Related
Accidentally i rewrote all folders permission from root.
chown -R www-data:www-data /
Just for example. Luckily i have another server. So i started fix all permissions manually one by one. And now everything seems work fine except for one thing: php can't write files.
I have a suggestion that some php or apache process have wrong permissions.
So symptoms:
The stream or file "/var/www/vhosts/.../httpdocs/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
Yes. I'm sure that files have correct permissions. Because this recursive process was not so fast to override /var folder too. At least some domain still untouched. So i checked it out.
Maybe it would be helpful to know that i use plesk. Because some .sock files could be located there.
I have no idea what i did but it works now. I hope one day it could be useful for someone too.
Just run script if you use plesk
/usr/lib/plesk-9.0/install_suexec
So in the we could say i just reinstall script.
I'm a bit confused here in Symfony functionality terms. I have a website which is supposed to write sessions in /var/lib/php/sessions/. I'm confused right there, because in /var/www/html/myproject/ everything is recursively property of www-data:www-data (yes, I'm using Apache). However the owner of /var/lib/php/sessions/ is root, so when Apache tries to write there, I get a 500 server error regarding writing permissions in that directory.
I have divided opinions here. Some people advice me to modify config.yml to manage sessions inside the project directory, while other people say that is a really bad practice. But, how do I get everything targeting /var/lib/php/sessions/ without that file permission error?
Here's what I get via Apache URL:
Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
Here's what I get via php development webserver:
Warning: SessionHandler::read(): open(/var/lib/php/sessions/sess_u3eg1842nlpkbm0rvddrq37dc2, O_RDWR) failed: Permission denied (13)
500 Internal Server Error - ContextErrorException
I really hope you can help me.
In order to create a file the user must have write and execute permission on the directory.
mkdir /tmp/foo
chmod 300 /tmp/foo
touch /tmp/foo/bar
test -e /tmp/foo/bar
In your case setting the 'other' permissions to 3 would allow www-data to write to it. chmod o+wx /var/lib/php/sessions/
In order to remove a file the user must also have write and execute permission on the directory.
In order to list the file names in a directory the user must have read permission on the directory. Note that if you know the filename it's not required to have permissions for listing the directory.
In order to list the properties of a file the user must have execute permission on the directory.
On my computer the permission for /var/lib/php/sessions is drwx-wx-wt. The t indicates execute & sticky bit. Sticky bit for directories means only the owner can delete it.
See Unix File and Directory Permissions and Modes by Wayne Pollock for more info.
I see that similar questions have been answered on Stack Overflow, but the solutions haven't fixed my particular problem, so I have to ask...
I have an app that needs to make directories and modify files outside the site directory. This works find on the production server.
After spinning up a test server with the exact same version of Ubuntu and PHP, I'm getting errors on the staging server when it tries to open files or create directories.
Here are the errors:
mkdir() [http://php.net/function.mkdir]: Permission denied
fopen(/root/Dropbox/Backend/Booth-01/settings.sh) [http://php.net/function.fopen]: failed to open stream: Permission denied
Things I have tried:
checking the username running the application (it's www-data)
changing the owner of the external directory recursively to www-data
changing permissions on the directory to 777 (I know, this is a bad idea, but I was just trying it to see if that would help until I figured out what the issue was and will change the permissions to something more restrictive once I get it working)
checking the umask value. It was set to 0002, which shouldn't give me problems. Just for kicks, I tried changing it to 0000 and it didn't help.
checking to make sure PHP's safe mode wasn't enabled.
checking to make sure that nothing was specified in open_basedir. In any case, if that was the issue, it would throw a different error message.
I can't think of what to try next and I'm hoping that someone else is seeing something that I'm not.
Ubuntu 12.04.5 x64
PHP 5.3.10
It's not only the folder itself you have to have permissions on. You should also check the parent folders. I think, if you check this, this will fix your problem.
If this is an external drive (see if it shows up in mount) then you may have to remount it. An auto-mounted external drive can thwart permissions
sudo umount <moint-point>
sudo mount /dev/<device> <new-moint-point>
I have written a PHP script for file uploading and for testing I gave my upload directory 777 permissions. The script works fine.
Now I want to remove execute permissions for obvious reasons, but once I do that, I get the following error:
move_uploaded_file([filepath]) [function.move-uploaded-file]: failed to open stream: Permission denied
Just taking the permissions down from 777 to 776 causes this error to appear when I try to upload a file. I don't understand why having execute permissions should have anything to do with this - can someone PLEASE shed some light?
Thank you!
A directory must have execute permission to be accessible in Unix & Linux.
Quoting from here:
On a directory, the execute permission (also called the "search bit")
allows you to access files in the directory and enter it, with the cd
command, for example. However, note that although the execute bit lets
you enter the directory, you're not allowed to list its contents,
unless you also have the read permissions to that directory.
I agree with lserni that the fact that revoking execute permission on the directory for O (the third digit) causes the problem is worrisome as it indicates that the webserver is accessing the directory neither as owner nor as member of the group. You should fix that.
Just taking the permissions down from 777 to 776 causes this error to appear
This shouldn't happen. You ought to be able to run with 770 permissions, i.e., the directory should be owned by the Website user ID, with the group of web server.
This way the owner and the webserver are both able to manipulate the directory and the data. Ideally the Web server serving your website ought to assume the same user ID as the website owner, and that way you can keep the directory mode 700 and have it read-writeable and listable only by you.
If the last digit of the permissions is biting you, it means that the server is running with permissions for "everyone", which may be okay for a development site but isn't too good on a shared site (imagine your passwords being readable by any other website owner in the machine).
However, if you're running on a test machine, the 777 permissions are okay. Directory executable bit does not mean executable (a directory can't be executed anyway) but merely 'listable'. Without that bit, you can create and delete files but you can't know whether they're really there, and move_uploaded_files is objecting to this situation.
There are other solutions (e.g. chrooting each virtualhost in Apache); see also What are best practices for permissions on Apache-writable directories?
for removing the execute permissions you need to execute following commands..
chown -R nobody upload_directory
chmod -R 755 upload_directory
The first command changes the owner of your upload_directory and files under it to 'nobody' which is what php operates under. The second changes the upload_directory and files to only allow user access to writing. -R is for Recursive..
im running on windows xp and i am an administrator, im using the latest xampp bundle available from their site and i receive these kinds of errors when i use file manipulation functions on php...
Warning: chmod() [function.chmod]: Permission denied in...
Warning: opendir(/feeds) [function.opendir]: failed to open dir: Permission denied in
do i need to set any environment variables for apache before i can use these functions?
but i think the problem lies only on my folder access permissions, but if so, how do i set a folder's accessibility properties on windows?
Does your php worker process have the necessary permissions?
Make sure whatever user the process is running as has proper permissions for the directory it is puking on.
right click on the folder, permissions...
it appears that my script referred to an inexistent directory as i just specified $dir='/feeds';it works fine on my machine in our office but i wonder why with the same configurations here on my pc at home it doesnt
as reference for other people who might have the same problem in the future my answer would be
check and make sure you are pointing your script to the right file :)
You can try setting the umask as well before the chmod like so;
$old_mask = umask(0);
chmod('/path/to/file', 0755);
umask($old_mask);
More information on umask can be found at PHP's Manual