Created
May 27, 2017 07:54
-
-
Save gagimilicevic/4aa32c5f80149648bad10cbec66426c2 to your computer and use it in GitHub Desktop.
Bash script for installing latest WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Installation script for the latest WordPress on Ubuntu | |
# | |
# Author: Dewploy Dev Team | |
# Created: November 11, 2016 | |
# Last Upate: November 11, 2016 | |
##### Functions | |
# Create new database | |
function userinput { | |
echo -n "Enter new WordPress installation name" | |
read installname | |
$dbname=$installname | |
$dbuser=$installname | |
$dbpass=$installname | |
$installpath=$installname | |
$mysqluser="root" | |
$mysqlpass="" | |
} | |
function create_new_db { | |
echo "Creating database" | |
Q00="CREATE DATABASE $dbname;" | |
Q01="USE $dbname;" | |
Q02="CREATE USER $dbuser@localhost IDENTIFIED BY '$dbpass';" | |
Q03="GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost;" | |
Q04="FLUSH PRIVILEGES;" | |
SQL0="${Q00}${Q01}${Q02}${Q03}${Q04}" | |
mysql -v -u $mysqluser -p$mysqlpass -e"$SQL0" | |
} | |
# Download WordPress, modify wp-config.php, set permissions | |
function install_wp { | |
wget http://wordpress.org/latest.tar.gz | |
tar xzvf latest.tar.gz | |
cp -rf wordpress/** ./ | |
rm -R wordpress | |
cp wp-config-sample.php wp-config.php | |
sed -i "s/database_name_here/$dbname/g" wp-config.php | |
sed -i "s/username_here/$dbuser/g" wp-config.php | |
sed -i "s/password_here/$dbpass/g" wp-config.php | |
wget -O wp.keys https://api.wordpress.org/secret-key/1.1/salt/ | |
sed -i '/#@-/r wp.keys' wp-config.php | |
sed -i "/#@+/,/#@-/d" wp-config.php | |
mkdir wp-content/uploads | |
find . -type d -exec chmod 755 {} \; | |
find . -type f -exec chmod 644 {} \; | |
chown -R :www-data wp-content/uploads | |
chown -R $USER:www-data * | |
chmod 640 wp-config.php | |
rm -f latest.tar.gz | |
rm -f wp-install.sh | |
rm -f wp.keys | |
} | |
##### User inputs | |
echo -n "WordPress database name: " | |
read dbname | |
echo -n "WordPress database user: " | |
read dbuser | |
echo -n "WordPress database password: " | |
read -s dbpass | |
echo "" | |
echo -n "Install Wordpress? [Y/n] " | |
read instwp | |
echo -n "Create a NEW database with entered info? [Y/n] " | |
read newdb | |
##### Main | |
if [ "$newdb" = y ] || [ "$newdb" = Y ] | |
then | |
create_new_db | |
install_wp | |
else | |
if [ "$instwp" = y ] || [ "$instwp" = Y ] | |
then | |
install_wp | |
generate_htaccess | |
fi | |
fi | |
echo -n "Now, go to your WordPress site to finish installation!" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment