How to quickly update WHMCS on WiredTree hosting and others.
NOTE: This script has been updated to remove the premature deletion of the install directory.
Over the last month or two, WHMCS has been updated many times. This is a GOOD THING, but it can be annoying to go through the normal update process every week or two.
So, I created a small function that I’ve added to /etc/bashrc on my server.
It does the following:
1. Verifies the script is running from the right server.
2. Changes directories to the location where I have WHMCS installed.
3. Removes any files and folders from a previous update
4. Downloads the latest update from the password protected WiredTree repository
5. Unpacks it
6. Renames the admin directory to a new name for security purposes (you may need to do the cron dir too)
7. Changes the owner and group of the new files to be the one required for this website.
8. Copies in all of the new files, overwriting what is there.
So updates now take a few seconds rather than 20 distracting minutes. Maybe you will find this useful.
Here is the function I added to /etc/bashrc:
function upwhmcs(){ curhostname=$(hostname -s) desiredhost='REPLACE_WITH_HOSTNAME' if [ "${curhostname}" == "$desiredhost" ]; then cd /home/REPLACE_WITH_DIRNAME rm -Rf whmcs rm -f whmcs_current.zip wget http://REPLACE_WITH_USERNAME:REPLACE_WITH_PASSWORD@whmcs.wiredtree.com/whmcs_current.zip unzip -o whmcs_current.zip cd whmcs mv admin REPLACE_WITH_ADMIN_DIR_NAME chown -R REPLACE_WITH_DIROWNER:REPLACE_WITH_DIROWNER . cp -Rf * ../www cd ../www pwd return fi echo "Wrong Server. Update skipped" }
To use that listing you need to replace the following text
REPLACE_WITH_HOSTNAME – Replace this with what you get when you run ‘hostname -s’ from the command line.
REPLACE_WITH_DIRNAME – Replace this text with the directory of your whmcs installation. Maybe it is /home/whmcs/ or /home/hosting/ or /home/sales/
REPLACE_WITH_USERNAME – This should become the username that WiredTree gave you to login and get WHMCS updates
REPLACE_WITH_PASSWORD – This should become the password that WiredTree gave you to login and get WHMCS updates
REPLACE_WITH_ADMIN_DIR_NAME – This is the custom name of the admin directory on your server. If you just use admin, delete this mv line entirely.
REPLACE_WITH_DIROWNER – This is quite likely the same value as REPLACE_WITH_DIRNAME
This script assumes that you have WHMCS installed as its own website/subdomain. You can probably adjust it to your needs if you run it in a sub-directory. If you make this customization, send it back to me and I’ll add it to the article.
After the upgrade process, you must visit the site, follow the update steps and then go back and delete the “install” directory from the installation. That should do it!