PHP: get_current_user() vs. exec('whoami')

戏子无情 提交于 2019-11-29 01:28:34
  1. get_current_user() (should) return the owner of the file, which is firstnamelastname in this case. There have been reported issues that this function is inconsistent between platforms however. As such, I would not trust its output. daemon is the user Apache is running as.
  2. The owner of the PHP script is the user who owns the file itself according to the operating system. You can run ls -la in the directory your scripts are in to find the user and group the file belongs to.
  3. Whichever user you're editing your scripts with needs to be able to write it, so most likely, firstnamelastname (+rw).
  4. For the folder itself, you should have +rx (execute and read) for daemon and for the PHP file, +r (read). On my installation of XAMMP, they've done this by setting everything in htdocs as public readable, thus daemon can read it, but not write to it.
  5. Mac has a root account that typically owns the htdocs or www directory. It fills the role of a traditional unix root user.

Here is some information on the file owners/groups and the process owner:

host:~$ ls -l /Applications/XAMPP/xamppfiles/htdocs
drwxr-xr-x 3 root admin  4096 2015-01-01 00:01 .
drwxr-xr-x 3 root admin  4096 2015-01-01 00:01 ..
-rw-r--r-- 1 firstnamelastname admin   189 2015-01-31 20:45 index.php

host:~$ ps aux | grep httpd | head -n1    
daemon          45204   0.0  0.1  2510176  10328   ??  S    Tue11AM   0:01.38 /Applications/XAMPP/xamppfiles/bin/httpd -k start -E /Applications/XAMPP/xamppfiles/logs/error_log -DSSL -DPHP

If you wanted to make a file writeable by the daemon user, you can create a new folder and name it as the owner with the group admin (so you can use it too), and give it +rwx for the user and group, with +rx for public:

host:~$ cd /Applications/XAMPP/xamppfiles/htdocs
host:htdocs$ mkdir some_dir
host:htdocs$ chmod 775 some_dir
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!