Server Hosting Secrets
February 4th in cPanel, Linux, Tutorials by .

cPanel Apache Security and Optimization

cPanel comes with apache compiled and configured, but it’s not secure at all, it’s not configured for performance either. In this article I’ll share a few tips on how to securely configure apache and optimize it a bit.

In this article I will share a few tips on how to optimize and secure Apache for cPanel servers. This article is the beginning of a long series of server security and optimization for cPanel.
Articles to come: PHP security, CentOS configuration for cPanel, mod security for apache, firewall configuration, cPanel optimization, and much more.

Building Apache:

In order to compile apache, php and other modules you can use “Easy Apache”, you can access it using this ways:
1. From cPanel WHM navigate to: Main >> Software >> EasyApache (Apache Update)
2. From a ssh session execute: /scripts/easyapache
I suggest using the web version, it is easier to read for beginners. Let’s begin:
Page1: Profile
Select: “PHP Security” and push: “Start customizing based on profile”
Page2: Apache Version
Select: “Apache 2.2″ and click “Next Step”
Page3: PHP Major Version
Select: “PHP 5″ and click “Next Step”
Page4: PHP Minor Version
Select: “PHP 5.2.12″ and click “Next Step” (PHP 5.3 is a bit different then 5.2 and has a lot of functions disabled/removed, select PHP 5.3 only if your scripts are compatible with this version).
Page5: Short Options List
Uncheck: Frontpage (this extension is not supported anymore)
Check: Anything that you might need and make sure that: Mod Security, Mod SuPHP and Suhosin for PHP remains checked.
After you are done click on: “Exhaustive Options List”
Page6: Exhaustive Options List
Check: Mod FCGID, Fileprotect, MPM Prefork, Mod SuPHP, Proxy, UniqueId, Mod Security, Suhosin for PHP, CGI, Fastcgi, SafeMode, Safe PHP CGI

Uncheck: Frontpage, Eaccelerator, POSIX, Path Info Check
Don’t forget to read the documentation before you activate any more extensions.
After you are done click “Save and build”.
The compilation process will take a while so be patient. After it is done you will be prompted with a form, select the following:
Default PHP Version (.php files) 5
PHP 5 Handler ***
PHP 4 Handler none
Apache suEXEC on
*** At this point you need to select the php handler, for now let’s stick with suPHP since it’s secure
I guess that you noticed fcgi was selected for compilation, I’ll explain in a future article how to securely configure fcgi as php handler, by default it’s a security risk and not stable at all. For suPHP you can’t enable Eaccelerator so make sure it’s disabled, when you wanna switch to fcgi you can enable it.

And click “Save New Configuration”

Configuring Apahce:

1. Navigate to: Main >> Security Center >> Apache mod_userdir Tweak
And check: “Enable mod_userdir Protection”

2.
Navigate to: Main >> Service Configuration >> Apache Configuration >> Global Configuration
Now configure the options as bellow:
TraceEnable – Off
ServerSignature – Off
ServerTokens – ProductOnly
FileTag – None
MaxClients – 256
MaxRequestsPerChild – 1000

Click “Save” and in the following window click “Rebuild Configuration and Restart Apache”.
If you server is under heavy traffic then you should edit: /usr/local/apache/conf/httpd.conf


<IfModule prefork.c>
ServerLimit 1000
MinSpareServers 5
MaxSpareServers 10
</IfModule>
 MaxClients 256
 MaxRequestsPerChild 1000

And raise the valuse of “ServerLimit” and “MaxClients”, don’t raise too much the value of MaxClients, if your server ever gets attacked/ddos then it might hang if it runs out of memory, try and set it to under: 150 x RAM Memory (in GB).

3. Navigate to: Main >> Service Configuration >> Apache Configuration >> Memory Usage Restrictions
And click: “Proceed >>”

4. Navigate to: Main >> Service Configuration >> Apache Configuration >> Log Rotation
And check all files/logs, after click “Save”.

That’s it for now, stay tuned for more.

VN:F [1.9.11_1134]
Rating: 7.7/10 (15 votes cast)
cPanel Apache Security and Optimization, 7.7 out of 10 based on 15 ratings

22 Comments

  • Affordable Web Hosting
    February 24, 2010
  • Claudiu Popescu
    February 24, 2010
  • John
    December 20, 2010
  • ThinkFast
    February 6, 2011
  • Kate Mag
    February 18, 2011
  • Fred
    March 3, 2011
  • Claudiu Popescu
    March 4, 2011
  • Kirsten
    April 7, 2011
  • Claudiu Popescu
    April 8, 2011
  • Kirsten
    April 8, 2011
  • Solo
    April 14, 2011
  • Claudiu Popescu
    April 14, 2011
  • Server Hardening
    July 10, 2011
  • Claudiu Popescu
    July 11, 2011
  • Chris
    October 12, 2011
  • Chris
    October 12, 2011
  • Claudiu Popescu
    December 4, 2011

Leave A Comment.