Mostafa Talebi
Mostafa Talebi

Reputation: 9183

PHP Does not have the permission to create a new file nor to write into a file

(Linux CentOS 7) I have installed Zend Serve 8. When I want to visit a project (for now it is OpenCart, but I also tested it with Laravel), it throws error that Permission is Denied for some file (does not allow it to write). Here is the error:

 Warning: mkdir(): Permission denied in /var/www/html/project/dir/install.php on line 26

But there are some other error exactly like the above error with the only difference in function (file_put_contents()). What should I do? Is ZendServer denied or PHP ?

Upvotes: 0

Views: 630

Answers (1)

Martin
Martin

Reputation: 22770

You need to set the permissions level on the directory you are wanting PHP to work on. Open your directory in SFTP or whatever and change it's permissions to Owner Read,Write,Execute and Group Read,Write,Execute and others, just Read - summarised as setting it to 774. This may not be the best - most secure setup (I'm sorry I'm not more expert on this exact topic), but it works for me. It is because the folder is not created by PHP and when it was created it was set to not allow others to save and write to it.

Displayed:

        Read | Write | Execute
Owner    X       X        X
Group    X       X        X     <-- see * 
Others   X 

Also seen as #774 .

  • On your file system this is the category that PHP is very probably set in, it is not the owner of the directory so it will not have been given the permissions illustrated above. Change the permissions to the above setup and PHP should now be able to work in that folder.

Edit:

Important: Make the changes recursive!

Upvotes: 3

Related Questions