amuck-landowner

Creating cPanel OpenVZ Template w/WHM Setup Wizard Fix

Tyler.S

New Member
Verified Provider
Down to business, I have been searching for a quick tutorial on how to do this and it has not been easy, though the solution is in-fact quite simple. I will keep this as simple as possible and brief, and add on it as the days go by and suggestions come in.

I am going to also include the instructions from the cPanel installation guide.

Ready? OK!

In this TUT we will be using SoluVM and CentOS 6 64bit. Feel free to use what you like, but for the purposes of writing this, this is what I am using.

1. Create your VM with your CentOS version chosen.

2. SSH into your VM.

3. Run the following commands to remove GroupServices that will not be needed:


yum grouplist

4. Remove the following if they appear in your grouplist:

  • FTP Server
  • GNOME Desktop Environment
  • KDE (K Desktop Environment)
  • Mail Server or E-mail Server
  • Mono
  • Web Server
  • X Window System
To remove multiple groupservices use quotes:


yum groupremove "Mono" "Mail Server"

5. Edit  /etc/selinux/config  from the command line and set the SELINUX parameter to disabled using a text editor, such as nano or vi. Nano I find is the easiest text editor for linux, the command that you would use would be:


nano /etc/selinux/config

If it comes up empty you are good to go. If you do not have nano installed just do a:

yum install nano 
   (Most pre-made CentOS templates from OpenVZ come with SELINUX not installed/already disabled. But it is always a safe bet to double      check as cPanel will not run with it enabled.)

6. We now need to disable the default firewall and check for updates: (Enter Y to confirm Updates)


chkconfig iptables off

service iptables stop

yum update

7. Now lets verify the TMP directory permissions:


stat /tmp


Should Output:

Access: (1777/drwxrwxrwt) Uid: ( 0/ root) Gid: ( 0/ root)


If it doesn't, run this:

chmod 1777 /tmp

8. Now let's install cPanel/WHM. For this TUT we will grab the lastest FULL/VPS installation:


cd /home

wget -N http://httpupdate.cpanel.net/latest

sh latest

9. Now we wait while it runs!

10. Still waiting...I know, it takes a while...Fast forward to Step 11!

11. Install your firewall and other add-ons you wish to include in your OS Template. Be sure not to include anything directly related to your Temporary VM's hostname or IP, as these settings will be different every time you use this template.

12. Ok, so cPanel is installed and you are able to access WHM (if you do not know how to, visit: https://YOURSERVERIP:2087)

      -Now that you are in WHM you have come up to the Setup Wizard. Change the fields for the contact email and hostname to some random chars such as ([email protected]). Do NOT use your email, or your clients will see it everytime!

Now that you have gone through WHM and customized everything, maybe installed Softaculous or other add-ons. It is now time to reset the box and create your Template.

13. Open an SSH to your VM, and type the following:


ls -alh /etc/.whostmgrft

-rw-r--r-- 1 root root 0 Feb 1 08:07 /etc/.whostmgrft

rm -rf /etc/.whostmgrft

What this does is resets the initial setup wizard. It is a 0-byte file that is created when you first log into WHM. If you remove this file, the setup will run again the next time a User logs into WHM. It isn't the perfect way of doing it...BUT IT WORKS!

14. Log into your SolusVM Master and shutdown the VM you just setup.

15. Inside the VM details in SolusVM you will see a "Create Template" button. Push This Button!

16. Give your template a filename, then hit the Create Template Button, and away she goes!

Please Note:

Sometimes the Create Template feature messes up and doesn't fully create the template. You can tell if this has happened by viewing the VZ/Template/Cache folder on your node. If you do not see your newly created template in there after an hour of the system notification of it starting, then it more than likely broke and you need to rerun the Create Template function again.

For a basic Template with cPanel installed (depending on node power and how packed it is) it should only take a few minutes to pack it all up and be done.

This TUT is just one way of doing it. It probably isn't the best way, but it will reset the hostname, IP and other basic config settings allowing you to update, optimize and secure WHM for your clients without having to worry about hostname conflicts and what not.

Hope it helps, and don't cry to me if you break something lol j/k Will help where I can!
 

mikho

Not to be taken seriously, ever!
I might be asking a stupid question, what if you skip step 12 & 13? Wouldn't that be better to create the template then and there, before messing with the setup?
 

Tyler.S

New Member
Verified Provider
I might be asking a stupid question, what if you skip step 12 & 13? Wouldn't that be better to create the template then and there, before messing with the setup?
Ya of course you can, but some like to enter WHM and tweak it or rebuild Apache/PHP and setup custom rules etc...Some just do not want to or do not have the skill to do it through SSH, so this TUT will allow you to enter WHM and reset the basic setup changes, while leave all your other changes in tact.

Oh, and do not worry about your ROOT Passwords, SolusVM changes them on OS Install ;)
 

mikho

Not to be taken seriously, ever!
Ok, then I understand why one would login before creating the template.
 

Tyler.S

New Member
Verified Provider
Ok, then I understand why one would login before creating the template.
Ya, it can be a bit more time consuming, but the results are worth it in the end. It is perfect for those wanting to include WHM Add-ons like WHMSonic (I do not recommend them, their product is great, but their support is horrible...just an example ;) )

Great tutorial :)

Thank you, like I said I was looking for a solution on how to solve the cPanel wizard save issue, and this was the best I could come up with, so far it has work without an issue. If I find a better way (more than likely a batch script) I will be sure to share it.
 

Nick_A

Provider of the year (2014)
I have been casually looking for a full solution for this for a while. I'll have to check it out.
 

Tyler.S

New Member
Verified Provider
I plan on putting together a more advanced and secured OpenVZ template w/cPanel, to include full OS hardening including cPanel/WHM, mod_security, rootkit hunters, more advanced anti-spam setup...the basics of a Dedi hardening plus more for use, which I might be willing to share once I find the time lol.
 
Last edited by a moderator:

nunim

VPS Junkie
Sometimes the Create Template feature messes up and doesn't fully create the template. You can tell if this has happened by viewing the VZ/Template/Cache folder on your node. If you do not see your newly created template in there after an hour of the system notification of it starting, then it more than likely broke and you need to rerun the Create Template function again.
These are the commands I use for creating my Proxmox templates, assuming you've setup your template to your liking, cleaned package cache etc...

Code:
vzctl set xxx --ipdel all --save
rm -f /vz/private/xxx/etc/hostname
vzctl stop xxx
cd /vz/private/xxx/
tar –czvf /var/lib/vz/template/cache/<template name>.tar.gz .
 

Tyler.S

New Member
Verified Provider
Here is a script that you can call upon in your rc.local file to execute it on the first boot of your VPS. It will check venet0:0 and replace any ip in /etc/wwwacct.conf with the current IP. It will then run a cPanel/WHM & OS Update to make sure you have all the needed updates.

It will also remove the reference in the rc.local file once it is finished so it no longer gets called upon reboot. The script was not designed by me, but was created by a Tech (Andrew) that I use on a regular basis.

Code:
#!/bin/bash
#
# Server preparation for cPanel server
#
# This will upgrade OS and the software to the newest version
#
# Andrew N.
#
# All Rights Reserved. Aqua Networks Ltd.
#
# Insert the right IP to cPanel config
MAIN_IP=`/sbin/ifconfig venet0:0 | awk -F ' *|:' '/inet addr/{print $4}'`; sed -i "s/^ADDR .*$/ADDR $MAIN_IP/" /etc/wwwacct.conf
# Upgrade OS by yum
yum -y upgrade >> /root/install.log
# Upgrade cPanel to the newest version
/scripts/upcp >> /root/cpanel.install.log
# Remove script from auto-boot
sed -i '/setup/d' /etc/rc.local
 
Last edited by a moderator:

rsk

Active Member
Verified Provider
Thanks for this, it is useful and hopefully I have some time to create some templates but for KVM :p
 

mitgib

New Member
Verified Provider
Here is a script that you can call upon in your rc.local file to execute it on the first boot of your VPS. It will check venet0:0 and replace any ip in /etc/wwwacct.conf with the current IP. It will then run a cPanel/WHM & OS Update to make sure you have all the needed updates.


It will also remove the reference in the rc.local file once it is finished so it no longer gets called upon reboot. The script was not designed by me, but was created by a Tech (Andrew) that I use on a regular basis.


#!/bin/bash
#
# Server preparation for cPanel server
#
# This will upgrade OS and the software to the newest version
#
# Andrew N.
#
# All Rights Reserved. Aqua Networks Ltd.
#
# Insert the right IP to cPanel config
MAIN_IP=`/sbin/ifconfig venet0:0 | awk -F ' *|:' '/inet addr/{print $4}'`; sed -i "s/^ADDR .*$/ADDR $MAIN_IP/" /etc/wwwacct.conf
# Upgrade OS by yum
yum -y upgrade >> /root/install.log
# Upgrade cPanel to the newest version
/scripts/upcp >> /root/cpanel.install.log
# Remove script from auto-boot
sed -i '/setup/d' /etc/rc.local
Since setup adds 170mb to the size of the OS of un-needed packages, I modified this to add to /etc/rc.local on the 7th line

/etc/rc.d/init.d/firstboot


Then edit the last line of this script to

Code:
sed -i '7d' /etc/rc.local
 
Top
amuck-landowner