Skip to content

Instantly share code, notes, and snippets.

@afragen
Last active April 14, 2022 18:27
Show Gist options
  • Save afragen/4581d6c0f5fea2cd72c5d6f07db0be23 to your computer and use it in GitHub Desktop.
Save afragen/4581d6c0f5fea2cd72c5d6f07db0be23 to your computer and use it in GitHub Desktop.
Change LocalWP wp-config.php for WP-CLI
# Testing
DB_HOST=$(sh -c "$(curl -fsSL https://gist.githubusercontent.com/afragen/4581d6c0f5fea2cd72c5d6f07db0be23/raw/socket-db-host.sh)");sed "s|define( 'DB_HOST', 'localhost' );|${DB_HOST}|" wp-config.php
# Actual replacement
DB_HOST=$(sh -c "$(curl -fsSL https://gist.githubusercontent.com/afragen/4581d6c0f5fea2cd72c5d6f07db0be23/raw/socket-db-host.sh)");sed -i '' "s|define( 'DB_HOST', 'localhost' );|${DB_HOST}|" wp-config.php
SOCKET=$(mysqld --verbose --help | grep ^socket | awk '{print $2, $3}')
echo "defined( 'WP_CLI' ) \\&\\& WP_CLI ? define( 'DB_HOST', 'localhost:${SOCKET}' ) : define( 'DB_HOST', 'localhost' );"
@afragen
Copy link
Author

afragen commented Apr 14, 2022

I keep trying to add the newline/tab but I don't think it's worth the effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment