Last active
August 29, 2015 13:55
-
-
Save simonrjones/8738780 to your computer and use it in GitHub Desktop.
Finding the Apache user in PHP, see http://www.simonrjones.net/2009/10/finding-apache-user/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Error reporting | |
error_reporting(E_ALL); | |
ini_set('display_errors', true); | |
// Return the Apache user | |
$tmpFilename = tempnam('/tmp', 'TEST'); | |
$handle = fopen($tmpFilename, 'w'); | |
fwrite($handle, 'testdata'); | |
fclose($handle); | |
$info = posix_getpwuid(fileowner($tmpFilename)); | |
$apacheUser = $info['name']; | |
unlink($tmpFilename); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Apache user</title> | |
<style> span.fixed { font-family: courier, fixed; } </style> | |
</head> | |
<body> | |
<h1>Apache user</h1> | |
<p>The current Apache user is: <span class="fixed"><?php echo $apacheUser; ?></span></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment