我想爲我的PHP項目做一個安裝程序。我需要將以下塊添加到<VirtualHost *:80>
。以下是我的安裝程序腳本的一部分:如何在php中打開一個linux文件?
<?php
$path = "/var/www/html/myProject";
$default_conf = shell_exec('cat /etc/apache2/sites-available/000-default.conf');
$new_directory = "<Directory $path/public>
Allow Override all
Require all granted
</Directory>";
$res = str_replace("</VirtualHost>","$new_directory</VirtualHost>", $default_conf);
file_put_contents("/etc/apache2/sites-available/000-default.conf",$res);
但是$default_conf
爲空。爲什麼?我該如何解決它?
注意,在命令行環境
cat /etc/apache2/sites-available/000-default.conf
此命令的結果是000-default.conf
文件而這正是如預期(它不是空的)的內容。
您是否嘗試過'error_reporting(E_ALL); ini_set('display_errors',1);'在頂部 - 您可能會收到'Permission denied'消息。 –
@NigelRen我的腳本名稱是'installer.php',我已經運行了這個命令:'sudo chmod 777 installer.php' – stack
看起來像web服務器用戶沒有權限做,或者你可能需要絕對路徑爲你的' cat'命令 –