gpt4 book ai didi

java - PHP 为 ls 命令返回问号

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:35:46 27 4
gpt4 key购买 nike

我已经遇到这个问题大约一个星期了。但是,似乎只有在这台服务器上我才会收到所有这些错误。我已经尝试使用不同的分区多次重新安装操作系统,并且发生了完全相同的事情。现在,我不知道为什么会这样。

问题是,出于某种原因,当运行命令 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 Screen) 之类的命令时,这会变得更成问题。 Screen 需要使用位于 /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

当在用户 root 下通过 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/运行。更改目录的权限没有任何作用,从 root 用户重新创建目录并使所有者成为 Web 服务器用户也是如此。

尽管这是一个修复,但并不总是意味着一切都会正常工作。如果我随后尝试在屏幕内启动 JVM(命令 java),则会返回此错误:

Error occurred during initialization of VM
Could not reserve enough space for code cache

在这一点上,我只是屈服了,因为我不知道发生了什么。

任何人都可以阐明我的情况并尝试解释发生了什么或为我提供解决方案。

发生这种情况的机器是一台运行 CentoOS 6.4 的专用服务器,配备 16GB 内存、500GB 硬盘和 Intel(R) Xeon(R) 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 /`;
?>

最佳答案

此问题与 SELinux 有关。 禁用它解决了问题。这是因为进程正在尝试执行子进程。

关于java - PHP 为 ls 命令返回问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19370790/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com