keensoen / cpanel-api
cPanel API which enables you to connect and carry out several common task in the cpanel
Requires
- php: ^7.1
This package is auto-updated.
Last update: 2025-03-29 00:51:35 UTC
README
Laravel Package for CPanel UAPI
Please consider starring the project to show your ❤️ and support.
This laravel package allows you to connect and manage you CPanel based hosting using CPanel UAPI.
Some practical usages are:
- Create database, sub domains, emails accounts etc
- Create database users
- Set privileges on database of any user
- List all email account of the specified domain
- Check email account size
- Increase email quota when need arises
- Delete email account when necessary
Learn more about at CPanel UAPI
Installation
Step 1) Install the Package
Use following composer command to install the package
composer require keensoen/cpanel-api
or
Add keensoen/cpanel-api
as a requirement to composer.json
:
{
...
"require": {
...
"keensoen/cpanel-api": "^1.0"
},
}
Update composer:
$ composer update
Step 2) Publish Configurations
Run following command:
php artisan vendor:publish --provider="Keensoen\CPanelApi\CPanelApiServiceProvider"
Step 3) Set CPanel details in .env
CPANEL_DOMAIN=
CPANEL_PORT=
CPANEL_API_TOKEN=
CPANEL_USERNAME=
or
$cpanel = new CPanel($cpanel_domain=null, $cpanel_api_token=null, $cpanel_username=null, $protocol='https', $port=2083);
To generate CPANEL_API_TOKEN
, login to the CPanel >> SECURITY >> Manage API Tokens >> Create
.
Usages & available methods
Make sure you import:
use Keensoen\CPanelApi\CPanel;
To Get List of All Email Account in the CPanel
$cpanel = new CPanel(); $response = $cpanel->getEmailAccounts();
Create Email Account
Your password must be eight character above and should contain alphanumeric and symbols. For example
$cpanel = new CPanel() $username = 'john.dansy'; $password = 'ideaHeals@#12'; $response = $cpanel->createEmailAccount($username, $password);
To Delete Email Account
You will have to pass a full email address to be able to delete the account.
$cpanel = new CPanel() $response = $cpanel->deleteEmailAccount('john.dansy@example.com');
To Get Email Account Disk Usage
You will have to pass a full email address of which you want to get disk usage.
$cpanel = new CPanel() $response = $cpanel->getDiskUsage('john.dansy@example.com');
To Increase Email Account Quota
You will have to pass a full email address of which you want to get disk usage.
$cpanel = new CPanel() $email = 'john.dansy@example.com'; $quota = 1024; $response = $cpanel->increaseQuota($email,$quota);
To Create Database
Database name should be prefixed with cpanel username cpanelusername_databasename
If your CPanel username is surf
then your database name
| should be surf_website
.
$cpanel = new CPanel(); $response = $cpanel->createDatabase('cpanelusername_databasename');
Find More Details at CPanel UAPI - Mysql::create_database
To Delete Database
$cpanel = new CPanel(); $response = $cpanel->deleteDatabase('cpanelusername_databasename');
CPanel UAPI - Mysql::delete_database
To Get List of All Databases in the CPanel
$cpanel = new CPanel(); $response = $cpanel->listDatabases();
To Create Database User
$cpanel = new CPanel(); $response = $cpanel->createDatabaseUser($username, $password);
To Delete Database User
$cpanel = new CPanel(); $response = $cpanel->deleteDatabaseUser($username);
To Give All Privileges to a Database User On a Database
$cpanel = new CPanel(); $response = $cpanel->setAllPrivilegesOnDatabase($database_user, $database_name);
Using CPanel UAPI Methods
You can also call all the method available at CPanel UAPI using following method:
$cpanel = new CPanel(); $response = $cpanel->callUAPI($Module, $function, $parameters);
for example if you want to add new ftp
account, documetation is available at CPanel UAPI - Ftp::add_ftp then use the method as represented below:
$cpanel = new CPanel(); $Module = 'Ftp'; $function = 'add_ftp'; $parameters_array = [ 'user'=>'ftp_username', 'pass'=>'ftp_password', //make sure you use strong password 'quota'=>'42', ]; $response = $cpanel->callUAPI($Module, $function, $parameters_array);
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email sesughagbadu@yahoo.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.