2016-07-25 65 views
1

我正在建立一个亚马逊Web服务堆栈,我想在/etc/apache2/sites-enabled/000-default.conf中配置文档根目录,我目前通过修改该文档的DocumentRoot。然后我在/etc/apache2/apache2.conf中反映了这种改变。是否可以使用命令行进行这些更改,而不是打开和编辑文件?提前致谢。用命令行更改文档根

+0

是的,你必须使用命令行编辑器来编辑像“nano” – error2007s

回答

0

你可以用sed来做。我用下面的包装功能,使其更方便:

replace_string() { 
    while :; do 
     case $1 in 
       file=?*) local file=${1#*=} ;; 
      replace=?*) local replace=${1#*=} ;; 
       with=?*) local with=${1#*=} ;; 
        *) break     ;; 
     esac 
     shift 
    done 

    sudo sed -i -- "s/$replace/$with/ig" $file 
} 

replace_string file='/etc/apache2/sites-enabled/000-default.conf' \ 
       replace='.*DocumentRoot.*' \ 
        with='DocumentRoot path-to-your-document-root' 


replace_string file='/etc/apache2/apache2.conf' \ 
       replace='.*DocumentRoot.*' \ 
        with='DocumentRoot "path-to-your-document-root"' 

记住,用户运行此脚本应该能够使用sudo没有密码的。