Automatically upload index for new accounts in cpanel

To automatically upload an index file (e.g. index.html) for new accounts in cPanel, you can use a combination of cPanel's built-in features and a simple script. Here's a step-by-step guide:

Prerequisites:

  1. You have a cPanel server with a version that supports custom scripts (e.g. cPanel 11.52 or later).
  2. You have a basic understanding of shell scripting and Linux.

Step 1: Create a custom script

Create a new file in the /usr/local/cpanel/scripts directory (e.g. upload_index.sh) with the following contents:

#!/bin/bash

# Set the path to the index file
INDEX_FILE=/path/to/index.html

# Set the path to the document root of the new account
DOCROOT=$1

# Upload the index file to the document root
cp $INDEX_FILE $DOCROOT

Make the script executable by running the command chmod +x /usr/local/cpanel/scripts/upload_index.sh.

Step 2: Configure cPanel to run the script

Edit the /etc/cpanel/cpanel.config file and add the following line at the end:

script_upload_index = /usr/local/cpanel/scripts/upload_index.sh

This will tell cPanel to run the upload_index.sh script whenever a new account is created.

Step 3: Configure the script to run on new account creation

Edit the /etc/cpanel/whostmgr/config file and add the following line at the end:

script_upload_index_on_create = 1

This will tell cPanel to run the upload_index.sh script whenever a new account is created.

Step 4: Restart cPanel services

Restart the cPanel services by running the command service cpanel restart.

How it works:

When a new account is created in cPanel, the whostmgr script will run the upload_index.sh script as part of the account creation process. The script will upload the index.html file to the document root of the new account.

Tips and Variations: