Skip to content

Instantly share code, notes, and snippets.

@cipulan
Created April 20, 2023 04:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipulan/10fa3036a7b8d7c153df9c3c5045212e to your computer and use it in GitHub Desktop.
Save cipulan/10fa3036a7b8d7c153df9c3c5045212e to your computer and use it in GitHub Desktop.
Automatic Install Wordpress On cPanel Account Creation
#!/bin/bash
TMPFILE="$(mktemp -p /tmp wp-auto-install-XXXXXXXX)"
cat "${1:-/dev/stdin}" > $TMPFILE
DOMAIN=$(python2.7 -c "import sys, json; print json.load(open('$TMPFILE'))['data']['domain']")
CUSTOMEREMAIL=$(python2.7 -c "import sys, json; print json.load(open('$TMPFILE'))['data']['contactemail']")
## The following variable contains the name of the Package that was assigned to the account.
## It would be possible to add additional logic to this script so that WordPress is only installed for certain packages
PACKAGE=$(python2.7 -c "import sys, json; print json.load(open('$TMPFILE'))['data']['plan']")
rm -f $TMPFILE
if [ "$PACKAGE" == "A" ] || [ "$PACKAGE" == "B" ]; then
if [ ! -z $CUSTOMEREMAIL ]; then
wp-toolkit --install -domain-name $DOMAIN -admin-email $CUSTOMEREMAIL
else
# If a contact email address was not provided while creating the account, WP Toolkit will use the default of admin@DOMAIN.TLD as the WordPress Admin email
wp-toolkit --install -domain-name $DOMAIN
fi
else
echo "WordPress installation is only supported for A and B packages"
exit 1
fi
@cipulan
Copy link
Author

cipulan commented Apr 20, 2023

Automatic Install Wordpress On cPanel Account Creation

Create File /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh with content above

Setting permission & owner

chmod 0755 /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh
chown root:root /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh

Add to cPanel hook
/usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh --manual --category Whostmgr --event Accounts::Create --stage=post

Test create cPanel account with selected package A or B

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