Add a custom virtualhost configuration on cpanel |Apache 2.4
Add a custom virtualhost configuration on cpanel |Apache 2.4
Date posted: 13-10-2017
Latest cPanel comes with apache 2.4 and in this post we will explain on how to create custom vhost configuration.
Assumption:
- cPanel server
- Server Access
- Assuming that, we will create a custom configuration for the domain ‘domain.tld’ and the username is ‘cusername’
Implementation:
Create a directory for the domain custom virtual host configuration. This custom configuration is for https section.
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/cusername/domain.tld/
For http configuration, create a directory.
mkdir -p /etc/apache2/conf.d/userdata/std/2_4/cusername/domain.tld/
Now, create a configuration file and append the changes in it.
vi /etc/apache2/conf.d/userdata/ssl/2_4/cusername/domain.tld/domaintld.conf
DirectoryIndex home.html
In the above example, we just added DirectoryIndex in it. You can add more configuration changes in this file.
Similarly, we will be adding the changes on http virtualhost configuration.
vi /etc/apache2/conf.d/userdata/std/2_4/cusername/domain.tld/domaintld.conf
DirectoryIndex home.html
Rebuild httpd configuration.
/usr/local/cpanel/scripts/rebuildhttpdconf
After, we executed the above command, the following lines will be uncommented automatically.
Include “/etc/apache2/conf.d/userdata/ssl/2_4/cusername/domain.tld/*.conf”
Include “/etc/apache2/conf.d/userdata/2_4/cusername/domain.tld/*.conf”
Restart the httpd service using scripts
/usr/local/cpanel/scripts/restartsrv_httpd
Now, the changes automatically applied after restart the service.