Append code into wp-config.php

We have multiple wordpress sites and need to update the wp-config for w3 total cache. We have to append define('WP_CACHE', true); into the wp-config.php file. Is it possible to do this via ssh. I don’t want to have to go in and open each config file and add it myself.

Your help will be much appreciated.

Related posts

Leave a Reply

2 comments

  1. This commands prepends a line at the beggining of yourfile

    sed -i 1i"define('WP_CACHE', true);" yourfile
    

    To look for many files named wp-config.php and prepend the same text, type this in the shell:

    for i in $(find . -name wp-config.php) 
    do
    sed -i 1i"define('<?php WP_CACHE', true); ?>" $i
    done
    

    Run this from the main folder where you have all the WP sites.

  2. This will search the server recursively from root (/) for all files named wp-config.php and append the string define('WP_CACHE', true); onto the end of the file.

    find / -name "wp-config.php" -print | while read i; do echo "define('WP_CACHE', true);" >> "$i"; done