리눅스 sed로 wp-config.php 설정 변경

1 개요[ | ]

리눅스 sed로 wp-config.php 설정 변경
AS-IS
PHP
Copy
<?php
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
TO-BE
PHP
Copy
<?php
define( 'DB_NAME', 'mydb' );
define( 'DB_USER', 'user1' );
define( 'DB_PASSWORD', 'P@ssw0rd' );
define( 'DB_HOST', '192.168.12.34' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

2 실습[ | ]

Console
Copy
root@wsl:~# cat wp-config.php
<?php
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
root@wsl:~# sed "s|'DB_NAME', '[^']*'|'DB_NAME', 'mydb'|g"             -i wp-config.php
root@wsl:~# sed "s|'DB_USER', '[^']*'|'DB_USER', 'user1'|g"            -i wp-config.php
root@wsl:~# sed "s|'DB_PASSWORD', '[^']*'|'DB_PASSWORD', 'P@ssw0rd'|g" -i wp-config.php
root@wsl:~# sed "s|'DB_HOST', '[^']*'|'DB_HOST', '192.168.12.34'|g"    -i wp-config.php
root@wsl:~# cat wp-config.php
<?php
define( 'DB_NAME', 'mydb' );
define( 'DB_USER', 'user1' );
define( 'DB_PASSWORD', 'P@ssw0rd' );
define( 'DB_HOST', '192.168.12.34' );
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );

3 같이 보기[ | ]