Skip to content

Instantly share code, notes, and snippets.

@AustinGil
Last active January 29, 2024 09:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save AustinGil/cc6eafaaa31b4da5126df5a3c6dae693 to your computer and use it in GitHub Desktop.
Save AustinGil/cc6eafaaa31b4da5126df5a3c6dae693 to your computer and use it in GitHub Desktop.
Bash script to install and set up WordPress on new cPanel account in WHM
#/bin/bash
# Script for automating new account setups with WordPress installed
echo Lets setup a new WordPress dev site!
# Get user input
# Us RegEx to check for valid domain
read -p 'Enter the domain name: ' domain
result=`echo $domain | grep -P '(?=^.{1,254}$)(^(?>(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)'`
if [[ -z "$result" ]]
then
echo -e "\nNot a valid domain!"
exit
fi
read -p 'Enter a username for the account (15 characters max): ' username
read -sp 'Enter a password for the account: ' password
# Create cPanel account
echo -e "\n\nCreating new cPanel account for $domain"
whmapi1 createacct username=${username:0:15} domain=$domain plan=Unlimited featurelist=default quota=0 password=$password ip=n cgi=0 hasshell=1 contactemail=info@thisisvisceral.com cpmod=paper_lantern maxftp=unlimited maxsql=unlimited maxpop=unlimited maxlst=unlimited maxsub=unlimited maxpark=unlimited maxaddon=unlimited bwlimit=unlimited language=en useregns=1 hasuseregns=1 reseller=0 forcedns=1 mxcheck=local max_email_per_hour=500 max_defer_fail_percentage=80
# Create mySQL database
dbname=${username:0:8}"_wordpress"
dbuser=${username:0:8}"_dbuser"
dbpassword=$password"sql"
echo -e "\n\nCreating mySQL database ($dbname) in new cPanel account"
uapi --user=$username Mysql create_database name=$dbname
uapi --user=$username Mysql create_user name=$dbuser password=$dbpassword
uapi --user=$username Mysql set_privileges_on_database user=$dbuser database=$dbname privileges=ALL%20PRIVILEGES
# Install WordPress
wppassword=$password"wp"
echo -e "\n\nInstalling WordPress"
cd /home/${username:0:15}/public_html
wp core download --allow-root
chown -R ${username:0:15}:${username:0:15} *
wp core config --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpassword --allow-root
wp core install --url=$domain --title=$domain --admin_user=Visceral_Dev_Admin --admin_email=info@thisisvisceral.com --admin_password=$wppassword --allow-root
chown -R ${username:0:15}:${username:0:15} *
# Finish
echo -e "\n\nSuccess!"
@desis123
Copy link

Is it possible to installed pre configured (with themes and plugins) wordpress . If yes , can you please tell me where to modify on script,

@AustinGil
Copy link
Author

@desis123, I haven't used this in a very long time, so Im not sure I could tell you. But something I've used instead that I like a bit more is http://wp-quick-install.com/ You can keep your own copy of the data.ini file and put the plugins and themes that you want installed in there and it works just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment