How to Create a Directory and Configure a Custom VirtualHost for a Domain in cPanel

This article provides step-by-step instructions for creating a directory and configuring a custom virtualhost.conf file for a specific domain in cPanel. Please ensure that you replace any placeholder values (such as yourdomain.com) with your actual domain name.

1. Create the Custom Directory

To create a custom directory for your domain, use the following command. Replace yourdomain.com with your actual domain name:

mkdir -p /home/username/custom/yourdomain.com

2. Create the VirtualHost Configuration File

Next, create a custom virtual host configuration file for your domain. Use the command below, replacing yourdomain.com with your actual domain name and username with your cPanel username:

nano /etc/apache2/conf.d/userdata/std/2_4/username/yourdomain.com/virtualhost.conf

Add your custom configuration directives to this file as needed.

3. Apply the Changes

After editing the configuration file, you must rebuild the Apache configuration and restart Apache to apply the changes:

/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd

Important Reminders

  • Always replace placeholder values (yourdomain.com and username) with your actual domain and account information.
  • Ensure you have the necessary permissions to perform these actions on your server.
  • Take a backup of any configuration files before making changes.

You can use cp filename filename.bak before editing any configuration file to create a backup.

Warning: Incorrect configuration changes can cause website downtime. Proceed with caution and verify all custom directives.

For more information about custom VirtualHost configurations in cPanel, refer to the official documentation or consult your hosting provider.

×