OnApp enabled cPanel hosting – Creating ready-to-deploy cPanel servers

Tags: cloudhostingcPanelOnApponOnApp

Published on: March 3, 2016 by Shafeer P

OnApp enabled cPanel hosting – Creating ready-to-deploy cPanel servers


Server Provisioning is one of the most routinely performed activities in Web hosting environment. cPanel is the most popular hosting control panel in the industry. Naturally there is huge demand for creation of OnApp enabled cPanel hosting servers.

It is possible to create a template for cPanel VMs and its VM instances in OnApp.  However, each VM will have its own identity elements such as IP, Hostname etc. These parameters are defined in various configuration files of each cPanel and other related services. Proper functioning of each cPanel VMs depends these unique values and hence the general values specified in the template needs modification. Changing the configuration files in accordance with the requirement of each VM is obviously a tedious task.

OnApp provides great tool for such operations on VMs, named Recipe. However, due to the security layer of cPanel architecture, Recipe cannot be executed in cPanel servers by default.

We can overcome this restriction by implementing a simple tweak, as discussed below.

1. Create an empty Virtual Server for template: See

2. Install and configure the cPanel: See

3. Install required third-party optional packages required.

For example, we can install third-party packages such as Softaculous, Percona MySQL, LiteSpeed etc.

Now, let us go deeper in to the OnApp Recipe setup.

4. Prepare the OnApp recipe script

4a. Recipe prerequisties and preperations

  • OnApp recipe will executes via the native Linux SSH environment. So the SSH service should listen on the default port 22 with direct Root login.

Ref 1#:
Ref 2#:

  • The commands specified in the Recipe will be copied into the /tmp of VM with an arbitrary filename.
  • The /tmp partition should be mounted with exec option.
    Add the following command to /root/.bashrc to mount the /tmp with exec option when the Root user logins:
 mount -o remount exec /tmp 

This mount option will be removed automatically during Recipe execution.

  • The Linux filesystem table (/etc/fstab) will be overwritten by the OnApp during VM deployment. So, we have to keep the backup of fstab and recipe will restore during VM creation.
 /bin/cp -p /etc/fstab /etc/fstab.cpanel 

4b. The shell scripts


## Script to update IP/Hostname after OnApp VM deployment.


OLD_IP= # Input the IP address of the Template server here

OLD_HOST= # Input the hostname of the Template server here

echo "Old IP address: $OLD_IP"
echo "New IP address: $NEW_IP"
echo "Old hostname: $OLD_HOST"
echo "New hostname: $NEW_HOST"

if [ "$OLD_HOST" == "$NEW_HOST" ]
 echo "Error: This script won't run on this server!"
 exit 1
 echo -e "\nStopping cPanel and Apache..."
 /etc/init.d/cpanel stop &>> $LOG_FILE
 /etc/init.d/httpd stop &>> $LOG_FILE

 echo -e "Updating IP in wwwacct.conf..."
 replace $OLD_IP $NEW_IP -- $WWW_CONF &>> $LOG_FILE

 echo -e "Updating Main IP for cPanel..."
 /scripts/mainipcheck &>> $LOG_FILE

 echo -e "Updating Exim RDNS..."
 replace $OLD_IP $NEW_IP -- $RDNS_CONF &>> $LOG_FILE

 echo -e "Updating Apache configuration..."
 /scripts/rebuildhttpdconf &>> $LOG_FILE
 replace $OLD_IP $NEW_IP -- $HTTP_CONF &>> $LOG_FILE
 /usr/local/cpanel/bin/apache_conf_distiller --update &>> $LOG_FILE
 echo -e "Staring Apache..."
 /etc/init.d/httpd start &>> $LOG_FILE
 echo -e "Updating cPanel license..."
 /usr/local/cpanel/cpkeyclt &>> $LOG_FILE
 echo -e "Staring cPanel..."
 /etc/init.d/cpanel start &>> $LOG_FILE

 echo -e "Updating Hostname via WHM..."
 curl --insecure --user root:$ROOT_PASSWORD https://$NEW_IP:2087/scripts2/dochangehostname?hostname=$NEW_HOST &>> $LOG_FILE

## FSTAB hardening

 echo -e "\nHardening fstab..."
 mv -f /etc/fstab /etc/fstab.onapp &>> $LOG_FILE
 /bin/cp /etc/fstab.cpanel /etc/fstab &>> $LOG_FILE
 mount -a &>> $LOG_FILE
 mount -o remount / &>> $LOG_FILE
 replace "`grep mount /root/.bashrc `" "" -- /root/.bashrc &>> $LOG_FILE
 echo -e "\nUpdating file system quota..."
 /scripts/fixquotas &>> $LOG_FILE

Note: You need to enter the values for the variables OLD_HOST and OLD_IP with the IP and hostname of the Template server.

5. Create OnApp Recipe

Refer this article for creating the OnApp Recipe. In the script field, enter the following command.

/bin/sh /path/to/the/


6. Create the Virtual Server template in OnApp

7. Assign the Recipe into the Template

Get 24/7 expert server management

Category : cPanel, Howtos, Linux

Shafeer P

Shafeer P

Shafeer is currently working as Senior System Engineer at SupportSages. He is capable of tackling time-consuming issues quickly with his advanced scripting abilities. His unchallenged expertise in solving complex issues in a cut-and-dried way makes him a dependable man in the team. The attitude and philosophy he shows on his workplace make his colleagues call him 'Mr. Perfectionist'. Furthermore, he is a travel and photography enthusiast, and loves to spend his leisure times on music and DIY arts.

You may also read:


Add new commentSIGN IN

Let's Connect


Your Cart

Cart is empty.

Send this to a friend