I my VPS 2012 R2 i have a plesk configured and a domain when iam trying to create and write a text in txt file that gives me error i tried all possible ways to fix it am not able to do
My PHP
<?php
$myfile = fopen("E:Lognewfile.txt", "w") or die("Unable to open file! " . var_export(error_get_last(), true));
$txt = "Mickey Mousen";
fwrite($myfile, $txt);
$txt = "Minnie Mousen";
fwrite($myfile, $txt);
fclose($myfile);
?>
Error :
PHP Warning: fopen(): open_basedir restriction in effect. File(E:Log
ewfile.txt) is not within the allowed path(s): (C:/Inetpub/vhosts/test.in;C:WindowsTemp) in C:Inetpubvhoststest.inhttpdocsTest.php on line 2
PHP Warning: fopen(E:Log
ewfile.txt): failed to open stream: Operation not permitted in C:Inetpubvhoststest.inhttpdocsTest.php on line 2
2
Answers
You’ve got
open_basedir
turned on which limits where PHP is allowed to read and write files (to protect against potential attacks or bugs that could read or write any file on the filesystem). Either remove the setting or write to a file within the configured base dir.http://php.net/manual/en/ini.core.php#ini.open-basedir
Beside of
open_basedir
, your PHP script executes under special system user which has permissions only inside ofC:/Inetpub/vhosts/test.in
Also check this “Additional write/modify permissions” in “Hosting Settings”: