Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to change a cPanel account domain name from Command Line?
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.

How to change a cPanel account domain name from Command Line?

HybridHybrid Member

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

  • SadySady Member

    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.

  • jlayjlay Member

    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.

    Thanked by 1Hybrid
  • jlayjlay Member

    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?

  • @century1stop said:
    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.

  • HybridHybrid Member

    @nexmark said:

    @century1stop said:
    why can't you just use account transfer instead of running your own script?

    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

    @tehmaggot said:
    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.

    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

  • jarjar Patron Provider, Top Host, Veteran
    edited July 2015

    @tehmaggot said:
    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.

    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.

    Thanked by 1Hybrid
  • jlayjlay Member

    @Jar
    You left HG as well? I eventually had enough and left, much better days now where I ended up. How about you?

  • jarjar Patron Provider, Top Host, Veteran

    @tehmaggot said:
    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 :D Austin or Houston? I'm at DO now. I really loved HG but this was the right choice for the family :)

  • jlayjlay Member
    edited July 2015

    @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!

    Thanked by 1jar
  • jarjar Patron Provider, Top Host, Veteran

    @tehmaggot said:
    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 :D

  • jlayjlay Member
    edited July 2015

    @Jar Yes indeed, you were my go-to guy for handoffs in the morning! :D Just send you a request on FB so we can keep in touch and stop steering this thread in the wrong direction :p

    Thanked by 1jar
  • HybridHybrid Member

    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.

    /scripts/removeacct --force username
    /scripts/restorepkg --force --ip=xxx.xxx.xxx.xxx /home/backupuser/backup/cpmove-username.tar.gz
    mv /var/cpanel/userdata/username/username.com /var/cpanel/userdata/username/username.net
    mv /var/cpanel/userdata/username/username.com.cache /var/cpanel/userdata/username/username.net.cache
    sed -i -e 's/username\.com/username\.net/g' /var/cpanel/userdata/username/username.net
    rm -f /var/cpanel/userdata/username/cache
    sed -i -e 's/username\.com/username\.net/g' /var/cpanel/userdata/username/main
    rm -f /var/cpanel/userdata/username/main.cache
    sed -i -e 's/username\.com/username\.net/g' /var/cpanel/users/username
    /scripts/updateuserdomains
    /scripts/updateuserdatacache --force username
    /scripts/rebuildhttpdconf
    /scripts/restartsrv_apache
    #Changing Password
    export ALLOW_PASSWORD_CHANGE=1
    /scripts/chpass username mysuperhardpassword
    #Synching FTP pass
    /scripts/ftpupdate
    
    Thanked by 1jar
  • jlayjlay Member
    edited July 2015

    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.

    Thanked by 2jar Hybrid
  • HybridHybrid Member
    edited July 2015

    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

    /scripts/removeacct --force username
    /scripts/restorepkg --force --ip=xxx.xxx.xxx.xxx /home/backupuser/backup/cpmove-username.tar.gz
    mv /var/cpanel/userdata/username/username.com /var/cpanel/userdata/username/username.net
    mv /var/cpanel/userdata/username/username.com.cache /var/cpanel/userdata/username/username.net.cache
    sed -i -e 's/username\.com/username\.net/g' /var/cpanel/userdata/username/username.net
    rm -f /var/cpanel/userdata/username/cache
    sed -i -e 's/username\.com/username\.net/g' /var/cpanel/userdata/username/main
    rm -f /var/cpanel/userdata/username/main.cache
    sed -i -e 's/username\.com/username\.net/g' /var/cpanel/users/username
    mv /var/named/username.com.db /var/named/username.net.db
    sed -i -e 's/username\.com/username\.net/g' /var/named/username.net.db
    sed -i -e 's/username\.com/username\.net/g' /etc/named.conf
    /scripts/updateuserdomains
    /scripts/updateuserdatacache --force username
    /scripts/rebuildhttpdconf
    /scripts/restartsrv_apache
    rndc reload
    #Changing Password
    export ALLOW_PASSWORD_CHANGE=1
    /scripts/chpass username myhardpassword
    #Synching FTP pass
    /scripts/ftpupdate
    
Sign In or Register to comment.