Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use sed to uncomment a line in httpd.conf

I'm trying to write a little shell script to go through the steps needed to enable apache and php on a new install of Mountain Lion. The step I'm stuck on is going into /etc/apache2/httpd.conf and uncommenting this line: #LoadModule php5_module libexec/apache2/libphp5.so

From googling around so far I think sed is the way this would be done, but I can't get the syntax right. I tried this:

cd /etc/apache2
sudo sed -i '/s/#LoadModule php5_module libexec\/apache2\/libphp5.so/LoadModule php5_module libexec\/apache2\/libphp5.so' httpd.conf

which I thought would replace the commented line (escaping the slashes) with the uncommented line. But when I run that, I just get the following message back, and no result in the file:

sed: 1: "httpd.conf": extra characters at the end of h command

I'm out of my depth here with this type of scripting, how do I accomplish this task?

like image 359
zakkain Avatar asked Jul 26 '12 07:07

zakkain


1 Answers

You can use comma.

sed -i 's,#LoadModule php5_module libexec/apache2/libphp5.so,LoadModule php5_module libexec/apache2/libphp5.so,g'

or

sed -i 's,#\(LoadModule php5_module libexec/apache2/libphp5.so\),\1,g' foo.txt
like image 141
slitvinov Avatar answered Oct 20 '22 00:10

slitvinov