Improve Apache Start Speed on cPanel Servers

cPanel recently made the switch to a new Apache system which improved the maintainability of the system easier however did increase the overhead quite significantly. As a result restarting say apache when you add a domain can take quite a while long enough that it may be noticeable. We were noticing this with a few random 1 minute down times each week which was becoming increasingly annoying getting SMS notices a couple times a week only to find nothing down. The problem comes from all the includes that are there by default to help make it easier to do customizations. Here’s all the includes on each vhost of a httpd.conf

Include “/usr/local/apache/conf/userdata/*.conf”
Include “/usr/local/apache/conf/userdata/*.owner-root”
Include “/usr/local/apache/conf/userdata/std/*.conf”
Include “/usr/local/apache/conf/userdata/std/*.owner-root”
Include “/usr/local/apache/conf/userdata/std/2/*.conf”
Include “/usr/local/apache/conf/userdata/std/2/*.owner-root”
Include “/usr/local/apache/conf/userdata/std/2/username/*.conf”

That’s a lot of includes to be doing and just imagine doing it on 500+ vhosts. After speaking with cPanel I found out that at this time cPanel has no plans on making use of the extra include ability it’s there for you to add customizations that may be global. The only one that is necessary is the last one which includes the php mime options in most setups.

So what I found out is you can remove all these includes by modifying your vhost template. So if you were to navigate to /var/cpanel/templates/apache(1|2)/. So in our case I wanted to go to /var/cpanel/templates/apache2/ as we run Apache 2.2. From here you want to make a copy of vhost.default naming it vhost.local which will tell cPanel to use it opposed to the default vhost template.

Now you’re going to want to use your favorite editor to modify the vhost.local and get rid of all those extra includes.

The first set you want to remove is:

[% IF file_test(‘d’, ‘/usr/local/apache/conf/userdata/’) -%]
Include “/usr/local/apache/conf/userdata/*.conf”
[% IF vhost.owner -%]
Include “/usr/local/apache/conf/userdata/*.owner-[% vhost.owner %]”
[% END -%]
[% END -%]

The next set you’ll also want to remove is

[% IF file_test(‘d’, ‘/usr/local/apache/conf/userdata/std’) -%]
Include “/usr/local/apache/conf/userdata/std/*.conf”
[% IF vhost.owner -%]
Include “/usr/local/apache/conf/userdata/std/*.owner-[% vhost.owner %]”
[% END -%]
[% END -%]

We’ve now just need to remove

Include “[% vhost_include_base %]*.conf”

And finally the last include we don’t need

Include “[% vhost_include_base %]*.owner-[% vhost.owner %]”

Now save the file and running the following command

/scripts/rebuildhttpdconf

Once this script is done if you view httpd.conf for your apache you’ll now see the includes are all gone except the one you’ll actually be needing. Now if you restart apache you’ll watch as it almost instantly restarts again like it used to do in the old cPanel configuration. We’ve implemented this on all servers and our issues with slow apache starting speeds are now gone.

As always I cannot guarantee this will work for everyone. But for most generic hosting companies this will be fine as I doubt you’ll be adding custom configuration files. If you ever wish to switch back to the old apache configuration file with the includes simply delete the vhost.local then run the rebuildhttpdconf again and you’ll be back on the old configuration.

This entry was posted in Tips and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *