Last active
March 22, 2023 14:19
-
-
Save DjakaTechnology/3deef7f61f5a50a14a10961145558c6d 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
echo "This script will copy the WordPress installation into" | |
echo "/var/www/yourNewSubDomain/html" | |
echo "--------------------------------------------------" | |
echo "This setup requires a domain name. If you do not have one yet, you may" | |
echo "cancel this setup, press Ctrl+C. This script will run again on your next login" | |
echo "--------------------------------------------------" | |
echo "Enter the domain name for your new WordPress site." | |
echo "(ex. example.org or test.example.org) do not include www or http/s" | |
echo "--------------------------------------------------" | |
a=0 | |
while [ $a -eq 0 ] | |
do | |
read -p "Subdomain (e.g cooking.google.com): " dom | |
if [ -z "$dom" ] | |
then | |
a=0 | |
echo "Please provide a valid domain or subdomain name to continue to press Ctrl+C to cancel" | |
else | |
a=1 | |
fi | |
done | |
b=0 | |
while [ $b -eq 0 ] | |
do | |
read -p "Subdomain name without root domain (e.g cooking.google.com need to input cooking): " domName | |
if [ -z "$domName" ] | |
then | |
b=0 | |
echo "Please provide a valid domain or subdomain name to continue to press Ctrl+C to cancel" | |
else | |
b=1 | |
fi | |
done | |
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/$domName.conf | |
while [ -z $email ] | |
do | |
echo -en "\n" | |
read -p "Your Email Address: " email | |
done | |
mkdir -p /var/www/$domName/html | |
chown -Rf www-data:www-data /var/www/$domName/html | |
sed -i "s/\$domain/$dom/g" /etc/apache2/sites-enabled/$domName.conf | |
sed -i "s|/var/www/html|/var/www/$domName/html|g" /etc/apache2/sites-enabled/$domName.conf | |
service apache2 restart | |
echo -en "Now we will create your new admin user account for WordPress." | |
function wordpress_admin_account(){ | |
while [ -z $email ] | |
do | |
echo -en "\n" | |
read -p "Your Email Address: " email | |
done | |
while [ -z $username ] | |
do | |
echo -en "\n" | |
read -p "Username: " username | |
done | |
while [ -z $pass ] | |
do | |
echo -en "\n" | |
read -s -p "Password: " pass | |
echo -en "\n" | |
done | |
while [ -z "$title" ] | |
do | |
echo -en "\n" | |
read -p "Blog Title: " title | |
done | |
} | |
wordpress_admin_account | |
while true | |
do | |
echo -en "\n" | |
read -p "Is the information correct? [Y/n] " confirmation | |
confirmation=${confirmation,,} | |
if [[ "${confirmation}" =~ ^(yes|y)$ ]] || [ -z $confirmation ] | |
then | |
break | |
else | |
unset email username pass title confirmation | |
wordpress_admin_account | |
fi | |
done | |
echo -en "\n\n\n" | |
echo "Next, you have the option of configuring LetsEncrypt to secure your new site. Before doing this, be sure that you have pointed your domain or subdomain to this server's IP address. You can also run LetsEncrypt certbot later with the command 'certbot --apache'" | |
echo -en "\n\n\n" | |
read -p "Would you like to use LetsEncrypt (certbot) to configure SSL(https) for your new site? (y/n): " yn | |
case $yn in | |
[Yy]* ) certbot --apache; echo "WordPress has been enabled at https://$dom Please open this URL in a browser to complete the setup of your site.";break;; | |
[Nn]* ) echo "Skipping LetsEncrypt certificate generation";break;; | |
* ) echo "Please answer y or n.";; | |
esac | |
echo "Creating database..." | |
mysql -e "DROP DATABASE IF EXISTS wordpress_$domName;" | |
mysql -e "CREATE DATABASE wordpress_$domName;" | |
dbUserName="${username}_${domName}" | |
mysql -e "DROP USER IF EXISTS '$dbUserName'@'localhost';" | |
mysql -e "CREATE USER '$dbUserName'@'localhost' IDENTIFIED BY '$pass'" | |
mysql -e "GRANT ALL PRIVILEGES ON wordpress_$domName.* TO $dbUserName@localhost;" | |
mysql -e "FLUSH PRIVILEGES;" | |
echo "Finalizing installation..." | |
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/bin/wp | |
chmod +x /usr/bin/wp | |
echo -en "Completing the configuration of WordPress." | |
wp core download --path="/var/www/$domName/html" --allow-root | |
wp config create --path="/var/www/$domName/html" --allow-root --dbname=wordpress_$domName --dbuser=$dbUserName --dbpass=$pass --dbhost=localhost | |
wp core install --allow-root --path="/var/www/$domName/html" --title="$title" --url="$dom" --admin_email="$email" --admin_password="$pass" --admin_user="$username" | |
wp plugin install wp-fail2ban --allow-root --path="/var/www/$domName/html" | |
wp plugin activate wp-fail2ban --allow-root --path="/var/www/$domName/html" | |
chown -Rf www-data.www-data /var/www/ | |
cp /etc/skel/.bashrc /root | |
echo "Installation complete. Access your new WordPress site in a browser to continue." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment