Create a gist now

Instantly share code, notes, and snippets.

Finding the Apache user in PHP, see http://www.simonrjones.net/2009/10/finding-apache-user/
<?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