我的配置文件中的Apache的根目录

时间:2016-04-22 13:20:04

标签: apache directory vagrant root

我有一个问题。我终于找到了如何更改apache的根目录。我只需编辑这行代码DocumentRoot /var/www/html,但由于vagrant是惊人的并且有这个配置脚本,我想我可以从这里告诉apache根目录。 因为每次我创建一个可以节省大量时间的新网站时,我都可以使用这个配置脚本。我不一定要去配置文件并且每次都改变它

增加:

这就是我的配置脚本现在的样子:

#!/usr/bin/env bash

PROJECT="foundation"
PROJECT_LOG="foundation"

MYSQL_PASSWORD="wachtwoord"

set -o nounset -o errexit -o pipefail -o errtrace

error() {
   local sourcefile=$1
   local lineno=$2
   echo "ERROR at ${sourcefile}:${lineno}; Last logs:"
   grep "${PROJECT}" /var/log/syslog | tail -n 20
}

trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

oe() { "$@" 2>&1 | logger -t "${PROJECT}" > /dev/null; }
ol() { echo "[${PROJECT_LOG}] $@"; }

export DEBIAN_FRONTEND=noninteractive

ol 'Updating repository caches'
oe sudo apt-get -q -y update

ol 'Adding apt repositories'
oe sudo apt-get -q -y install python-software-properties
oe sudo add-apt-repository ppa:ondrej/php5-5.6

ol 'Updating repository caches (second time)'
oe sudo apt-get -q -y update

ol "Installing misc packages"
oe sudo apt-get -q -y install language-pack-nl

ol 'Installing Apache 2'
oe sudo apt-get -q -y install apache2
oe sudo systemctl restart apache2
oe sudo systemctl status apache2

ol "Installing PHP"
oe sudo apt-get -q -y install php5 libapache2-mod-php5 php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcached php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache


debconf-set-selections <<< 'phpmyadmin phpmyadmin/dbconfig-install boolean true'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/app-password-confirm password ${MYSQL_PASSWORD}'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/admin-pass password ${MYSQL_PASSWORD}'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/app-pass password ${MYSQL_PASSWORD}'
debconf-set-selections <<< 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2'

ol "Installing PHPmyadmin"
apt-get install -y phpmyadmin

# Make Composer available globally
ln -s /etc/phpmyadmin/apache.conf /etc/apache2/sites-enabled/phpmyadmin.conf



ol 'Installing Sendmail'
oe sudo apt-get -q -y install sendmail

ol 'Restarting Apache 2'
oe sudo systemctl restart apache2
oe sudo systemctl status apache2

ol "Installing MySQL"
oe sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${MYSQL_PASSWORD}"
oe sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${MYSQL_PASSWORD}"
oe sudo apt-get -q -y install mysql-server mysql-client
oe sudo systemctl restart mysql
oe sudo systemctl status mysql

1 个答案:

答案 0 :(得分:1)

您可以使用sed命令在文件中进行替换,例如

sed -i "s/DocumentRoot.*/DocumentRoot <your new path>" <path to httpd/apache2.conf>

PS:

  • -i备份您的文件
  • DocumentRoot。*将替换所有以DocumentRoot开头的行(如果有多行以DocumentRoot开头,请不要记住;在这种情况下,请制作正确的模式而不是通配符)
  • 如果您的新路径中有/,请务必使用\/

另一个选项(可能更简单一点)是使用您的特定设置在/etc/apache2/conf-enabled/目录下推送新的conf文件,以防您有其他设置,例如VirtualHost或其他设置让它更简单