Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mkdir: Permission denied problem

Tags:

php

I am trying to create a directory with PHP mkdir function but I get an error as follows: Warning: mkdir() [function.mkdir]: Permission denied in .... How to settle down the problem?

like image 223
folos Avatar asked Mar 09 '11 12:03

folos


1 Answers

I know this is an old thread, but it needs a better answer. You shouldn't need to set the permissions to 777, that is a security problem as it gives read and write access to the world. It may be that your apache user does not have read/write permissions on the directory.

Here's what you do in Ubuntu

  1. Make sure all files are owned by the Apache group and user. In Ubuntu it is the www-data group and user

    sudo chown -R www-data:www-data /path/to/webserver/www

  2. Next enabled all members of the www-data group to read and write files

    sudo chmod -R g+rw /path/to/webserver/www

The php mkdir() function should now work without returning errors

like image 184
simpleengine Avatar answered Oct 07 '22 10:10

simpleengine