Last active
August 17, 2020 06:53
-
-
Save lcherone/2a81df31e59443bcf1390385c3af48ef to your computer and use it in GitHub Desktop.
WordPress Installer
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 | |
# LXC.systems - Cloud Script - https://lxc.systems/cloud-script/MQCeGU1 | |
# | |
# Title -------: WordPress Install | |
# Description -: This cloud script will install all base system packages, a LAMP server and the latest version of WordPress. It will work on any Ubuntu server from version 12.04 to 17.04. | |
# Created -----: June 17th 2017, 8:58pm | |
# Updated -----: June 21st 2017, 12:09am | |
# Usage ------: wget -O - https://lxc.systems/cloud-script/MQCeGU1 | sudo sh | |
# bash <(curl -s https://lxc.systems/cloud-script/MQCeGU1) | |
set -e | |
export DEBIAN_FRONTEND=noninteractive | |
# import distro release values as variables | |
. /etc/lsb-release | |
# for root database user, is written to /root/passwords.txt | |
rootdbpass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
# for wordpress database user, is written to /root/passwords.txt | |
dbname="wordpress" | |
dbuser="wordpress" | |
dbpass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
echo "MariaDB users:passwords\nroot:$rootdbpass\nwordpress:$dbpass" > /root/passwords.txt | |
echo "===================================================" | |
echo "= LXC.systems - Automatic WordPress LAMP Installer!" | |
echo "= " | |
echo "= Database Settings" | |
echo "= rootpw: $rootdbpass" | |
echo "= dbname: $dbname" | |
echo "= dbuser: $dbuser" | |
echo "= dbpass: $dbpass" | |
echo "= Passwords are also written to /root/passwords.txt" | |
echo "= " | |
echo "= Grab yourself a coffee! Install takes a few minutes." | |
# root user check | |
if [ $EUID != 0 ]; then | |
echo "This script should be run as root!" 1>&2 | |
exit 1 | |
fi | |
# Update System | |
sudo apt-get -yqq update | |
sudo apt-get -yqq upgrade | |
# Base system packages | |
sudo apt-get -yqq install perl | |
sudo apt-get -yqq install ca-certificates | |
sudo apt-get -yqq install wget | |
sudo apt-get -yqq install curl | |
sudo apt-get -yqq install unzip | |
sudo apt-get -yqq install git | |
sudo apt-get -yqq install nano | |
# | |
# install mariadb | |
# | |
sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $rootdbpass" | |
sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $rootdbpass" | |
sudo apt-get -yqq install mariadb-server | |
sudo apt-get -yqq install mariadb-client | |
# | |
sudo service mysql start | |
sudo mysql -u root -p$rootdbpass -e "CREATE DATABASE $dbname /*\!40100 DEFAULT CHARACTER SET utf8 */;" | |
sudo mysql -u root -p$rootdbpass -e "CREATE USER $dbuser@localhost IDENTIFIED BY '$dbpass';" | |
sudo mysql -u root -p$rootdbpass -e "GRANT ALL PRIVILEGES ON $dbname.* TO '$dbuser'@'localhost';" | |
sudo mysql -u root -p$rootdbpass -e "GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '$rootdbpass';" | |
sudo mysql -u root -p$rootdbpass -e "FLUSH PRIVILEGES;" | |
# | |
sudo service mysql restart | |
# Apache2 and ModPHP5/7 | |
sudo apt-get -yqq install apache2 | |
# | |
# Import distibution variables | |
. /etc/lsb-release | |
# | |
# Is PHP5? | |
if [ $DISTRIB_RELEASE = "12.04" ] || [ $DISTRIB_RELEASE = "14.04" ] || [ $DISTRIB_RELEASE = "15.04" ]; then | |
phpver="5" | |
fi | |
# | |
# Is PHP7? | |
if [ $DISTRIB_RELEASE = "16.04" ] || [ $DISTRIB_RELEASE = "16.10" ] || [ $DISTRIB_RELEASE = "17.04" ] || [ $DISTRIB_RELEASE = "17.10" ]; then | |
phpver="7" | |
fi | |
# | |
# Is PHP7.2? | |
if [ $DISTRIB_RELEASE = "18.04" ] || [ $DISTRIB_RELEASE = "18.10" ]; then | |
phpver="7.2" | |
fi | |
# | |
# Install PHP5 | |
if [ "$phpver" = "5" ]; then | |
# | |
echo "Installing PHP5.5.9" | |
sudo apt-get -yq install php5 php5-cli | |
sudo apt-get -yq install php5-{curl,gd,mcrypt,json,mysql,sqlite} | |
# | |
sudo apt-get -yq install libapache2-mod-php5 | |
# | |
# enable mods | |
sudo php5enmod mcrypt | |
fi | |
# | |
# Install PHP7 | |
if [ "$phpver" = "7" ]; then | |
# | |
echo "Installing PHP7.0" | |
sudo apt-get -yq install php7.0 php7.0-cli | |
sudo apt-get -yq install php7.0-{mbstring,curl,gd,mcrypt,json,xml,mysql,sqlite} | |
# | |
sudo apt-get -yq install libapache2-mod-php7.0 | |
fi | |
# | |
# Install PHP7.2 | |
if [ "$phpver" = "7.2" ]; then | |
# | |
echo "Installing PHP7.2" | |
sudo apt-get -yq install php7.2 php7.2-cli | |
sudo apt-get -yq install php7.2-{mbstring,curl,gd,json,xml,mysql,sqlite,sqlite3,opcache,zip} | |
# | |
sudo apt-get -yq install libapache2-mod-php7.2 | |
fi | |
# enable apache modules | |
sudo a2enmod headers | |
sudo a2enmod rewrite | |
sudo awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}' /etc/apache2/apache2.conf > tmp.conf && mv tmp.conf /etc/apache2/apache2.conf | |
# | |
# restart apache2 service | |
# | |
sudo service apache2 restart | |
# | |
# empty webroot | |
# | |
cd /var/www/html | |
if [ -f index.html ] ; then | |
sudo rm index.html | |
fi | |
# non interactive presets | |
echo "Europe/London" > /etc/timezone | |
dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>/dev/null | |
#download wordpress | |
curl -O https://wordpress.org/latest.tar.gz | |
#unzip wordpress | |
tar -zxvf latest.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 | |
cp 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 up..." | |
#remove zip file | |
rm latest.tar.gz | |
echo "=========================" | |
echo "= WordPress Installed, ready for setup via the web." | |
echo "=========================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment