How to add a domain in cPanel
Add a secondary domain to your cPanel account using the standard interface or the API. Follow these steps to configure the redirect and document root.
You will add a secondary domain to your cPanel account and configure the document root. These steps target cPanel 118.x on a standard Linux distribution like AlmaLinux 9 or Rocky Linux 9. You will use the standard interface for most users or the API for automation.
Prerequisites
- cPanel Account: You need a cPanel account with root privileges or access to the
Domainssection. Standard accounts allow adding domains; reseller accounts require theresellmodule enabled. - Domain Name: The domain you want to add must not already exist in your account.
- Web Server: Apache 2.4.59 or later running on the same server as your cPanel instance.
- Network Access: Ensure port 2083 (cPanel API) or port 2087 (WHM) is accessible if using API methods.
Step 1: Access the cPanel Interface
Navigate to your cPanel dashboard using your username and password. Log in via HTTPS at https://your-server-ip:2083. Click the Domains icon in the main menu. This opens the domain management page where you can add new entries.
Step 2: Add the New Domain
Click the Add Domain button. Enter the full domain name you wish to add, such as example.com. Select the appropriate document root from the dropdown list. This path is usually /home/username/domains/example.com/public_html. Ensure the Redirect option is set to 301 if you want search engines to follow the redirect automatically.
Step 3: Configure Email Settings
Check the Email Accounts box if you want to create email addresses for the new domain. Leave it unchecked if you only need web hosting. Click Create to save the configuration. The system will create the necessary directory structure and update the Apache virtual host configuration.
Step 4: Verify DNS Propagation
After adding the domain, you must update your DNS records at your domain registrar. Add an A record pointing example.com to your server IP. Wait 15 to 30 minutes for DNS propagation. You can verify this by running
dig example.com from your terminal. The output should show your server IP address as the authoritative answer.
Verify the installation
Open a web browser and navigate to http://example.com. You should see the default cPanel welcome page or your custom index.php file. Check the /.htaccess file in the document root to ensure no errors are logged. View the Apache error log at /var/log/apache2/error.log or /var/log/httpd/error_log to confirm no 403 Forbidden or 500 Internal Server errors.
Troubleshooting
Error 403 Forbidden: This occurs when the public_html directory permissions are incorrect. Run
chown -R username:username /home/username/domains/example.com/public_html and chmod -R 755 /home/username/domains/example.com/public_html.
Error 404 Not Found: This happens if the index.php or index.html file is missing. Create the file using
touch /home/username/domains/example.com/public_html/index.php.
Domain not resolving: If the domain does not load, check your DNS records at the registrar. Ensure the A record points to the correct IP and that no CNAME records conflict with the A record.
SSL Certificate Issues: If you see a security warning, install the certificate using the SSL/TLS icon in cPanel. Follow the wizard to generate a certificate for the new domain.