I have a previously working PHP script that is able to create a directory with mkdir
:
$webfolder = "/var/www/html/images/user";
mkdir($webfolder, 0770);
I made some changes to the permission setting of the folder /var/www/html/images
which is now:
drwxrwx---. myself apache system_u:object_r:httpd_sys_content_t:s0 images
I think previously this folder was owned by apache
. But since apache
has the full privileges of read, write and execute as a user group, I wonder why it can't create a folder within. Using the mkdir
produces a false
boolean value.
Is the problem due to directory ownership or is there some other reasons? Note that I am using PHP version 5.4.
Error Log added:
[Mon Dec 17 11:12:34 2012] [error] [client 127.0.0.1] PHP Warning: mkdir(): Permission denied in /var/www/html/upload on line 33, referer: https://mywebsite.com/referer
Resolving The Problem Simply log in as super user “su” and use “chmod 777” to set the directory permissions of where you wish the rational directory to be created. Once done, you can re-enter the original directory again and the install will continue using the same directory.
mkdir: cannot create directory – Permission denied The reason for this error is that the user you're running the mkdir as, doesn't have permissions to create new directory in the location you specified. You should use ls command on the higher level directory to confirm permissions.
[ErrorException] mkdir(): Permission denied That means you do not have write permission on your project folder. Create a new folder, say 'myproject and run sudo chmod 777 myproject . Then move to 'myproject' folder and create project.
Methods: file_exists(): It is an inbuilt function that is used to check whether a file or directory exists or not. is_dir(): It is also used to check whether a file or directory exists or not. mkdir() : This function creates a directory.
The answer is staring right in front of me, but I miss it due to my unfamiliarity with SELinux.
The SELinux context type should be set as httpd_sys_content_rw_t
instead of httpd_sys_content_t
so that the folder is both readable and writable for apache. Changing the context recursively is done with the following command:
# chcon -R -t httpd_sys_content_rw_t /var/www/html/images
Good grief. Hope it helps others who come across this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With