我一直有这个问题约一个星期了。但是,它似乎只是在这台服务器上,我得到了所有这些错误。我试过用不同的分区多次重新安装操作系统,同样的事情正在发生。现在,我不知道为什么会发生。PHP返回ls命令的问号
问题是,出于某种原因,在运行命令ls
时,PHP会为文件/目录权限和所有者返回很多问号。例如,运行命令ls -al /
时,这是什么返回:
total 96
dr-xr-xr-x. 25 root root 4096 Oct 14 12:52 .
dr-xr-xr-x. 25 root root 4096 Oct 14 12:52 ..
-rw-r--r--. 1 root root 0 Oct 14 12:45 .autofsck
dr-xr-xr-x. 2 root root 4096 Oct 14 13:12 bin
d?????????? ? ? ? ? ? boot
drwxr-xr-x. 17 root root 3740 Oct 14 12:46 dev
drwxr-xr-x. 2 root root 4096 Oct 14 12:52 downloads
drwxr-xr-x. 102 root root 12288 Oct 14 13:12 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 home
dr-xr-xr-x. 11 root root 4096 Oct 14 12:41 lib
dr-xr-xr-x. 9 root root 12288 Oct 14 13:11 lib64
d?????????? ? ? ? ? ? lost+found
drwxr-xr-x. 2 root root 4096 Sep 23 2011 media
drwxr-xr-x. 2 root root 0 Oct 14 12:46 misc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 mnt
drwxr-xr-x. 2 root root 0 Oct 14 12:46 net
drwxr-xr-x. 3 root root 4096 Oct 14 12:41 opt
dr-xr-xr-x. 225 root root 0 Oct 14 12:45 proc
d?????????? ? ? ? ? ? root
dr-xr-xr-x. 2 root root 12288 Oct 14 13:12 sbin
drwxr-xr-x. 7 root root 0 Oct 14 12:45 selinux
drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv
drwxr-xr-x. 13 root root 0 Oct 14 12:45 sys
drwxrwxrwt. 5 root root 4096 Oct 14 13:11 tmp
drwxr-xr-x. 13 root root 4096 Oct 14 12:37 usr
drwxr-xr-x. 22 root root 4096 Oct 14 12:52 var
可以理解,目录/root
和/lost+found
回报问号,因为他们的权限不允许读取和执行为所有用户(如drwx- -----)。但是,尽管目录/boot
允许从所有用户读取并执行(dr-xr-xr-x.
),但该目录也会返回问号。
当我运行诸如screen
(GNU屏幕)之类的命令时,这会变得更加有问题。屏幕要求使用位于/var/run/screen
的目录。不幸的是,每次从PHP运行屏幕时,它都会返回Cannot make directory '/var/run/screen': File exists
。通过SSH运行屏幕时,按预期工作。
当通过PHP运行命令ls -al /var/run
检查目录的权限,它返回:
total 48
drwxr-xr-x. 23 root root 4096 Oct 14 12:52 .
drwxr-xr-x. 22 root root 4096 Oct 14 12:52 ..
d?????????? ? ? ? ? ? ConsoleKit
drwxr-xr-x. 2 root root 4096 Oct 14 12:46 abrt
-rw-r--r--. 1 root root 5 Oct 14 12:46 abrtd.pid
-?????????? ? ? ? ? ? acpid.pid
s?????????? ? ? ? ? ? acpid.socket
-?????????? ? ? ? ? ? atd.pid
-?????????? ? ? ? ? ? auditd.pid
-?????????? ? ? ? ? ? autofs-running
p?????????? ? ? ? ? ? autofs.fifo-misc
p?????????? ? ? ? ? ? autofs.fifo-net
-?????????? ? ? ? ? ? autofs.pid
drwxr-xr-x. 2 root root 4096 Feb 22 2013 certmonger
-?????????? ? ? ? ? ? certmonger.pid
d?????????? ? ? ? ? ? console
-?????????? ? ? ? ? ? console-kit-daemon.pid
-?????????? ? ? ? ? ? cron.reboot
-?????????? ? ? ? ? ? crond.pid
d?????????? ? ? ? ? ? cups
-?????????? ? ? ? ? ? cupsd.pid
drwxr-xr-x. 2 root root 4096 Oct 14 12:46 dbus
drwxr-xr-x. 2 root root 4096 Feb 21 2013 faillock
d?????????? ? ? ? ? ? hald
-?????????? ? ? ? ? ? haldaemon.pid
drwx--x---. 2 root apache 4096 Oct 14 13:04 httpd
d?????????? ? ? ? ? ? lvm
d?????????? ? ? ? ? ? mdadm
-?????????? ? ? ? ? ? messagebus.pid
drwxr-xr-x. 2 mysql mysql 4096 Oct 14 12:52 mysqld
drwxrwxr-x. 2 root root 4096 Feb 22 2013 netreport
d?????????? ? ? ? ? ? plymouth
d?????????? ? ? ? ? ? pm-utils
d?????????? ? ? ? ? ? portreserve
-?????????? ? ? ? ? ? rpc.statd.pid
-?????????? ? ? ? ? ? rpcbind.lock
-?????????? ? ? ? ? ? rpcbind.pid
s?????????? ? ? ? ? ? rpcbind.sock
d?????????? ? ? ? ? ? saslauthd
d?????????? ? ? ? ? ? screen
d?????????? ? ? ? ? ? sepermit
drwxr-xr-x. 2 root root 4096 May 10 05:06 setrans
-?????????? ? ? ? ? ? sm-notify.pid
-?????????? ? ? ? ? ? sshd.pid
-?????????? ? ? ? ? ? syslogd.pid
-?????????? ? ? ? ? ? utmp
drwxr-xr-x. 2 root root 4096 Feb 21 2013 winbindd
当通过SSH运行相同的命令的用户根目录下,以交叉检查的权限的所有目录出现这种情况:
total 164
drwxr-xr-x. 23 root root 4096 Oct 14 12:52 .
drwxr-xr-x. 22 root root 4096 Oct 14 12:52 ..
drwxr-xr-x. 2 root root 4096 Oct 14 12:46 abrt
-rw-r--r--. 1 root root 5 Oct 14 12:46 abrtd.pid
-rw-r--r--. 1 root root 5 Oct 14 12:46 acpid.pid
srw-rw-rw-. 1 root root 0 Oct 14 12:46 acpid.socket
-rw-r--r--. 1 root root 5 Oct 14 12:46 atd.pid
-rw-r-----. 1 root root 5 Oct 14 12:46 auditd.pid
prw-------. 1 root root 0 Oct 14 12:46 autofs.fifo-misc
prw-------. 1 root root 0 Oct 14 12:46 autofs.fifo-net
-rw-r--r--. 1 root root 5 Oct 14 12:46 autofs.pid
----------. 1 root root 5 Oct 14 12:46 autofs-running
drwxr-xr-x. 2 root root 4096 Feb 22 2013 certmonger
-rw-------. 1 root root 5 Oct 14 12:46 certmonger.pid
drwxr-xr-x. 2 root root 4096 Feb 21 2013 console
drwxr-xr-x. 2 root root 4096 Oct 14 12:46 ConsoleKit
-rw-r--r--. 1 root root 5 Oct 14 12:46 console-kit-daemon.pid
-rw-r--r--. 1 root root 5 Oct 14 12:46 crond.pid
----------. 1 root root 0 Oct 14 12:46 cron.reboot
drwxr-xr-x. 3 root lp 4096 Oct 14 12:46 cups
-rw-r--r--. 1 root root 5 Oct 14 12:46 cupsd.pid
drwxr-xr-x. 2 root root 4096 Oct 14 12:46 dbus
drwxr-xr-x. 2 root root 4096 Feb 21 2013 faillock
drwx------. 2 haldaemon haldaemon 4096 Jul 19 2011 hald
-rw-r--r--. 1 root root 5 Oct 14 12:46 haldaemon.pid
drwx--x---. 2 root apache 4096 Oct 14 13:04 httpd
drwx------. 2 root root 4096 Feb 22 2013 lvm
drwx------. 2 root root 4096 Feb 21 2013 mdadm
-rw-r--r--. 1 root root 5 Oct 14 12:46 messagebus.pid
drwxr-xr-x. 2 mysql mysql 4096 Oct 14 12:52 mysqld
drwxrwxr-x. 2 root root 4096 Feb 22 2013 netreport
drwxr-xr-x. 2 root root 4096 Feb 22 2013 plymouth
drwxr-xr-x. 4 root root 4096 Oct 14 12:40 pm-utils
drwxr-xr-x. 2 root root 4096 Oct 14 12:45 portreserve
-r--r--r--. 1 root root 0 Oct 14 12:45 rpcbind.lock
-rw-r--r--. 1 root root 5 Oct 14 12:45 rpcbind.pid
srw-rw-rw-. 1 root root 0 Oct 14 12:45 rpcbind.sock
-rw-r--r--. 1 rpcuser rpcuser 5 Oct 14 12:45 rpc.statd.pid
drwxr-xr-x. 2 root root 4096 Nov 27 2012 saslauthd
drwxrwxr-x. 2 root screen 4096 Jul 19 2011 screen
drwxr-xr-x. 2 root root 4096 Feb 21 2013 sepermit
drwxr-xr-x. 2 root root 4096 May 10 05:06 setrans
-rw-------. 1 root root 5 Oct 14 12:45 sm-notify.pid
-rw-r--r--. 1 root root 5 Oct 14 12:46 sshd.pid
-rw-------. 1 root root 5 Oct 14 12:45 syslogd.pid
-rw-rw-r--. 1 root utmp 3456 Oct 14 12:47 utmp
drwxr-xr-x. 2 root root 4096 Feb 21 2013 winbindd
同样,像/boot
目录,似乎目录,尽管具有允许读取和写入所有用户的权限(drwxrwxr-x.
- chmod 0775),为权限和所有者返回问号。
我只设法找到一个或两个问题关于屏幕返回的这个错误,其中没有人回答。我设法解决这个问题,让它工作就是删除/var/run/screen
目录,让PHP通过允许用户写入目录/var/run
来重新创建这个目录。更改目录的权限不会执行任何操作,所以从root用户重新创建目录并使拥有者成为Web服务器用户。
即使这是一个修复,它并不总是意味着一切都会正常工作。如果我再尝试启动屏幕内的JVM(命令java
),返回此错误:
Error occurred during initialization of VM
Could not reserve enough space for code cache
在这一点上,我只是给于我有没有线索,发生了什么。
任何人都了解我的情况有一些启发,试图解释发生了什么或者我提供了一个修补程序。
这台机器正在运行的是一台运行CentoOS 6.4的专用服务器,配有16GB RAM,500GB硬盘和Intel(R)Xeon®CPU E3-1230 V2 @ 3.30GHz。使用命令parted
然后print
这是什么返回有关分区:
Model: ATA WDC WD5003AZEX-0 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 466GB 466GB primary ext3 boot
2 466GB 500GB 34.4GB primary linux-swap(v1)
PHP是不是在安全模式下运行。
这是我运行以获取ls
命令等的代码,每次都从Web服务器运行。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
echo `whoami`;
echo "\n";
echo `ls -al /var/run`;
echo "\n";
echo `ls -al /`;
?>
你用来调用'ls'的PHP代码在哪里? –
@HamzaKubba更新时间 –
什么是您的PHP用户?你是否通过SSH登录并执行命令?也许'sudo'(如果在CentOS中可用)可以帮助您获得正确的权限(您只需要提升该单个脚本的权限)? – Fleshgrinder