Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Removing an Addon domain with commands / ssh / script

Discussion in 'cPanel Developers' started by jonahnaylor, Jun 18, 2016.

  1. jonahnaylor

    jonahnaylor Registered

    Jul 25, 2011
    Likes Received:
    Trophy Points:
    Hi hopefully someone can help. I'm writing a script to remove an addon domain but so far it's not getting rid of it...

    Currently I've just tried to use the safer cpanel scripts and a few commands to achieve this but I'm hoping some can fill in the gaps as to what I'm missing so that when I navigate back into that account after running the script the domain is no longer there under the Addon Domains section. Any help appreciated, here is what I have so far:

    set -x                                                                  # Turns tracing on so we can see what is happening
    ex +g/$addonDOMAIN/d' -cwq /var/cpanel/users/$cpanelACC                 # Remove all lines containing addon domain in users file
    ex +g/$addonDOMAIN/d' -cwq /var/cpanel/userdata/$cpanelACC/main         # Remove all lines containing addon domain in userdata file
    /usr/local/cpanel/scripts/killdns $addonDOMAIN                          # Remove Addon Domain from BIND
    /usr/local/cpanel/scripts/killvhost $addonDOMAIN                        # Remove Addon Domain http entries
    /usr/local/cpanel/scripts/rebuildhttpdconf                              # Rebuild Apache Configuration
    set +x                                                                  # Turns tracing off again
    APACHE_CONFIG=$(/usr/local/apache/bin/apachectl configtest 2>&1)        # Check condition of Apache with a test
    if [[ $APACHE_CONFIG =~ "Syntax OK" ]]; then
        echo "Apache config is ok. Restarting Apache."
        RESTART_APACHE=$(/usr/local/cpanel/scripts/restartsrv httpd)
        if [[ $RESTART_APACHE =~ "Apache successfully restarted" ]]; then
            echo "Apache restarted successfully"
            echo "Apache restart failed: $RESTART_APACHE"
        echo "Apache config problem. Will not restart apache: $APACHE_CONFIG"
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Apr 11, 2011
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator

    It looks like you are attempting to manipulate configuration files through the script. I suggest using cPanel API 2 instead. Here's a cPanel API 2 function you can use:

    cPanel API 2 Functions - AddonDomain::deladdondomain - Software Development Kit - cPanel Documentation

    You may also find this document helpful:

    Guide to cPanel API 2 - Software Development Kit - cPanel Documentation

    Note that cPanel UAPI is recommended over cPanel API 2, however no equivalent UAPI function exists at this time.

    Thank you.

Share This Page