Bash – Programatically change AllowOverride for

apache-2.2bashhttpd.conf

How can I progamatically (using BASH) change AllowOverride for <Directory /var/www/> from 'None' to 'All' ?

Rather then having to manually edit /etc/apache2/sites-enabled/000-default

Normally I could just use
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/sites-enabled/000-default

However my 000-default file has other AllowOverride directives that I don't want to change:

NameVirtualHost *
<VirtualHost *>
 ServerAdmin webmaster@localhost

 DocumentRoot /var/www/
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
  AllowOverride None
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog /var/log/apache2/access.log combined
 ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

For example I don't want AllowOverride on /usr/share/doc or /usr/lib/cgi-bin

I just want it set on <Directory /var/www/>
p.s. I am on Ubuntu-Server 8.04.

Best Answer

To change from None to All:

awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}'
Related Topic