Create a Package on WHM for a cPanel Account | Easy Setup

Posted on

Create a Package on WHM for a cPanel Account | Easy Setup

Create a Package on WHM for a cPanel Account | Easy Setup

In the realm of web hosting, efficiency and organization are paramount. Managing multiple cPanel accounts on a server requires a systematic approach to resource allocation and feature management. This is where Web Host Manager (WHM) steps in as a powerful administrative tool. Specifically, WHM allows you to create packages, predefined sets of resources and features, which can then be assigned to individual cPanel accounts. This article will guide you through the process of creating a package on WHM for a cPanel account, streamlining your hosting management. We will explore the traditional method, and then delve into alternative, potentially more flexible, approaches.

cPanel is a user-friendly control panel favored by web developers and hosting providers alike. It simplifies website and server management. WHM (Web Host Manager), on the other hand, offers administrative control over the entire server. It allows for server configuration, creation of multiple accounts, and management of numerous websites from a single interface.

This guide from Orcacore will provide a step-by-step walkthrough on how to Create a Package on WHM for a cPanel account.

Understanding WHM Packages

In WHM (Web Host Manager), a Package is a cornerstone of efficient server management. It’s a pre-configured blueprint that dictates the resource limits and available features for a cPanel account. Instead of manually configuring each account individually, hosting providers can assign a package, instantly applying the desired settings.

Key Purposes of Packages in WHM:

  • Resource Allocation: Packages define the amount of disk space, bandwidth, email accounts, databases, and other resources allocated to a cPanel account.
  • Feature Control: They determine which features are available to the cPanel user, such as CGI access, shell access, and specific cPanel themes.
  • Simplified Management: Packages allow for easy standardization and modification of account settings across multiple cPanel accounts.
  • Scalability: Hosting providers can offer different tiers of service by creating various packages with different resource levels.

Building a WHM Package: The Traditional Method

WHM provides a straightforward interface for creating new packages. To begin, log in to your WHM dashboard as the root user.

Step-by-Step Guide

  1. Access the Package Creation Interface: From the WHM search bar, type "Packages" and click on "Add a Package."


    add package on WHM

  2. Name Your Package: Provide a descriptive name for your package. Remember that resellers will see the package name preceded by their username and an underscore.


    enter a package name

  3. Define Hosting Resources: Configure the "Hosting Resources" section. This includes specifying the disk space quota, bandwidth limit, the number of allowed FTP accounts, email accounts, databases, subdomains, and parked domains.


    hosting resources on WHM

  4. Configure Settings: Select the desired settings for the package. This includes the cPanel theme, feature list, language, CGI access, Shell access, and other relevant options.


    package settings on WHM for a cPanel account

  5. Add the Package: Once you have configured all the desired settings, click the "Add" button to create the package.

  6. Verification: Your newly created package will now be listed in the "Packages" section of WHM, where you can later edit or delete it as needed.

Alternative Solutions for Package Management

While the WHM interface provides a convenient way to create packages, alternative approaches can offer greater flexibility and automation, especially in large-scale hosting environments. Here are two alternative solutions:

1. WHM API Integration

The WHM API (Application Programming Interface) allows you to interact with WHM programmatically. This means you can automate the creation, modification, and deletion of packages using scripts or custom applications. This approach is beneficial for hosting providers who need to manage a large number of packages or integrate package management into their existing systems.

Explanation:

Instead of manually creating packages through the WHM interface, you can write a script (e.g., in PHP, Python, or Perl) that uses the WHM API to create packages based on predefined configurations or data from an external source (like a database or a configuration file). This eliminates the need for manual intervention and ensures consistency across all packages.

Code Example (PHP):

<?php

require_once 'xmlapi.php';

$ip = 'your_server_ip'; // Replace with your server IP
$username = 'root'; // Replace with your WHM username
$password = 'your_root_password'; // Replace with your WHM password
$package_name = 'new_package';
$disk_quota = 1024; // MB
$bandwidth = 10000; // MB
$max_ftp = 10;
$max_email = 20;
$max_sql = 5;
$max_subdomains = 10;

$xmlapi = new xmlapi($ip);
$xmlapi->set_port(2087);
$xmlapi->set_protocol('https');
$xmlapi->set_output('json');
$xmlapi->set_auth_type('password');
$xmlapi->set_user($username);
$xmlapi->set_password($password);

$params = array(
    'name' => $package_name,
    'diskquota' => $disk_quota,
    'bwlimit' => $bandwidth,
    'maxftp' => $max_ftp,
    'maxemail' => $max_email,
    'maxsql' => $max_sql,
    'maxsub' => $max_subdomains,
    'featurelist' => 'default', // Or your custom feature list name
);

$result = $xmlapi->api1('addpkg', $params);

if ($result->result[0]->status == 1) {
    echo "Package '$package_name' created successfully.n";
} else {
    echo "Error creating package: " . $result->result[0]->statusmsg . "n";
}

?>

Explanation of the Code:

  • The code uses the xmlapi.php library (available from cPanel) to interact with the WHM API.
  • It sets the server IP, username, password, and other necessary parameters.
  • It defines the package name, resource limits, and feature list.
  • It calls the addpkg function in the WHM API to create the package.
  • It checks the result and displays a success or error message.

2. Infrastructure as Code (IaC) with Tools like Terraform or Ansible

Infrastructure as Code (IaC) allows you to define and manage your infrastructure (including WHM packages) using code. Tools like Terraform and Ansible can be used to automate the creation and management of WHM packages, ensuring consistency and reproducibility.

Explanation:

Instead of relying on the WHM interface or custom scripts, you can use an IaC tool like Terraform or Ansible to define your WHM packages as code. This code can then be used to create, update, or delete packages in a consistent and repeatable manner. This approach is particularly useful for managing complex hosting environments with numerous packages and servers.

Code Example (Ansible):

---
- hosts: whm_server
  gather_facts: no
  vars:
    whm_host: 'your_server_ip' # Replace with your server IP
    whm_user: 'root' # Replace with your WHM username
    whm_password: 'your_root_password' # Replace with your WHM password
    package_name: 'ansible_package'
    disk_quota: 2048 # MB
    bandwidth: 20000 # MB
    max_ftp: 15
    max_email: 30
    max_sql: 10
    max_subdomains: 15

  tasks:
    - name: Create WHM Package
      uri:
        url: "https://{{ whm_host }}:2087/json-api/addpkg"
        method: POST
        validate_certs: no
        body: "api.version=1&name={{ package_name }}&diskquota={{ disk_quota }}&bwlimit={{ bandwidth }}&maxftp={{ max_ftp }}&maxemail={{ max_email }}&maxsql={{ max_sql }}&maxsub={{ max_subdomains }}&featurelist=default"
        force_basic_auth: yes
        headers:
          Authorization: "Basic {{ ('root:' + whm_password) | b64encode }}"
        body_format: raw
      register: whm_result

    - debug:
        var: whm_result

Explanation of the Code:

  • The Ansible playbook targets a WHM server.
  • It defines variables for the WHM host, username, password, package name, and resource limits.
  • The uri module makes a POST request to the WHM API endpoint (addpkg).
  • The body parameter contains the API parameters, including the package name, resource limits, and feature list.
  • The Authorization header provides the necessary authentication credentials.
  • The debug module displays the result of the API call.

These alternative solutions offer increased automation and flexibility for managing WHM packages, particularly in large-scale hosting environments. Choosing the right approach depends on your specific needs and technical expertise.

Conclusion

This article has outlined the traditional method of creating a package on WHM for a cPanel account. In addition, we have explored alternative solutions using the WHM API and Infrastructure as Code tools. Understanding these methods empowers you to manage your hosting environment efficiently, ensuring optimal resource allocation and consistent configuration across all cPanel accounts. The creation of packages in WHM for a cPanel account, simplifies hosting management, enabling providers to scale and manage resources effectively. Learning to Create a Package on WHM for a cPanel account will help you to properly allocate server resources.

Remember to explore the WHM documentation and experiment with these techniques to find the best approach for your specific hosting needs.

Please subscribe to us on Facebook, YouTube, and X.

Also, you may like to read the following articles:

Create a cPanel account on WHM

Fix cPanel/WHM Installation on Red Hat 6 & 7

Install cPanel WHM on Rocky Linux 8

Set up JetBackup for cPanel

FAQs

What is a Package in WHM?

A package in WHM is a predefined set of resource limits and features assigned to a cPanel account, helping in efficient hosting management.

Can I edit an existing Package in WHM?

No, WHM does not allow direct editing of packages. You must delete and recreate the package with new settings.

Can I upgrade a cPanel account’s Package?

Yes, you can change the package for an existing cPanel account in WHM under Modify an Account.

How do I assign a Package to a cPanel account?

While creating a cPanel account in WHM, select the desired package. You can also change it later via Modify an Account in WHM.

Leave a Reply

Your email address will not be published. Required fields are marked *