Migrate/clone WHM settings between cPanel/WHM servers

If you want to clone or migrate between cPanel/WHM servers, the cpconftool is available and should make life a little bit easier unless you automated configuring all the options through the cPanel/WHM api.

As far as usage goes, it’s fairly standard: check what modules are tracked

[[email protected] ~]# /usr/local/cpanel/bin/cpconftool –list-modules

Backup the modules and then restore them on the target server.

/usr/local/cpanel/bin/cpconftool [–restore=file|–backup|–list-modules|–query-module-info] –modules=MODULE,MODULE,MODULE [–prerestore_backup] [–verbose]
[[email protected] ~]# /usr/local/cpanel/bin/cpconftool –modules=cpanel::easy::apache,cpanel::smtp::exim,cpanel::system::backups,cpanel::system::mysql,cpanel::system::whmconf,cpanel::ui::themes –backup
Backup Successful

Restoration goes like this:

/usr/local/cpanel/bin/cpconftool –modules=cpanel::easy::apache,cpanel::smtp::exim,cpanel::system::backups,cpanel::system::mysql,cpanel::system::whmconf,cpanel::ui::themes –restore /home/whm-config-backup-cpanel__easy__apache-1.0.0_cpanel__smtp__exim-10.990000_cpanel__system__backups-

If you came to this page and you’re looking for someone to make all your server related problems go away, feel free to drop us a message and we’ll get back to you asap.

cPanel/WHM mass add spf and domainkeys to all accounts

I am not really just now adding these, i merely ran some cleanups on the zones, removing obsolete ip’s and stuff like that, but i thought to share the script i used to reset the DKIM and SPF records for all accounts:

#!/bin/bash -x
for user in `ls -A /var/cpanel/users`;
/usr/local/cpanel/bin/dkim_keys_install $user && /usr/local/cpanel/bin/spf_installer $user;


Previous value removed by cPanel transfer auto-merge

So i have been doing a hardware upgrade, and during the migration of the accounts, the target server named zone files got polluted with stuff like this:

; 86400 ;refresh ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
; 7200 ;retry ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
; 3600000 ;expire ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT
; 86400 ) ; Previous value removed by cPanel transfer auto-merge on 20150804093325 GMT

In order to clean things up, you can do something like this:

1 –  backup your named folder : cd /var;tar czf named.tgz named

2 – cd /var/named

perl -i.bak -ne ‘next if (/^; .+ ; Previous value removed by cPanel transfer auto-merge on/); print;’ /var/named/*.db


Voila! Things should be clean.

Error from domain wrapper: Domain already exists, it was not added.: cPanel

So, today i had this guy that added some domain, a subdomain and then after removing, he wanted to add it once more, but got the error below:

Error from domain wrapper: Domain already exists, it was not added.

This means that after the deletion, there have been some bits and pieces of info that got left over at deletion. Doesn’t happen that often but here’s what you can do to fix it: (info provided by Tristan at the cPanel forums)

You would want to check the following locations:


Any of the above if it has traces of the subdomain will cause the subdomain to continue to be considered existing on the system. Simply make a copy of the file you are editing and then remove the subdomain. For the /var/cpanel/userdata/username/sub.maindomain.com file, simply move the file out of the way. For the /var/named/maindomain.com.db file, you could edit it in WHM > Edit a DNS zone if the subdomain is still there rather than edit that file directly.

If you did find the subdomain listed in any of the /var/cpanel/userdata/username files, you would need to run the following commands after removing it in the main file there and moving the sub.maindomain.com file there:

cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak110217
/etc/init.d/httpd restart

You would also likely want to run this script after that or possibly after editing /var/cpanel/users/username file:


If you directly edited the /var/named/maindomain.com.db file rather than editing it in WHM > Edit a DNS Zone, you’d need to run this command:

rndc reload

In all of the above, username is the cPanel username, maindomain.com is the main domain name, andsub.maindomain.com is the subdomain name.

For me the problem was that /var/cpanel/users/username had 2 lines referring to the old domain. Removed those, updated userdomains as instructed, then rebuilt the httpd.conf, reload apache and there you go.

PHP 5.2 and PHP 5.3 side by side in cPanel servers

I just got a customer that needs both php 5.3 and php 5.2 in the server for various reasons, so here’s how it works:

1 – You need to compile php5.2 from EasyApache

2 – mkdir /usr/local/buildphp53/ ; cd /usr/local/buildphp53/ ; wget http://cz2.php.net/get/php-5.3.27.tar.gz/from/us1.php.net/mirror ; tar zxf php-5.3.27.tar.gz ; cd php-5.3.27/

3 – Modify the configure line below to suit you:

./configure –enable-bcmath \
–enable-cgi \
–enable-calendar \
–enable-exif \
–enable-ftp \
–enable-gd-native-ttf \
–enable-libxml \
–enable-magic-quotes \
–enable-mbstring \
–enable-pdo=shared \
–enable-sockets \
–enable-zip \
–prefix=/usr/local/php53 \
–with-bz2 \
–with-curl=/opt/curlssl/ \
–with-curlwrappers \
–with-freetype-dir=/usr \
–with-gd \
–with-gettext \
–with-imap=/opt/php_with_imap_client/ \
–with-imap-ssl=/usr \
–with-jpeg-dir=/usr \
–with-kerberos \
–with-libdir=lib64 \
–with-libexpat-dir=/usr \
–with-libxml-dir=/opt/xml2/ \
–with-mcrypt=/opt/libmcrypt/ \
–with-mhash=/opt/mhash/ \
–with-mysql=/usr \
–with-mysql-sock=/var/lib/mysql/mysql.sock \
–with-mysqli=/usr/bin/mysql_config \
–with-openssl=/usr \
–with-openssl-dir=/usr \
–with-pcre-regex=/opt/pcre \
–with-pdo-mysql=shared \
–with-pdo-sqlite=shared \
–with-pic \
–with-png-dir=/usr \
–with-sqlite=shared \
–with-tidy=/opt/tidy/ \
–with-xmlrpc \
–with-xpm-dir=/usr \
–with-zlib \

4 – make && make install

5 – Go to Apache configuration in WHM, and edit /usr/local/apache/conf/includes/pre_virtualhost_global.conf

Add the lines below, save and restart apache.

Action application/x-httpd-php53 /cgi-sys/php53

 AddType application/x-httpd-php53 .php53

6 – Have apache skip the htaccess scan and remove mine types:

/usr/local/cpanel/bin/apache_conf_distiller –update

touch /var/cpanel/easy_skip_update_php_mime_types

7 – Create a new file and add the lines below to it: /usr/local/cpanel/cgi-sys/php53

 exec /usr/local/php53/bin/php-cgi

8 – Permissions:

chown root:wheel /usr/local/cpanel/cgi-sys/php53

chmod +x /usr/local/cpanel/cgi-sys/php53

9 – Linking:

 ln -s /usr/local/php53/bin/php-cgi /usr/local/bin/php53

10 – php.ini:

mv /usr/local/buildphp53/php-5.3.27/php.ini-production /usr/local/php53/lib/php.ini

Restart apache

Running php 5.3 :

Add this into a .htaccess file located in the public_html folder in the user’s account that you want it to run on.

AddHandler application/x-httpd-php53 .php

A running easyapache process was detected. Please wait for easyapache to finish before attempting to upgrade MySQL

I am just setting a new server up, and i upgraded apache first. Now i went to upgrade MySQL to 5.5, but when i am going in the interface, it says:

WARNING: A running easyapache process was detected. Please wait for easyapache to finish before attempting to upgrade MySQL.

If you are certain that the easyapache is no longer running, you may restart the MySQL upgrade by clicking the following button.
The “Ignore current upgrade button” is not working. What do we do?


What you can do, is to run:

ps aux | grep easyapache

If it doesn’t return any process running, then go delete the following file:


Find spammer scripts in Exim – useful commands

Had a customer the other day and he asked me to clear spammers on his server. Some of these commands came in handy:


1. To check the number of emails present in the queue:

# exim -bpc

2. To check the emails present in the queue with the mail id and sender ID:

# exim -bp
# exim -bp | less

3. To view the header of a particular email using mail ID:

# exim -MvH mail_id

4.  To view the body of a particular email using mail ID:

# exim -Mvb mail_id

5. To view a message’s logs:

# exim -Mvl mail_id

6. To trace path:

# exim -d -bt [email protected]

7. To get sorted list of email sender in exim queue:

# exim -bpr | grep “<” | awk {‘print $4’} |cut -d “<” -f 2 | cut -d “>” -f 1 | sort -n | uniq -c| sort -n

8. To check the script that will originate spam mails:

# grep “cwd=” /var/log/exim_mainlog|awk ‘{for(i=1;i<=10;i++){print $i}}’|sort| uniq -c|grep cwd|sort -n

9. If we need to find out exact spamming script. To do this, run following command:

# ps auxwwwe | grep user | grep –color=always “/home/user/public_html/templates/” | head

10.  To delete the emails of a specific user:

# grep -lr ‘[email protected]’ /var/spool/exim/input/ | sed -e ‘s/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g’ | xargs exim -Mrm

# exim -bp | grep “user_email-account” | awk ‘{print $3}’ | xargs exim -Mrm

11. To delete Frozen emails from the email queue:

# grep -R -l ‘*** Frozen’ /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm
# exim -bp| grep frozen | awk ‘{print $3}’| xargs exim -Mrm
# exiqgrep -z -i | xargs exim -Mrm

12.  To delete Spam emails from the email queue:

#  grep -R -l [SPAM] /var/spool/exim/msglog/*|cut -b26-|xargs exim -Mrm

13. To check the no. of frozen mails:

# exiqgrep -z -c

14. To check exim logs:

# tail -f /var/log/exim_mainlog

Freebsd / Drives larger than 1tb / gpart

This has taken me more than it should have.

Okay long story short: If you’re installing FreeBSD, then you should know that it doesn’t support drives larger than 1 tb drives by default from sysinstall / fdisk / label.
Quick and easy once you learn it, you realise that you can get the job done really quick by using gpart.

Problems you may encounter:

??(~)->gpart create -s gpt aacd1
gpart: geom ‘aacd1’: File exists

^^ This happens if you already tried (like i did) to mount the big 9 tb raid array through fdisk. Solution – dd the drives, and then you will erase the mbr, and it’s good to go:

??(~)->gpart show aacd1
=> 63 19503513477 aacd1 MBR (9.1T)
63 19503513477 – free – (9.1T)

??(~)-> dd if=/dev/zero of=/dev/aacd1 bs=1k count=1

??(~)->gpart show aacd1
gpart: No such geom: aacd1.

??(~)->gpart create -s gpt aacd1
aacd1 created

^^ And it works like a charm.
??(~)->gpart show aacd1
=> 34 19503513533 aacd1 GPT (9.1T)
34 19503513533 – free – (9.1T)

Time to make a partition and get this over with:

??(~)->gpart add -t freebsd-ufs -l bigraid aacd1
aacd1p1 added

??(~)->newfs aacd1p1

Once the partition is loaded, just add it to fstab:

/dev/aacd1p1 /var/www/html ufs rw 2 2

Then do a “mount -a” and it’s finished.

Took me a while to figure all this out. Hope it makes your life easier.

LE: for optimizing the block size: newfs -O2 -U -b 65536 -f 8192 -i 65536 /dev/ad5p1

LEE: for destroying partitions:

??(~)->gpart delete -i 1 ad7
??(~)->gpart destroy ad7