I've done a lot of research to find a way to do this, but I'm coming up short. I'm looking for a way to replace all of the 'put your unique phrase here'
with randomly generated salts.
Here is the section of the config I need to edit:
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
This question (here) is close to what I want but expects the standard wp-config-sample.php to be edited. I don't know if it would be easier to delete that whole section and replace it, or just do some sort of find and replace on each line.
UPDATE:
Here is a code sample form my current script (and the attempt at incorporating the answer below..).
sub modify_configs {
my $shell = $_[0];
my $dbname = $_[1];
my $dbuser = $_[2];
my $siteurl = $_[3];
# modify wp-config.php
print BOLD "Modifying configuration files...\n";
chdir($local_dir);
system('perl -pi -e "s/database_name_here/'.$dbname.'/g" wp-config-sample.php');
system('perl -pi -e "s/username_here/'.$dbuser.'/g" wp-config-sample.php');
system('perl -pi -e "s/password_here/'.$pass.'/g" wp-config-sample.php');
my ($keysalts, $flipflop);
`perl -ne 'BEGIN { $keysalts = qx(curl -sS https://api.wordpress.org/secret-key/1.1/salt) } if ( $flipflop = ( m/AUTH_KEY/ .. m/NONCE_SALT/ ) ) {if ( $flipflop =~ /E0$/ ) { printf qq|%s|, $keysalts; } next; } printf qq|%s|, $_;' wp-config-sample.php`;
# rename('wp-config-sample.php', 'wp-config.php');
...
}
This fails with:
Use of uninitialized value $keysalts in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
Use of uninitialized value $flipflop in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
Use of uninitialized value $flipflop in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
Use of uninitialized value $keysalts in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
syntax error at -e line 1, near "{ ="
BEGIN not safe after errors--compilation aborted at -e line 1.
Any help here would be appreciated!
Thanks.