Tuesday, February 7, 2017

Optimization Of Cpanel


Description: Here I have define various optimizations in Cpanel like Apache, MySQL, CSF Firewall, Mail and PHP.
1> Apache Web Server: Change the apache setting using below steps using  WHM » Service Configuration » Apache Configuration » “Global Configuration”
  • Timeout :- This setting determines how long Apache will wait for a visitor to send a request. In busy servers, we set it up to 120 seconds, but it is best to keep this value as low as possible to prevent resource wastage.
  • KeepAlive :-When “KeepAlive” is set to “On”, Apache uses a single connection to transfer all the files to load a page. This saves time in establishing a new connection for each file.
  • MaxKeepAliveRequests :-This setting determines how many files can be transferred via a KeepAlive connection. Unless there’s a reason not to (like resource constrains), this setting can be set to “0”, that is, “unlimited”.
  • KeepAliveTimeout :-This setting makes sure that a KeepAlive connection is not abused. It says how long should Apache wait for a new request before it resets the connection. In heavily loaded servers, we’ve found 10 Sec. to be a good limit.
  • MaxClients :-This setting tells Apache how many visitors can be served simultaneously. In busy servers (such as shared servers), we’ve found 512 to be a good value. However, note that setting it too high will cause resource wastage, and setting it too low will result in lost visitors.
  • MinSpareServers & MaxSpareServers :-Apache keeps a few “workers” on stand-by to handle a sudden surge of requests. If your site is prone to visit spikes, configure these variables. In heavily loaded servers, we’ve found MinSpareServers value of 10 and MaxSpareServers value of 15 to be a good limit.
  • HostnameLookups:-Apache can try to find out the hostname of every IP that connects to it, but that would be a wastage of resources. To prevent that, set HostnameLookups to “0”.
2> MYSQL Optimization : You can optimize SQL server depends on Hardware configuration of server [CPU and RAM]. So below are some my.cnf settings as per CPU and RAM
 
Below SQL Settings for having 2 Core CPU and 4 GB Memory


Open my.cnf and use below settings. 
[mysqld]
local-infile = 0
max_connections = 250
key_buffer = 64M
myisam_sort_buffer_size = 64M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 2M
max_heap_table_size = 16M
table_cache = 5000
thread_cache_size = 286
interactive_timeout = 25
wait_timeout = 7000
connect_timeout = 15
max_allowed_packet = 16M
max_connect_errors = 10
query_cache_limit = 2M
query_cache_size = 32M
query_cache_type = 1
tmp_table_size = 16M
open_files_limit=25280
performance_schema=0


[mysqldump]
max_allowed_packet = 16M


[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M


Below SQL Settings for having 8 Core CPU and 16+ GB Memory
[mysqld]
local-infile=0
max_connections = 600
max_user_connections=1000
key_buffer_size = 512M
myisam_sort_buffer_size = 64M
read_buffer_size = 1M
table_open_cache = 5000
thread_cache_size = 384
wait_timeout = 20
connect_timeout = 10
tmp_table_size = 256M
max_heap_table_size = 128M
max_allowed_packet = 64M
net_buffer_length = 16384
max_connect_errors = 10
concurrent_insert = 2
read_rnd_buffer_size = 786432
performance_schema=0
bulk_insert_buffer_size = 8M
query_cache_limit = 5M
query_cache_size = 128M
query_cache_type = 1
query_prealloc_size = 262144
query_alloc_block_size = 65535
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 8
external-locking=FALSE
open_files_limit=50000
[mysqldump]
max_allowed_packet = 16M
[isamchk]
key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M
[myisamchk]
key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M


3> Security and Limit Resources in Cpanel: Configuration of CSF for securing server
  1.  Go to WHM » Plugins » ConfigServer Security & Firewall » “Check Server Security” And pass on what appears as required to repair:
  2. Go to WHM » Plugins » ConfigServer Security & Firewall » “Firewall Configuration” and set the parameters according to your needs:
  • PT_USERMEM=180
  • PT_USERTIME=180
  • PT_USERKILL=1
  • PT_USERKILL_ALERT=1 (Optional)
Below are some Tweak Settings that increase server performance:
  • Tweak settings open using: Main >> Server Configuration >> Tweak Settings
  • Email delivery retry time: The default is a retry every hour - but you may want to extend this so the server is less strained with larger queues.
  • Max Hourly Emails: By default, this is unlimited. Our shared servers have a limit of 1000 per hour to avoid abuse or spamming.
  • BoxTrapper spam trap: This can help prevent spam, but consumes a lot of memory. We recommend disabling it.
  •  Mailman mailing lists: It's easier on the server to use a program like PHPList (installable through Softaculous). We recommend disabling this.
  • Webmail clients: By default there are three mail clients running. Use just one for better performance - we recommend RoundCube
4> PHP:  Below are some PHP settings that increase server performance
  • Max Execution Time: The default is 90 seconds, but this could be dropped lower if certain scripts are over consuming resources.
  • PHP Max Upload Size: The default is 50 megabytes or MB, but this can be reduced to prevent large files from overloading the server during upload.


No comments:

Post a Comment