This feature is great ! Thanks for providing this feature. Base on this feature, I created my own script: /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh with the following content:
Code:
#!/bin/bash
tmpfile="$(mktemp -p /tmp wp-auto-install-XXXXXXXX)"
cat "${1:-/dev/stdin}" > $tmpfile
cpuser=$(python -c "import sys, json; print json.load(open('$tmpfile'))['data']['user']")
domain=$(python -c "import sys, json; print json.load(open('$tmpfile'))['data']['domain']")
cppass=$(python -c "import sys, json; print json.load(open('$tmpfile'))['data']['pass']")
/bin/rm -f $tmpfile
srcroot="/root/tmp/wp_src/*"
sqlfile="/root/tmp/wp_sql/wpdb.sql"
webroot="/home/${cpuser}/public_html"
webconf="${webroot}/wp-config.php"
wpuser="admin"
wppass=$(< /dev/urandom tr -dc _@A-Z-a-z-0-9 | head -c${1:-20};echo;)
dbpass=$(< /dev/urandom tr -dc _@A-Z-a-z-0-9 | head -c${1:-16};echo;)
dbname="${cpuser}_wpdb"
dbuser="${cpuser}_wpuser"
dbhost="localhost"
/usr/bin/uapi --user=${cpuser} Mysql create_database name=${dbname}
/usr/bin/uapi --user=${cpuser} Mysql create_user name=${dbuser} password="${dbpass}"
/usr/bin/uapi --user=${cpuser} Mysql set_privileges_on_database user=${dbuser} database=${dbname} privileges=ALL
/usr/bin/mysql -u${dbuser} -p"${dbpass}" ${dbname} < ${sqlfile}
/usr/bin/rsync -av ${srcroot} ${webroot}
/usr/bin/sed -i "s/MYWPDB_DATABASE/${dbname}/g" ${webconf}
/usr/bin/sed -i "s/MYWPDB_USERNAME/${dbuser}/g" ${webconf}
/usr/bin/sed -i "s/MYWPDB_PASSWORD/${dbpass}/g" ${webconf}
/usr/bin/sed -i "s/MYWPDB_HOSTNAME/${dbhost}/g" ${webconf}
/usr/bin/chown -R ${cpuser}:${cpuser} ${webroot}
sudo -u ${cpuser} /opt/cpanel/ea-php72/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --path=${webroot} user update ${wpuser} --user_pass="${wppass}"
sudo -u ${cpuser} /opt/cpanel/ea-php72/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --path=${webroot} option update home "http://${domain}"
sudo -u ${cpuser} /opt/cpanel/ea-php72/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --path=${webroot} option update siteurl "http://${domain}"
My script can clone a custom designed wordpress website to new created cPanel user automatically. Just copy your wordpress website files into source path(/root/tmp/wp_src/) and export your wordpress database into a SQL text file and upload into source path(/root/tmp/wp_sql/wpdb.sql). You may change the source path if you like, and adjust any options as your wish.
Current my script capable to:
(1) rsync wordpress files from source path:/root/tmp/wp_src/ to cPanel user's public_html/
(2) use uapi command to create cPanel user's wordpress databalse with the following values:
Code:
DATABASE: {CPUSER}_wpdb
USERNAME: {CPUSER}_wpuser
PASSWORD: ****(random)
HOSTNAME: localhost
(3) Import wordpress SQL content from file:/root/tmp/wp_sql/wpdb.sql into above database.
(4) Change configuration of public_html/wp-config.php with above database information.
(5) Change wordpress administrator user(admin)'s password with random password(or with cPanel user's password).
(6) Update wordpress settings: HOME_URL and SITE_URL with the new created domain information.
(7) cPanel user can discovery/manage wordpress with cPanel addon "WordPress Manager".