代码之家  ›  专栏  ›  技术社区  ›  stack

如何在php中打开linux文件?

  •  1
  • stack  · 技术社区  · 9 年前

    我正在尝试为我的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 与预期完全一致的文件

    1 回复  |  直到 9 年前
        1
  •  0
  •   zaf    9 年前

    为什么不试试这个功能呢 file\u get\u内容

    http://php.net/manual/en/function.file-get-contents.php

    此外,您可以使用 和