JasonDaly.name

PHP, Ruby, Symfony, Rails, Doctrine, MooTools. Web Development.

Posts tagged with "cpanel"

September 3, 2009

Transferring a Live Site to a New Server Using cPanel/WHM and SSH

Using cPanel/WHM it is very easy to transfer an existing cPanel account between servers. Coordinating this with a client who manages DNS on their own can make things a bit tricky, especially when their MX records point to the same server for webmail service.

In order to guarantee no downtime on the site, typically I copy a cPanel account over to the new server including all site files and email in advance of notifying a client it is okay to change the DNS. I also tell the site at the newly located cPanel account to continue to read and write to the original database on the old server using the server’s IP address as the host. This gives the client the flexibility to change the DNS at a time convenient for them.

After the DNS Has Propagated to the New Server

Once the DNS has propagated to the new server, a bit of cleanup is required. Following the example above,

  1. The database from the original server (which now contains newer information than the copy existing on the new server’s copy of the database) must be copied, and the new cPanel account’s database references must once again be set to localhost.
  2. We must ensure that all deleted/added email on the original server which occured between the time the cPanel copy was performed and when the client changed their MX records must be reflected on the new server to ensure no loss of email or reappearance of previously deleted email.

To accomplish #1 above is simple. Via SSH on the new server run the following commands

mysqladmin drop your_database_name
# Now update your site to point to localhost instead of the original server's IP

Then, from the original server run the following commands

mysqldump -u your_cpanel_user -p your_database_name | ssh your_cpanel_user@the_new_server_ip mysql your_database_name

This will minimize downtime for your users1 while updating the site to read/write from the local copy of the database now containing the newest information.

Item #2 above is equally simple via rsync from the old server

rsync -av --progress /home/your_cpanel_user/mail/ root@the_new_server_ip:/home/your_cpanel_user/mail

This command properly updates the new mail server’s mail folder for all users with the latest changes to their accounts prior to the MX record change.


  1. It goes without saying that this work should be done very late at night. 

Tags: database dns mx record mysqladmin mysqldump mysql propogate rsync server ssh cpanel whm transfer server bash

April 12, 2009

Fixing Crontab Permissions for Jailshell cPanel Users on CentOS 5 & cPanel/WHM 11.24 RELEASE

Using CentOS 5 on my VPS, I recently found that newly created cPanel accounts running cPanel/WHM 11.24 RELEASE seemed to have some trouble properly setting permissions to allow the jailshell cPanel users to access/manage their crontab.

Setting up cron jobs via cPanel’s web interface itself worked just fine, but when trying to manage a jailshell users crontab via shell, the permissions were not set up properly to allow for this.

As d4ly you can see I don’t have permission to view/edit the crontab for d4ly

d4ly@d4ly.com [~]# crontab -e
cron/d4ly: Permission denied

So as root I did the following

root@server [~]# chmod 4775 /usr/bin/crontab
root@server [~]# cd /var/spool/cron
root@server [/var/spool/cron]# chmod 0755 .
root@server [/var/spool/cron]# chown d4ly.d4ly. d4ly

root@server [/var/spool/cron]# ls -l
total 24
drwxr-xr-x 2 root root 4096 Feb 4 17:03 ./
drwxr-xr-x 13 root root 4096 Sep 9 09:51 ../
-rw------- 1 d4ly d4ly 37 Feb 4 14:54 d4ly
-rw------- 1 root root 1555 Jan 19 20:52 mailman
-rw------- 1 root root 32 Jan 11 16:42 munin
-rw------- 1 root root 485 Jan 26 13:17 root

Then I tested things out once more as d4ly

d4ly@d4ly.com [~]# crontab -e
MAILTO="d4ly"
0 0 * * * ping d4ly.com # This cron is for testing jailshell crontab editing

Tags: cron centos5 centos whm cpanel 11.24 RELEASE crontab bash linux