Skip to main content
cPanel Technical Support has been heavily impacted by hurricane Beryl and our ability to respond to tickets has been hindered as a result. We appreciate your understanding and patience as we address these delays.

How To Automatically Install WordPress On New Accounts

Comments

20 comments

  • Cody Leeper
    Now is there a way after running curl to run wp cli commands within the script to install and activate plugins?
    0
  • Kevin Perrow
    Would be awesome if cPanel stepped up and offered an advance WordPress feature like Plesk offers its a really good tool for web agency. The number one control panel and the number one cms platform... Would be a winner for everyone.
    0
  • cPanelMichael
    Now is there a way after running curl to run wp cli commands within the script to install and activate plugins?

    Hello @Cody Leeper, Yes, you could append new lines at the end of the example script if you want to add additional commands (e.g. wp-cli). You'll just need to design the commands to detect and run on the individual WordPress installation under the cPanel account.
    Would be awesome if cPanel stepped up and offered an advance WordPress feature like Plesk offers its a really good tool for web agency. The number one control panel and the number one cms platform... Would be a winner for everyone.

    We are committed to improving the WordPress Manager Release Notes - cPanel Knowledge Base - cPanel Documentation Staging/Production syncing is one of the next additions to WordPress Manager feature that's planned for future versions. Thank you.
    0
  • chengkinhung
    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: #!/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: 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".
    0
  • cPanelAustin
    @chengkinhung Very nice script, thanks for sharing!
    0
  • Alnaggar
    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: #!/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: 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".

    I have tried it and it partially works, When a new account created it copy the files from the /root/tmp/wp_src/) and successfully create a new database and import (/root/tmp/wp_sql/wpdb.sql) to it. The problem is it doesn't change the configuration of public_html/wp-config.php (newly created site) with the database information created, And it doesn't update WordPress settings: HOME_URL and SITE_URL in the database with the newly created domain information. It seems that WP CLi commands from the script don't work, I tried with ea-php74, I have installed WP CLi for all users and everything seems to work fine. What may I have missed?
    0
  • Alnaggar
    I have found the problem and it was my bad, The script is perfect and many thanks to @chengkinhung for sharing it with public you really a great man, First I didn't match the data correctly in the /root/tmp/wp_src/wp-config.php So they can be replaced with new created value : MYWPDB_DATABASE MYWPDB_USERNAME MYWPDB_PASSWORD MYWPDB_HOSTNAME
    Second, I didn't give the right permission to the script after I edited it: chmod 0755 /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh chown root:root /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh /usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/3rdparty/bin/wpAutoInstall.sh --manual --category Whostmgr --event Accounts::Create --stage=post
    Again many thanks to @chengkinhung for this amazing script.
    0
  • johnhenrique
    I follow instructions but nothing happens when create a new account... This hook need be run as root? If yes, how to do?
    0
  • cPRex Jurassic Moderator
    @johnhenrique - yes, this needs to be setup as the root user. The details for the hook can be found here:
    0
  • johnhenrique
    @johnhenrique - yes, this needs to be setup as the root user. The details for the hook can be found here:
    0
  • cPRex Jurassic Moderator
    There is only one WordPress Toolkit software, so if that is already present you wouldn't need to install it.
    0
  • johnhenrique
    There is only one WordPress Toolkit software, so if that is already present you wouldn't need to install it.

    Do we have any way to check logs to try to understand why it`s not working for me?
    0
  • cPanelWilliam
    [QUOTE]Do we have any way to check logs to try to understand why it`s not working for me?
    Yes, you can review the WordPress toolkit logs located within the following directory:/usr/local/cpanel/3rdparty/wp-toolkit/var/logs/
    For reference:
    0
  • cPanelAdamF
    Starting with v102, Jupiter will now offer to install WordPress on the primary domain of an account if the account's document root is empty and the user hasn't otherwise opted-out: This occurs only if WordPress Toolkit is installed and enabled for the account, the primary document root is empty, and the user hasn't otherwise skipped or dismissed this.
    0
  • johnhenrique
    Yes, you can review the WordPress toolkit logs located within the following directory:/usr/local/cpanel/3rdparty/wp-toolkit/var/logs/
    For reference:
    0
  • cPRex Jurassic Moderator
    @johnhenrique - do you have root access to the server, or just access to your cPanel account?
    0
  • johnhenrique
    @johnhenrique - do you have root access to the server, or just access to your cPanel account?

    VPS, using root access.
    0
  • cPRex Jurassic Moderator
    If you have root access, I would expect that directory to exist. Here is what I see on my personal server: [root@host ~]# cd /usr/local/cpanel/3rdparty/wp-toolkit/var/logs/ [root@host logs]# ll total 704 drwx------. 3 wp-toolkit wp-toolkit 4096 Mar 8 18:00 action-logs -rw------- 1 wp-toolkit wp-toolkit 257283 Mar 12 23:58 main-2022-03-12.log -rw------- 1 wp-toolkit wp-toolkit 257334 Mar 13 23:58 main-2022-03-13.log -rw------- 1 wp-toolkit wp-toolkit 173037 Mar 14 13:58 main-2022-03-14.log -rw-------. 1 root root 5018 Mar 8 20:43 sw-engine.access.log -rw-------. 1 root root 752 Mar 9 14:32 sw-engine.error.log
    0
  • nucleobrasil
    Friend, I need to make a script like this, but customized. If I pay, will you build one for me?
    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: #!/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: 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".

    0
  • cPRex Jurassic Moderator
    @nucleobrasil - that would be a question for @chengkinhung - you could also reach out to an administrator at if you're looking to get a specific project completed.
    0

Please sign in to leave a comment.