DEV Community

Takdirul Islam Shishir
Takdirul Islam Shishir

Posted on

cPanel UAPI Operations for Creating Subdomains, MySQL Databases, and File Operations

Introduction

itwasCpanel

the cPanel User API (UAPI) stands out as a powerful interface for automating tasks and streamlining administrative operations. In this guide, we will delve into the practical usage of cPanel UAPI for creating subdomains, MySQL databases, and file operations.

UAPI Documentation

Managing Subdomains

Subdomains are indispensable for organizing and structuring websites within a domain. With cPanel UAPI, creating subdomains becomes a breeze. The following command snippet demonstrates how to create a subdomain:

uapi SubDomain addsubdomain domain=subdomain domain=example.com rootdomain=example.com dir=public_html/subdomain
Enter fullscreen mode Exit fullscreen mode

Simply replace subdomain with your desired subdomain name and example.com with your domain. Additionally, adjust the directory path (dir) as needed to reflect your hosting environment's structure.

Managing MySQL Databases

MySQL databases are the backbone of many web applications, storing crucial data and enabling dynamic content generation. Leveraging cPanel UAPI, you can effortlessly create MySQL databases and users with tailored privileges. Let's break down the process into two steps:

  1. Creating a MySQL Database:
uapi --user=username Mysql create_database name=mydatabase
Enter fullscreen mode Exit fullscreen mode

Replace username with your actual username and mydatabase with the desired name for your MySQL database.

  1. Creating a MySQL User and Granting Privileges:
uapi --user=username Mysql create_user name=myuser password=mypassword
uapi --user=username Mysql set_privileges_on_database user=myuser database=mydatabase privileges=ALL_PRIVILEGES
Enter fullscreen mode Exit fullscreen mode

Substitute username, myuser, mypassword, and mydatabase with your specific values. These commands will establish a MySQL user with all privileges on the designated database.

File Operations

Efficiently managing files and directories is essential for maintaining a well-organized web hosting environment. With cPanel UAPI, you can perform file operations seamlessly. Let's explore two common tasks:

  1. Moving Files:
uapi Fileman move_file source_file=public_html/oldfile.txt destination_file=public_html/newfile.txt
Enter fullscreen mode Exit fullscreen mode

Replace source_file and destination_file paths as necessary. This command facilitates the relocation of files within your hosting space.

  1. Moving Directories:
uapi Fileman move_dir source_dir=public_html/oldfolder destination_dir=public_html/newfolder
Enter fullscreen mode Exit fullscreen mode

Similar to moving files, this command relocates entire directories along with their contents, promoting efficient organization.

Additional Tips:

While cPanel UAPI offers robust functionality, certain tasks may be better suited for direct execution via shell commands, especially for bulk operations. For instance, moving or copying files can be accomplished using standard bash commands like mv and cp:

# Move all files from source directory to destination directory
mv /path/to/source/* /path/to/destination/

# Copy all files from source directory to destination directory
cp -r /path/to/source/* /path/to/destination/
Enter fullscreen mode Exit fullscreen mode

These commands provide flexibility and efficiency, particularly for complex file management tasks.

Author can talk :3

In retrospect, I realize there may have been oversights in the documentation review. I apologize for any mistakes . Thank you for your understanding and feedback.

Top comments (0)