CPanel EasyApache and Customizing httpd.conf

23 November 2007 – 4:06 pm

Warning: I’m geeking out for a bit here with a technical entry about editing apache configuration files in Cpanel. I barely found anything out on the Interwebs about this, so I thought I’d document what I learned.

All of our web servers run the CPanel host management software. It’s nice having so much of the server configuration options configurable with a web interface.

But sometimes, I need to make changes directly to the apache server configuration files (httpd.conf). This has never been a problem, as long as I didn’t screw anything up of course. I just edit the configuration file, restart apache and move on with life.

That is, until recently. At some point, the CPanel software was updated so that it builds the httpd.conf file based on the information that it gathers from the CPanel configuration settingsf. Now, if you simply edit this file, CPanel WILL overwrite your changes at some later time, breaking whatever functionality you were specifying.

There are all sorts of warnings now in the httpd.conf file instructing that it is no longer appropriate to edit this file directly.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Direct modifications to the Apache configuration file may be lost upon subsequent regeneration of the configuration file. To have modifications retained, all modifications must be checked into the configuration system by running: #
# /usr/local/cpanel/bin/apache_conf_distiller --update #
# To see if your changes will be conserved, regenerate the Apache configuration file by running:
#
# /usr/local/cpanel/bin/build_apache_conf #
# and check the configuration file for your alterations. If your changes have been ignored, then they will need to be added directly to their respective template files. #
# This configuration file was built from the following templates:
# /var/cpanel/templates/apache1/main.default
# /var/cpanel/templates/apache1/main.local
# /var/cpanel/templates/apache1/vhost.default
# /var/cpanel/templates/apache1/vhost.local
# /var/cpanel/templates/apache1/ssl_vhost.default
# /var/cpanel/templates/apache1/ssl_vhost.local
#
# Templates with the '.local' extension will be preferred over templates with the '.default' extension.
# The only template updated by the apache_conf_distiller is main.default. #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

I’m not sure exactly when this happened, though I think it was in the past few months. Or at least my hosting providers updated CPanel to this version recently.

You CAN edit the main httpd.conf settings as long as you run the apache_conf_distiller script to check in the changes.

You CANNOT edit the virtualHost settings and save them with that same script, however. They will not stick.

In order to make customizations to any VirtualHost sections of the httpd.conf file, you must create include files.

The documentation on this is quite poor, but here’s what I figured out.

If you want to change the default VirtualHost settings, either globally, for a specific user, or for a specific domain, you must do so by overriding those settings with separate include file, placed in a very specific directory location. Once you create the appropriate include files in the correct directory tree, a script will add those include files to your httpd.conf file for you.

To me, I only ever want to edit the vhost behavior on a single domain, so I’ll cut to the chase here and show that example:

First, create the following directory struture and file:

/usr/local/apache/conf/userdata/(ssl|std)/(1|2)/<user>/<domain>/custom.conf

for Standard (non-ssl), apache version 1, user called abc, domain called abc.com it would look like this:

/usr/local/apache/conf/userdata/std/1/abc/abc.com/custom.conf

Then put your custom directives in that file. In my case, I wanted to handle wildcard subdomains, so I just added this one line:

ServerAlias *.abc.com

Now, run the following script:

/scripts/ensure_vhost_includes --user=joe

And the appropriate include directives will get added to the VirtualHost sections of your httpd.conf file.

I ran the distiller, just to make sure the data was saved, though that may not be necessary.

If you enjoyed this post, please subscribe to my RSS feed

  1. 13 Responses to “CPanel EasyApache and Customizing httpd.conf”

  2. I’m just getting familiar with cpanel so this informtion is usefull - thanks. I’ve been using plesk for a few years now and I am quite comfortable with the way it does things.

    By CBR on Dec 2, 2007

  3. I’m really struggling to get my cpanel off the ground. Sometimes I do get really confused on the configuration. Hmmm…I think I’ll try the method mentioned by you. Good to find out the info.

    By Sock Yee on Dec 7, 2007

  4. That’s a very helpful tutorial. On shared hosting there are quite a few crons that are run on the boxes that lie outside users control. Even though you really need a sys admin the greater scope for customization on a dedicated box is a clear advantage.

    By Cheap Web Hosting Phil on Dec 10, 2007

  5. I’ve only had to edit my httpd.conf once, well actually it wasn’t me, it was for a client. It’s not quite at the level you were at, but a nice little edit if the situation arises.

    Basically my client needed to add some php script to his site: I was helping him solve the problem of Google returning his home page in their SERPs with a clickbank hoplink! The problem was, all his site was .html and we didn’t want to rename his files to .php and lose the page rank.

    The solution was to add this line to his httpd.conf:

    AddType application/x-httpd-php .html

    So that the server processed his .html files as if they were .php . Nice.

    By Colin McNulty on Dec 14, 2007

  6. Why put things in httpd.conf when you can do it in .htaccess? Is there a difference?

    By Utah Web Design on Dec 18, 2007

  7. Well, this almost works, however, when I do what is above, it creates includes for ALL sites on the server. Not a problem you say? Well, I have three sites on the server using wildcard domains, and now only the first one listed in the httpd.conf works correctly - the others get 404 not found errors. Darn, I wish cpanel would provide a way within the thing to do wildcard subdomains - would really solve this for a lot of people. :(

    By Shane Lambert on Dec 19, 2007

  8. I used this same method twice. It worked once on a Red Hat system.

    It seems that it depends on what the machine is and the platform. Does not always work.

    Bit of a pain for sure.

    OZ

    By OzBlog on Dec 20, 2007

  9. Solution worked great. For awhile I was manually copying custom conf settings (like mod_proxy) after each rebuild. I just followed your directions, and easyapache in WHM automatically added the includes for the custom conf files.

    Thank you for the article. Saved me a ton of research.

    By Sterling Okura on Dec 22, 2007

  10. That’s a very helpful tutorial for me too. On shared hosting there are quite a few crons that are run on the boxes that lie outside users control.

    By marhgil macuha on Dec 27, 2007

  11. Excellent post and an awesome blog. Very thorough and technical. Just the way I like it. You’ve got a phenomenal layout and design. Kudos!

    Kind regards,
    Martin

    By ZYON.COM on Feb 25, 2008

  12. Thanks ALOT. Very useful information.

    Best regards,
    Alexander Borg

    By Borg on Mar 7, 2008

  13. I have found cPanel to be extremely easy to work with it allows us to tweak and setup our sites faster, easier and pain free.

    Nice little tid-bit on info here!

    By Learn cPanel Videos on Apr 1, 2008

  1. 1 Trackback(s)

  2. Dec 1, 2007: n00bie Challenge - Page 10 - WickedFire - Affiliate Marketing Forum - Internet Marketing Webmaster SEO Forum

Post a Comment


Note: Your comment may be delayed for moderation. Sorry for the delay.