我正在尝试为我的PHP项目制作一个安装程序。我需要将以下块添加到
<VirtualHost *:80>
<?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
与预期完全一致的文件