{"id":2179,"date":"2017-10-13T19:59:34","date_gmt":"2017-10-13T14:29:34","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=2179"},"modified":"2026-09-16T19:07:40","modified_gmt":"2026-09-16T13:37:40","slug":"add-custom-virtualhost-configurationapache-2-4","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/add-custom-virtualhost-configurationapache-2-4\/","title":{"rendered":"How to Configure a Custom VirtualHost in cPanel with Apache 2.4"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">cPanel with Apache 2.4 lets you add custom virtual host configuration without editing Apache&#8217;s main config directly \u2014 changes go into per-domain &#8220;userdata&#8221; files that cPanel automatically includes and preserves across rebuilds. This guide explains how to add a custom virtual host configuration on cPanel with Apache 2.4.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">I. Prerequisites<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A cPanel server running Apache 2.4<\/li>\n\n\n\n<li>Root\/server access<\/li>\n\n\n\n<li>The domain and cPanel username you&#8217;re configuring (this guide uses <code>domain.tld<\/code> and <code>cusername<\/code> as examples)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">II. How cPanel&#8217;s userdata System Works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">cPanel doesn&#8217;t want you editing its main Apache config directly, since it regenerates that file automatically. Instead, it reads any <code>.conf<\/code> files placed in specific per-domain &#8220;userdata&#8221; directories and automatically includes them \u2014 separately for HTTP and HTTPS.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/ChatGPT-Image-Sep-16-2026-06_59_59-PM.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"936\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/ChatGPT-Image-Sep-16-2026-06_59_59-PM-1024x936.png\" alt=\"\" class=\"wp-image-11819\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/ChatGPT-Image-Sep-16-2026-06_59_59-PM-1024x936.png 1024w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/ChatGPT-Image-Sep-16-2026-06_59_59-PM-300x274.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/ChatGPT-Image-Sep-16-2026-06_59_59-PM-768x702.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/ChatGPT-Image-Sep-16-2026-06_59_59-PM.png 1312w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">III. Create the Configuration Directories<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For the HTTPS (SSL) virtual host:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir -p \/etc\/apache2\/conf.d\/userdata\/ssl\/2_4\/cusername\/domain.tld\/\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the HTTP (non-SSL) virtual host:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir -p \/etc\/apache2\/conf.d\/userdata\/std\/2_4\/cusername\/domain.tld\/\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">IV. Add the SSL Configuration<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/apache2\/conf.d\/userdata\/ssl\/2_4\/cusername\/domain.tld\/domaintld.conf\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DirectoryIndex home.html\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can add any other Apache directives you need in this file, not just <code>DirectoryIndex<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">V. Add the HTTP Configuration<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">vi \/etc\/apache2\/conf.d\/userdata\/std\/2_4\/cusername\/domain.tld\/domaintld.conf\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DirectoryIndex home.html\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">VI. Rebuild the Apache Configuration<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/usr\/local\/cpanel\/scripts\/rebuildhttpdconf\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This regenerates cPanel&#8217;s main Apache config and automatically uncomments the include directives pointing at your userdata files, correctly separated by SSL and non-SSL:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Include \"\/etc\/apache2\/conf.d\/userdata\/ssl\/2_4\/cusername\/domain.tld\/*.conf\"\nInclude \"\/etc\/apache2\/conf.d\/userdata\/std\/2_4\/cusername\/domain.tld\/*.conf\"\n<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The <code>std<\/code> include path is easy to get wrong if typed from memory \u2014 both the SSL and non-SSL include paths must match the directory structure from Step III exactly, including the <code>std<\/code> segment for the non-SSL path. A missing or mismatched path segment here means cPanel silently won&#8217;t pick up your HTTP-side configuration.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">VII. Restart Apache<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/usr\/local\/cpanel\/scripts\/restartsrv_httpd\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your custom configuration is now active.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">VIII. Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Custom virtual host configuration on cPanel comes down to placing <code>.conf<\/code> files in the correct per-domain userdata directories \u2014 separately for SSL and non-SSL \u2014 then running <code>rebuildhttpdconf<\/code> and restarting Apache. This keeps your customizations safe from being overwritten whenever cPanel regenerates its main Apache configuration.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Will my changes survive a cPanel update?<\/strong> Yes \u2014 userdata files are cPanel&#8217;s officially supported way to persist custom Apache configuration, specifically so it isn&#8217;t lost when cPanel regenerates the main config.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What if I only need HTTP or only HTTPS, not both?<\/strong> Just create the one directory and config file you need \u2014 you don&#8217;t have to configure both if your site only requires one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Can I include more than DirectoryIndex in these files?<\/strong> Yes \u2014 any valid Apache directive can go in these <code>.conf<\/code> files, not just <code>DirectoryIndex<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-deploy-wordpress-behind-a-reverse-proxy-on-cpanel-apache\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Deploy WordPress Behind a Reverse Proxy on cPanel\/Apache<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/installing-modsecurity-with-owasp-crs-on-apache-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Installing ModSecurity with OWASP CRS on Apache (Ubuntu)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Talk to our experts.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team <a href=\"https:\/\/pheonixsolutions.com\/contact\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction cPanel with Apache 2.4 lets you add custom virtual host configuration without editing Apache&#8217;s main config directly \u2014 changes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[263,370],"class_list":["post-2179","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","tag-cpanel","tag-virtualhost","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-z9","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2179"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2179\/revisions"}],"predecessor-version":[{"id":11820,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2179\/revisions\/11820"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}