简体   繁体   中英

Permission denied using mkdir in PHP

I tried to create the directory /home/freestyle/test like this

$location = "/home/freestyle/test";
$uold     = umask(0);

mkdir($location,0777,true);
umask($uold);

but I get the error

Warning: mkdir(): Permission denied in /opt/lampp/htdocs/test/test.php on line 6

I don't want to chmod permission via terminal, I want to do it in PHP directly.

How to do that?

Edit ps aux | grep httpd ps aux | grep httpd shown

root     10868  0.0  0.3 351528 14288 ?        Ss   09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11263  0.0  0.1 347600  5500 ?        S    09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11266  0.0  0.3 352036 11864 ?        S    09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11267  0.0  0.3 352852 12864 ?        S    09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11268  0.0  0.3 352036 11868 ?        S    09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11269  0.0  0.3 352128 12308 ?        S    09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11270  0.0  0.3 351944 11848 ?        S    09:41   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11329  0.0  0.3 352088 12088 ?        S    09:42   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11444  0.0  0.3 351900 11348 ?        S    09:44   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11922  0.0  0.2 351528 10572 ?        S    10:09   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11946  0.0  0.2 351528 10984 ?        S    10:10   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
daemon   11953  0.0  0.2 351528 10120 ?        S    10:11   0:00 /opt/lampp/bin/httpd -k start -E /opt/lampp/logs/error_log -DSSL -DPHP
freestyle   12516  0.0  0.0  15124   984 pts/5    S+   10:42   0:00 grep --color=auto httpd

You first need to make sure you have the right permissions for /home/freestyle/ to do this run ls -l /home/freestyle/ from your terminal

than run (*depending on your apache configs, in my case it's www-data)

chown "www-data:www-data" /home/freestyle/

and ls -l /home/freestyle/ again to see if permission changed

UPDATE*

from the output you've provided it looks like your apache runs under daemon . to give permissions for /home/freestyle/ run:

chown "daemon:daemon" /home/freestyle/

UPDATE 2*

to change apache ownership user and group, change/add the following in your apache configs

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM