Ais..2025 11 19..2135..srv..generate.subdomains

· eog's blog


πŸ‘€ User #

In my php hoster's cpanel i can generate subdomains Have ssh access but only user rights Can i script the generating of subdomains?


πŸ‘† ChatGPT #

Yes, but only if your hosting provider allows it via one of the following:

1. Use cPanel’s API (UAPI) #

cPanel provides an API you can call over HTTPS to create subdomains.

API endpoint

1POST /execute/SubDomain/addsubdomain

Example cURL command

1curl -u "cpanel_user:cpanel_password" \
2  -H "Authorization: Basic $(printf '%s' "cpanel_user:cpanel_password" | base64)" \
3  "https://yourdomain.com:2083/execute/SubDomain/addsubdomain?domain=sub&rootdomain=yourdomain.com&dir=public_html/sub"

Requirements

βœ” cPanel account βœ” Ability to use HTTPS from your script βœ” API access not blocked by your host

2. Use SSH + cPanel API tokens (better than password) #

In cPanel, go to:

cPanel β†’ Security β†’ API Tokens β†’ Create Token

Then use:

1curl -H "Authorization: cpanel youruser:YOUR_API_TOKEN" \
2  "https://yourdomain.com:2083/execute/SubDomain/addsubdomain?domain=test&rootdomain=yourdomain.com&dir=public_html/test"

The safest way.

3. What you CANNOT do #

With only user-level SSH access, you cannot:

4. Example Bash script to create subdomains automatically #

 1#!/bin/bash
 2
 3API_TOKEN="YOUR_TOKEN"
 4USER="cpaneluser"
 5HOST="yourdomain.com"
 6
 7SUB=$1
 8DOMAIN="yourdomain.com"
 9DIR="public_html/$SUB"
10
11curl -s -H "Authorization: cpanel $USER:$API_TOKEN" \
12  "https://$HOST:2083/execute/SubDomain/addsubdomain?domain=$SUB&rootdomain=$DOMAIN&dir=$DIR"

Usage:

1./addsub.sh blog

❓ Want me to write:

βœ” a full script? βœ” a PHP version? βœ” a bulk-generator to create many subdomains at once?

last updated: