Essential cPanel Command-Line Tools for Server Management

Managing a cPanel server from the command line can streamline tasks, automate routines, and solve issues faster.
In this article, you will find the most useful cPanel and WHM scripts and commands for account handling, service control, updates, email tools, database operations, DNS tasks, and backups.

Prerequisites

Before you begin:

  • Root or sudo access on your server
  • cPanel & WHM installed
  • Basic familiarity with the Linux shell

1. Account Management

Automate user account tasks with these scripts:

  • Create a new account
    /usr/local/cpanel/scripts/createacct example.com myuser StrongP@ssw0rd
  • Suspend an account
    /usr/local/cpanel/scripts/suspendacct myuser
  • Unsuspend an account
    /usr/local/cpanel/scripts/unsuspendacct myuser
  • List all accounts
    whmapi1 listaccts

2. Service Control

Check and restart key services:

  • Restart Apache (httpd)
    /usr/local/cpanel/scripts/restartsrv_httpd
  • Restart the cPanel service
    /usr/local/cpanel/scripts/restartsrv_cpsrvd
  • Restart Exim (mail server)
    /usr/local/cpanel/scripts/restartsrv_exim
  • Check service status
    systemctl status cpsrvd

3. Updates and Maintenance

Keep your server secure and up to date:

  • Update cPanel to latest release
    /usr/local/cpanel/scripts/upcp
  • Check for OS security updates
    yum check-update
  • Install all pending updates
    yum update -y

4. Email Management

View and manage email accounts and queues:

  • List email accounts for a user
    uapi --user=myuser Email list_pops
  • Delete an email account
    uapi --user=myuser Email delete_pop email=user@example.com
  • Count messages in Exim queue
    exim -bpc
  • Force-flush mail queue
    exim -qff

5. Database Operations

Work with MySQL/MariaDB from shell:

  • Show all databases
    mysql -e "SHOW DATABASES;"
  • Create a new database
    uapi --user=myuser Mysql create_database name=newdb
  • Backup every database
    mysqldump --all-databases > /root/all_databases.sql

6. DNS and Domains

Manage DNS zones and domain records:

  • List all DNS zones
    whmapi1 listzones
  • Add an A record
    whmapi1 addzonerecord zone=example.com name=shop.example.com type=A address=192.0.2.10
  • Refresh user domains file
    /usr/local/cpanel/scripts/updateuserdomains

7. Backups and Restores

Generate and restore full account backups:

  • Create a full cPanel backup
    /usr/local/cpanel/scripts/pkgacct myuser
  • Restore from backup
    /usr/local/cpanel/scripts/restorepkg myuser

Conclusion

These scripts and commands will help you manage your cPanel server from the shell more effectively.
Always test in a development environment before using in production.
For high-performance hosting with dedicated hardware, our unmanaged dedicated servers start at 20 USD per month.

Was this answer helpful? 8923 Users Found This Useful (8935 Votes)