New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to change a cPanel account domain name from Command Line?
Hello,
I'm creating a script to backup a cPanel user account from serverX and restore it on ServerY
During the restoration process, I want to change the domain name from domain.com to domain.net, but I'm unable to find the command line that does that.
Both servers are dedi servers and I have root privileges.
So far what I have in the restoration process is:
#Restore account on serverY /scripts/restorepkg --force --ip=xxx.xxx.xxx.xxx /home/backupes/backup/cpmove-user.tar.gz #changing account domain name ??? #Change password /scripts/chpass user passwd /scripts/ftpupdate
Any help is appreciated.
Thanks
Comments
I'm sure that it's not possible through ssh, you'll might be able to do this over cPanel's API or something.
maybe if you modify httpd.conf but i dont think so.
This can be done by editing files in /var/cpanel/{users,userdata}. There are files named after the user account that owns the domain and also files for each of their domains in those two places.
Two example paths for the user 'bob':
/var/cpanel/users/bob
/var/cpanel/userdata/bob/domain.com
Once those are modified you then have to run the either the cPanel script 'updateuserdata' or 'update user domains'. That updates the metadata in /etc/*domains. Then you also need to run 'rebuildhttpconf' then gracefully restart Apache.
It is very easy to mess this up and break things, so I'd recommend practicing this on a nonproduction server first. One thing to consider is the process differs a bit if you're changing the primary domain vs an addon/sub domain, since cPanel treats anything that's not the primary domain as a sub domain internally. It'll makre more sense once you study the files.
It's been a long time since I've done this, since I no longer work for a cPanel host, so these steps might be a bit off. Apologies if that's the case.
I can't edit my reply because CloudFlare thinks it's a SQL injection attempt, lol. I wanted to clarify - you might need to run both of those 'user*' scripts. The files you edit before that step have a comment in them that reminds you which to run but I've forgotten which one (or if its both).
why can't you just use account transfer instead of running your own script?
This, why use the time and effort of using your own script when the the Transfer Tool is already there and works perfectly fine.
Because it has to be done twice a day, it's a long story, but basically I need to frequently create an updated image of the live domain
Thanks, I tried to mess a little bit with them, but didn't succeed in changing the domain name correctly yet... The account configuration keeps getting messed up. That's why I'm wondering if there is an easier way.
sorta like high availability?
An updated image? Why not use backups in cpanel or use a third party backup system like siteautobackup
Yeah this is definitely along the right lines here. I can't seem to find the one liner I had made for this when I worked at HG. I think it was something around 16 files total that I ran sed on. We would have people signup with their domain as "www." + the domain name, and cPanel accepted it at the time, so I had a script to redo it all.
It's pretty much like @tehmaggot said, /var/cpanel/users, /var/cpanel/userdata, and /etc/*domains. Run sed on the cache files in /var/cpanel/user{s,data} as well (or remove them, but you can totally just sed them).
Edit: Oh don't forget DNS zones either.
@Jar
You left HG as well? I eventually had enough and left, much better days now where I ended up. How about you?
Aye. Hello there likely former colleague
Austin or Houston? I'm at DO now. I really loved HG but this was the right choice for the family 
@Jar
Austin office on graveyard shift - I'm Josh, lol. After basically doing the L2 role for about a year as an L1 with the L1 quota (and pay) with no prospect of a promotion I left and joined Rackspace as an L2. Couldn't ask for a better place, really. Glad you're off to bigger and better things!
Josh! I know you don't I? The one who handed off tickets to me in the AM if I recall
@Jar Yes indeed, you were my go-to guy for handoffs in the morning!
Just send you a request on FB so we can keep in touch and stop steering this thread in the wrong direction 
Thanks @tehmaggot & @jar
I finally figured it out, and it seems to be working fine so far.
Here's the solution in case someone ever needs it.
Glad you got it! One thing that @Jar mentioned you might still want to address is DNS. The zones are in /var/named/domain.com.db if I'm remembering correctly. The zone file might need renamed/edited, and /etc/named.conf updated. Once that's done you should be able to run 'rndc reload' to apply the new settings. You can check syslog (/var/log/messages) for any reported issues.
This is all from memory and I haven't worked on a cPanel box in quite a while, so sorry if I've forgotten something lol.
Thanks @tehmaggot, I edited the script to fix the DNS zones, seems to be working, no error showed up and nothing in /var/log/messages