Skip to content

Instantly share code, notes, and snippets.

@antopj
Last active June 26, 2017 11:07
Show Gist options
  • Save antopj/02f2027266bcc720a7669ac74bbceb6f to your computer and use it in GitHub Desktop.
Save antopj/02f2027266bcc720a7669ac74bbceb6f to your computer and use it in GitHub Desktop.
generate .env file from wp-config.php RUN THIS >> wget -qO genv https://goo.gl/uKJNSd && sudo bash genv && rm genv
#!/usr/bin/bash
######### created by Anto ##########
#!IMPORTANT
#execute this script from same directory where wp-config.php exists
#considering current working directory name as site name /var/www/example.com/
#SITENAME=${PWD##*/}
echo -e "Enter Your domain name"
read SITENAME
echo "WP_ENV=dev" > .env
echo "WP_HOME=https://$SITENAME" >> .env
echo "WP_SITEURL=https://$SITENAME" >> .env
echo -e "\n#-----------\n">> .env
echo "DB_NAME=`cat wp-config.php | grep DB_NAME | cut -d \' -f 4`">> .env
echo "DB_USER=`cat wp-config.php | grep DB_USER | cut -d \' -f 4`">> .env
echo "DB_PASSWORD=`cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`">> .env
echo "DB_HOST=`cat wp-config.php | grep DB_HOST | cut -d \' -f 4`">> .env
echo -e "\n#-----------\n">> .env
#Download salts and save to file
wget -qO /tmp/wp.keys https://api.wordpress.org/secret-key/1.1/salt/
#parse the key-values into variables
echo "AUTH_KEY=\"$(cat /tmp/wp.keys |grep -w AUTH_KEY | cut -d \' -f 4)\"" >> .env
echo "SECURE_AUTH_KEY=\"$(cat /tmp/wp.keys |grep -w SECURE_AUTH_KEY | cut -d \' -f 4)\"" >> .env
echo "LOGGED_IN_KEY=\"$(cat /tmp/wp.keys |grep -w LOGGED_IN_KEY | cut -d \' -f 4)\"" >> .env
echo "NONCE_KEY=\"$(cat /tmp/wp.keys |grep -w NONCE_KEY | cut -d \' -f 4)\"" >> .env
echo "AUTH_SALT=\"$(cat /tmp/wp.keys |grep -w AUTH_SALT | cut -d \' -f 4)\"" >> .env
echo "SECURE_AUTH_SALT=\"$(cat /tmp/wp.keys |grep -w SECURE_AUTH_SALT | cut -d \' -f 4)\"" >> .env
echo "LOGGED_IN_SALT=\"$(cat /tmp/wp.keys |grep -w LOGGED_IN_SALT | cut -d \' -f 4)\"" >> .env
echo "NONCE_SALT=\"$(cat /tmp/wp.keys |grep -w NONCE_SALT | cut -d \' -f 4)\"" >> .env
#2nd Method for Salts
# echo "AUTH_KEY=\"`cat /tmp/wp.keys |grep -w AUTH_KEY | cut -d \' -f 4`\"" >> .env
# echo "SECURE_AUTH_KEY=\"`cat /tmp/wp.keys |grep -w SECURE_AUTH_KEY | cut -d \' -f 4`\"" >> .env
# echo "LOGGED_IN_KEY=\"`cat /tmp/wp.keys |grep -w LOGGED_IN_KEY | cut -d \' -f 4`\"" >> .env
# echo "NONCE_KEY=\"`cat /tmp/wp.keys |grep -w NONCE_KEY | cut -d \' -f 4`\"" >> .env
# echo "AUTH_SALT=\"`cat /tmp/wp.keys |grep -w AUTH_SALT | cut -d \' -f 4`\"" >> .env
# echo "SECURE_AUTH_SALT=\"`cat /tmp/wp.keys |grep -w SECURE_AUTH_SALT | cut -d \' -f 4`\"" >> .env
# echo "LOGGED_IN_SALT=\"`cat /tmp/wp.keys |grep -w LOGGED_IN_SALT | cut -d \' -f 4`\"" >> .env
# echo "NONCE_SALT=\"`cat /tmp/wp.keys |grep -w NONCE_SALT | cut -d \' -f 4`\"" >> .env
#remove key file
rm /tmp/wp.keys
echo "DISABLE_WP_CRON=true" >> .env
echo "WP_CACHE_KEY_SALT=$SITENAME:" >> .env
echo -e "\n#-----------\n">> .env
echo -e "\n\n.env Generated, using https as scheme in WP_HOME and WP_SITEURL...\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment