我有一个PHP脚本应该更新用户列表和grouplist文件。我可以读取这两个文件,但在尝试写入时我得到权限被拒绝错误:
警告:file_put_contents(/ etc / httpd / conf / userlist):无法打开流:第60行/var/www/html/add_admin.php中的权限被拒绝
我在群组列表中遇到同样的错误。
我非常确定服务器上的所有权限都已正确设置,但它仍无效。
php页面的权限:
-rwxrwxrwx. 1 apache webdev 2022 Sep 1 11:30 add_admin.php
/ etc / httpd / conf:
的权限drwxrwxrwx. 2 apache webdev 4096 Sep 1 11:28 conf
/ etc / httpd / conf中的权限:
-rwxrwxr--. 1 apache apache 32 Aug 30 13:45 grouplist
-rwxrwxr--. 1 root root 35661 Aug 30 14:26 httpd.conf
-rwxrwxr--. 1 root root 35405 Aug 30 12:19 httpd.conf.bak
-rwxrwxr--. 1 root root 13139 Oct 16 2014 magic
-rwxrwxr--. 1 apache apache 385 May 26 14:23 userlist
-rwxrwxr--. 1 root root 328 May 26 13:54 userlist.bak
守则:
<html>
<head>
<title>Admin Creation Tool</title>
<style>
#userInfo{
width: 300px;
}
</style>
</head>
<body>
<form action="add_admin.php" method="post" enctype="multipart/form-data" id="uploadForm">
<input type="text" placeholder="username" name="username" id="username" required/><br>
<input type="password" placeholder="password" name="password1" id="password1" required/><br>
<input type="password" placeholder="Re-enter password" name="password2" id="password2" required/><br>
<input type="checkbox" id="isAdmin" name="isAdmin"/>Administrator<br>
<input type="submit" value="Add User" name="submit" id="submit" />
</form>
<script>
var password = document.getElementById("password1")
, confirm_password = document.getElementById("password2");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
</script>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_POST["submit"])) {
$groupFileDir = "/etc/httpd/conf/grouplist";
$userListDir = "/etc/httpd/conf/userlist";
$username = $_POST["username"];
$password = $_POST["password1"];
$encryptedPassword = crypt($password, base64_encode($password));
echo file_get_contents($userListDir); //This is just a test for reading
file_put_contents($userListDir, $username . ":" . $encryptedPassword . "\n", FILE_APPEND);
echo "User Added";
if(isset($_POST["isAdmin"])){
file_put_contents($groupFileDir, " " . $username, FILE_APPEND);
echo " as Administrator";
}
}
?>
</body>
</html>
我对linux并不擅长,所以我可能会错过一些东西,但我是由我友好的邻居linux大师运行的,而且他也很困惑。