I'm trying to make an installer for my PHP project. I need to add the following block into <VirtualHost *:80>
. Here is a part of my installer script:
- <?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);
But $default_conf
is empty. Why? How can I fix it?
Noted that the result of this command in the command line environment
cat /etc/apache2/sites-available/000-default.conf
is the content of 000-default.conf
file which is exactly as expected (it is not empty).