PHP mkdir permission denied Ubuntu Linux

Permission denied issue mostly come in two cases,
In first case, check the directory which you want to access have write permission

To check,

cd /opt/lampp/htdocs/parent-dir/
ls -al

For image-dir directory do not have write permission.

drwxrwxrwx 62 root     root        4096 Apr 29 16:32 .
drwxrwxrwx 38 root     root        4096 Apr 28 18:44 ..
-rwxrwxrwx  1 root     root         460 Jun 19  2015 index.php
drwxr-xr-x  2 root     root        4096 Jun 19  2015 image-dir
-rwxrwxrwx  1 root     root         728 Jun 19  2015 header.php
-rwxrwxrwx  1 root     root         360 Jun 19  2015 footer.php

To give full permission to the directory image-dir recursively,

chmod -R 777 image-dir/

In second case, Apache runs under daemon. So the ownership of the directory may be daemon.

drwxrwxrwx 62 root     root        4096 Apr 29 16:32 .
drwxrwxrwx 38 root     root        4096 Apr 28 18:44 ..
-rwxrwxrwx  1 root     root         460 Jun 19  2015 index.php
drwxrwxrwx  2 daemon     daemon        4096 Jun 19  2015 image-dir
-rwxrwxrwx  1 root     root         728 Jun 19  2015 header.php
-rwxrwxrwx  1 root     root         360 Jun 19  2015 footer.php

To change it,

chown daemon:daemon image-dir

To fix it permanently, Open Apache config file

/opt/lampp/apache2/conf/httpd.conf

And add and save the following configs, then restart apache and check.

export APACHE_RUN_USER=your_user_name
export APACHE_RUN_GROUP=your_user_name

 

PHP Apache Ubuntu Linux Posted on 2016-05-05 08:39:27