0

I'm looking for modify a line in my apache2.conf file thanks to bash script. It's the first time I'm using bash script and I need help.

In my apache2.conf file, I have :

DocumentRoot /var/www/html/

And I would like to change this by :

DocumentRoot /var/www/html/erp/htdocs/

I have to write something like this into my bash script ?

sed -i 's/"old word"/"new word"/g' apache2.conf

So :

sed -i 's/DocumentRoot /var/www/html//DocumentRoot /var/www/html/erp/htdocs//g' apache2.conf

Thank you for your help !

EDIT :

#Apache2

cd /etc/apache2/sites-available/
sudo sed -i 's,/var/www/html/,/var/www/html/erp/htdocs/,g'  000-default.conf
echo -e "\033[31m Modification chemin accès dolibarr : ok"
Essex
  • 6,042
  • 11
  • 67
  • 139
  • It's not a duplicate because I didn't know which kind of command I should use in order to replace text in file with bash script.. – Essex Nov 27 '17 at 10:11

1 Answers1

1

For convenience concerns, you ca. use a different delimiter ,:

sed -i 's,/var/www/html/,/var/www/html/erp/htdocs/,g' apache2.conf

You have to escape all slashes if you use it as the delimiter:

sed -i 's/DocumentRoot \/var\/www\/html\//DocumentRoot \/var\/www\/html\/erp\/htdocs\//g' apache2.conf
iBug
  • 35,554
  • 7
  • 89
  • 134