从 php 获取 apache linux 用户 [英] Get apache linux user from php

查看:28
本文介绍了从 php 获取 apache linux 用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个外国的 linux 系统上,需要确定运行 apache 的用户(php 也是如此).

I'm on a foreign linux system and need to determine the user that apache runs on (and so does php).

宗旨:我需要获取脚本的所有者(这没有问题,因为我可以使用 SplFileInfo)并将其与 apache 进程的所有者进行比较.

The aim: I need to get the owner of the script (this is no problem as I can use SplFileInfo) and compare it to the owner of the apache process.

我愿意接受任何替代提案.

I'm open to any alternative proposals.

问候,马里奥

附加信息:

该脚本是一个缩略图生成器,它使用 XML 文件从较大的图像生成缩略图.该脚本需要创建文件夹和写入文件.由于我无法影响 php 配置并且我没有任何 shell 访问权限,因此必须非常安静地完成此操作.创建过程通过异常停止并在失败时发送邮件.由于 php 的大部分功能都不能在失败时抛出异常,我需要一些手动检查来确定我所处的环境.因此我需要 apache 用户将其与某个目录或文件所有者进行比较.

The script is a thumbnail generator, that uses an XML file to generate thumbs from larger images. The script needs to create folders and write files. As I cannot influence the php configuration and I do not have any shell access, this has to be done very silently. The creation process stopps via exception and sends a mail on failue. As most of php's function cannot throw exceptions on failue, I need some manual checks to determine the environment I'm in. Therefore I need the apache user to compare it to some directory or fileowner.

推荐答案

您可以调用 php exec 函数来执行whoami:

You can call the php exec function to execute whoami:

<?php echo exec('whoami'); ?>

这篇关于从 php 获取 apache linux 用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆