Skip to content

Instantly share code, notes, and snippets.

@PetengDedet
Created February 19, 2021 10:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PetengDedet/46546e44c9504facf15a3316534f34b4 to your computer and use it in GitHub Desktop.
Save PetengDedet/46546e44c9504facf15a3316534f34b4 to your computer and use it in GitHub Desktop.
Change wordpress config via sed in docker
RUN cp wp-config-sample.php wp-config.php
# Replace configuration file with desired env
RUN sed -i 's/database_name_here/'"${DB_NAME}"'/g' wp-config.php;
RUN sed -i 's/username_here/'"${DB_USER}"'/g' wp-config.php;
RUN sed -i 's/password_here/'"${DB_PASSWORD}"'/g' wp-config.php;
RUN sed -i 's/localhost/db/g' wp-config.php;
RUN sed -i 's/'"'AUTH_KEY',".*"'put your unique phrase here'"'/'"'AUTH_KEY', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'SECURE_AUTH_KEY',".*"'put your unique phrase here'"'/'"'SECURE_AUTH_KEY', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'LOGGED_IN_KEY',".*"'put your unique phrase here'"'/'"'LOGGED_IN_KEY', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'NONCE_KEY',".*"'put your unique phrase here'"'/'"'NONCE_KEY', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'AUTH_SALT',".*"'put your unique phrase here'"'/'"'AUTH_SALT', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'SECURE_AUTH_SALT',".*"'put your unique phrase here'"'/'"'SECURE_AUTH_SALT', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'LOGGED_IN_SALT',".*"'put your unique phrase here'"'/'"'LOGGED_IN_SALT', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
RUN sed -i 's/'"'NONCE_SALT',".*"'put your unique phrase here'"'/'"'NONCE_SALT', '""$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1)""'"'/g' wp-config.php;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment