Skip to content

Instantly share code, notes, and snippets.

@bssanchez
Created September 3, 2019 15:57
Show Gist options
  • Select an option

  • Save bssanchez/14c07060aba7e4d5e2e66e1e6fe01a92 to your computer and use it in GitHub Desktop.

Select an option

Save bssanchez/14c07060aba7e4d5e2e66e1e6fe01a92 to your computer and use it in GitHub Desktop.
Bash script for install lastest version of wordpress
#!/bin/bash -e
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Database Name: "
read -e dbname
read -sp "Database root password: " rootpassdb
echo
dbuser="mydbuser"
dbpass="mypassworddbuser"
until mysql -u root -p$rootpassdb -e ";" ; do
read -p "Can't connect mysql, please retry: " rootpassdb
done
echo "run install? (y/n)"
read -e run
if [ "$run" == n ] ; then
exit
else
echo "==============================================="
echo "Creating database and assigning user privileges"
echo "==============================================="
mysql -uroot -p${rootpassdb} -e "CREATE DATABASE IF NOT EXISTS ${dbname} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql -uroot -p${rootpassdb} -e "GRANT ALL PRIVILEGES ON ${dbname}.* TO '${dbuser}'@'localhost';"
mysql -uroot -p${rootpassdb} -e "FLUSH PRIVILEGES;"
#download wordpress
curl -O https://es.wordpress.org/latest-es_ES.tar.gz
#unzip wordpress
tar -zxvf latest-es_ES.tar.gz
#change dir to wordpress
cd wordpress
#copy file to parent dir
cp -rf . ..
#move back to parent dir
cd ..
#remove files from wordpress folder
rm -R wordpress
#create wp config
mv wp-config-sample.php wp-config.php
#set database details with perl find and replace
perl -pi -e "s/database_name_here/$dbname/g" wp-config.php
perl -pi -e "s/username_here/$dbuser/g" wp-config.php
perl -pi -e "s/password_here/$dbpass/g" wp-config.php
#set WP salts
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' wp-config.php
#create uploads folder and set permissions
mkdir wp-content/uploads
chmod 775 wp-content/uploads
echo "Cleaning..."
#remove zip file
rm latest-es_ES.tar.gz
echo "========================="
echo "Installation is complete."
echo "========================="
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment