Created
November 10, 2016 18:32
-
-
Save gagimilicevic/057b1bf3df628b61823de83214bc3d77 to your computer and use it in GitHub Desktop.
This file contains 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 { | |
printf "Enter new WordPress installation name: " | |
read -e installname | |
dbname=$installname | |
dbuser=$installname | |
dbpass=$installname | |
installpath=$installname | |
mysqluser="root" | |
mysqlpass="root" | |
} | |
function create_new_db { | |
echo "Creating database" | |
Q00="CREATE DATABASE $dbname;" | |
Q01="USE $dbname;" | |
Q02="FLUSH PRIVILEGES;" | |
Q03="CREATE USER $dbuser@localhost IDENTIFIED BY '$dbpass';" | |
Q04="GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost;" | |
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 { | |
localpath="/var/www/html/" | |
cd $localpath | |
mkdir $installpath | |
cd $installpath | |
wget http://wordpress.org/latest.tar.gz | |
tar -xzf 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 {} \; | |
sudo chown -R :www-data wp-content/uploads | |
sudo chown -R $USER:www-data * | |
sudo chmod 640 wp-config.php | |
rm -f latest.tar.gz | |
rm -f wp-install.sh | |
rm -f wp.keys | |
} | |
# Create .htaccess file | |
function generate_htaccess { | |
cd $localpath$installpath | |
touch .htaccess | |
sudo chown :www-data .htaccess | |
sudo chmod 644 .htaccess | |
bash -c "cat > .htaccess" << _EOF_ | |
# Block the include-only files. | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^wp-admin/includes/ - [F,L] | |
RewriteRule !^wp-includes/ - [S=3] | |
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L] | |
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L] | |
RewriteRule ^wp-includes/theme-compat/ - [F,L] | |
</IfModule> | |
# BEGIN WordPress | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.php [L] | |
</IfModule> | |
# END WordPress | |
# Prevent viewing of .htaccess file | |
<Files .htaccess> | |
order allow,deny | |
deny from all | |
</Files> | |
# Prevent viewing of wp-config.php file | |
<files wp-config.php> | |
order allow,deny | |
deny from all | |
</files> | |
# Prevent directory listings | |
Options All -Indexes | |
_EOF_ | |
} | |
##### Main | |
userinput | |
create_new_db | |
install_wp | |
generate_htaccess | |
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