Skip to content
Enables you to make cPanel API requests with PHP.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
public
src
.env.dist
.gitignore
LICENSE.md
README.md
composer.json
composer.lock
console.php

README.md

license release

cPanel Requests

A simple PHP project to make API requests on your cPanel installation. This allows you to call modules inside the installation and interact with them to add, show or list data such as domains, e-mail accounts, databases and so on.

The project makes use of UAPI. Therefore it is required to have a cPanel installation with at least version 42.

Installation

Clone the repository first:

git clone git@github.com:eliashaeussler/cpanel-requests.git
cd cpanel-requests

Install the dependencies (composer needs to be installed for this):

composer install

Now point your web server/virtual host to the public directory of your cloned project and you should be able to access the project.

Usage

User-specific environment

In order to access your cPanel instance and set some configuration settings, it's necessary to create a user-specific environment file:

cp .env.dist .env

Add user functions

The index.php serves as entry point for code execution. It includes all PHP files which are located inside the src/includes directory and executes them. Files starting with an underscore (e.g. _example.php) won't be included.

Each include file should return a closure which executes the user-specific code. The authenticated cPanel instance should be passed as first argument. An example file can be found in src/includes/_example.php.

Example

This project ships an example user function which reads sub domains from the cPanel instance and prints them as HTML list. For this, a domain name can be specified as DOMAIN_NAME in your .env file. If it's set, only sub domains matching this domain name will be printed, otherwise sub domains of the current server name will be printed. Setting * will print all sub domains for all available domain names.

Console

The project includes a console which can be used to execute several functions from the command line. It's located in the root directory of the project:

# General usage
./console.php

# Clear expired cookie files
./console.php clear:cookie
./console.php clear:cookie --lifetime 604800

# Clear log files
./console.php clear:logfile

License

MIT License

You can’t perform that action at this time.