WHM/CPANEL is the most popular Shared Hosting panel in the world, even if it is used mostly for HTML/PHP, it comes with a very good interface to manage and assign users and resources to users willing to host 1 or more websites. Customize the virtualhosts on WHM/CPANEL!
Every time an user creates or modifies information about a site, host, domain, subdomain Cpanel modifies the Apache configuration.
Virtual hosting is a method for hosting multiple domain names (with separate handling of each name) on a single server (or pool of servers).
This allows one server to share its resources, such as memory and processor cycles, without requiring all services provided to use the same host name.
In Apache, a virtualhost allows to map a domain/subdomain to a specific path. The definitions of each virtualhost are saved on:
/usr/local/apache/conf/httpd.conf
And if you created a site name mysite.com, you should be able to find a virtualhost like this:
ServerName mysite.com DocumentRoot /home/mysite/public_html ## User reds # Needed for Cpanel::ApacheConf UserDir enabled reds suPHP_UserGroup reds reds SuexecUserGroup reds reds RMode config RUidGid reds reds # To customize this VirtualHost use an include file at the following location # Include "/usr/local/apache/conf/userdata/std/2/mysite/mysite.com/*.conf"
The httpd.conf file is re-generated every time an user updates a site, so this is not the right place to customize the virtualhost.
Instead of that, please refer to the last commands in the Virtualhost definition:
# To customize this VirtualHost use an include file at the following location # Include "/usr/local/apache/conf/userdata/std/2/mysite/mysite.com/*.conf"
This line shows you where to create a folder where we will include our definitions:
mkdir -p /usr/local/apache/conf/userdata/std/2/mysite/mysite.com/
Inside this directory you can create a configuration file where you will include your definition. For example you can create a file called custom.conf
vim /usr/local/apache/conf/userdata/std/2/mysite/mysite.com/custom.conf
And add the following content to add an alias:
Alias /my-url /path/to/custom/directory
Once you finish to edit the file you should execute to apply the changes.
/scripts/ensure_vhost_includes --all-users
This technique allows you to extend your WHM application, for any purpose. If you find a limitation inside the CPANEL options that would require you to modify the apache configuration, this is the solution!
Visit: Rename files in Bash with Regular expressions
If you want to know more about virtualhosting or you want us to customize the virtualhosting, contact us.