While using WHM/cPanel, We can not make any changes directly in Apache configuration file. This file is automatically created by cPanel templates and re-created on system reboot or WHM update. Any Custom changes will be lost during recreation of Apache configuration file.
But If we want to add own custom configuration in Apache configuration of any websites VirtualHost, We can do it by creating configuration file at /usr/local/apache/conf/userdata/std/2_2/<username>/<sitename.com>/extra.conf. In other versions this location may change. So to find this location, check website VirtualHost in main configuration file, at the end of VirtualHost you will get location like below
# To customize this VirtualHost use an include file at the following location # Include "/usr/local/apache/conf/userdata/ssl/2_2/myuser/mydomain.com/*.conf"
How to do:
Now use the following commands to create directory structure and configuration file. Change myuser with your actual cPanel username and change mydomain.com with actual domain name for which you want to add custom settings.
# mkdir -p /usr/local/apache/conf/userdata/ssl/2_2/myuser/mydomain.com/ # cd /usr/local/apache/conf/userdata/ssl/2_2/myuser/mydomain.com/
Now create configuration file with any name but with .conf extension
# vim extra.conf
Put your custom settings in extra.conf file and execute following command from shell. This command will uncomment “Include “/usr/local/apache/conf/userdata/ssl/2_2/myuser/mydomain.com/*.conf” line in VirtualHost of main apache configuration file.
# /scripts/ensure_vhost_includes --all-users
And all done. By this way you will not loose any custom changes for your VirtualHost.