Arama Yap Mesaj Gönder
Biz Sizi Arayalım
+90
X
X
X
X

Knowledge Base

Homepage Knowledge Base General Plesk Apache Optimization

Bize Ulaşın

Konum Halkalı merkez mahallesi fatih cd ozgur apt no 46 , Küçükçekmece , İstanbul , 34303 , TR

Plesk Apache Optimization

Why is Apache Optimization Important?

Apache is one of the cornerstones of web servers and directly affects the performance of websites hosted on Plesk. A poorly configured Apache server can lead to slow loading times, high server load, and even site crashes. Optimization allows the server to use its resources more efficiently, allowing it to handle more traffic smoothly. This improves user experience, increases SEO ranking, and boosts overall business performance.

Key Points:

  • Fast Loading Times: Users prefer fast-loading websites.
  • Low Server Load: Optimization ensures that the server consumes fewer resources.
  • Increased Traffic Capacity: An optimized server can handle more concurrent requests.
  • Improved SEO: Search engines rank fast and user-friendly websites higher.

Which Areas Should I Focus On in Apache Optimization?

Apache optimization covers a wide area. You can start by focusing on the following areas:

  1. MPM (Multi-Processing Module) Selection: Apache's MPM determines how it handles requests. Different MPMs are available, such as Event, Worker, and Prefork. Choosing the right MPM significantly affects server performance.
  2. KeepAlive Settings: KeepAlive keeps the connection between the client and the server open, allowing multiple requests to be sent over the same connection. When configured correctly, it reduces connection establishment costs and improves performance.
  3. Module Optimization: Disabling unused or unnecessary modules reduces the server's resource consumption.
  4. Caching: Caching static content reduces the server's load and shortens loading times.
  5. Compression: By using compression algorithms such as Gzip or Brotli, you can reduce the size of web pages and reduce bandwidth usage.
  6. Security Settings: Security vulnerabilities can negatively affect server performance. Configuring security settings correctly improves both performance and security.

How to Choose an MPM (Multi-Processing Module)? Which MPM is Right for Me?

MPM (Multi-Processing Module) is a module that determines how Apache handles requests. There are three main MPMs: Prefork, Worker, and Event. Each has different advantages and disadvantages. The choice depends on the server's hardware, operating system, and expected traffic.

  • Prefork: Creates a new process for each connection. Consumes more resources but is more compatible with older applications. Often used with PHP's mod_php mode.
  • Worker: Each process uses multiple threads. Consumes fewer resources and can handle more concurrent connections.
  • Event: Similar to Worker, but handles KeepAlive connections more efficiently. Ideal for high-traffic websites.
MPM Advantages Disadvantages Suitable Scenarios
Prefork Compatible with older applications, more stable High resource consumption, fewer concurrent connections Servers with low traffic and using older applications
Worker Low resource consumption, more concurrent connections May have compatibility issues with older applications Servers with medium traffic and using modern applications
Event Lowest resource consumption, highest concurrent connections, KeepAlive optimization May have compatibility issues with older applications Servers with high traffic and using modern applications

Step-by-Step MPM Change (CentOS/RHEL Example):

  1. Checking the Current MPM:
    httpd -V | grep MPM
  2. Changing the MPM (Ex: Switching to Event):
    yum install httpd-event

    (If necessary, remove other MPMs: yum remove httpd-prefork httpd-worker)

  3. Restarting Apache:
    systemctl restart httpd

Case Study: An e-commerce site was experiencing performance issues due to high traffic during peak campaign periods. Prefork MPM was being used. After switching to Event MPM, the server load decreased by 40% and page load times dropped from an average of 2 seconds to 0.8 seconds.

How to Optimize KeepAlive Settings?

KeepAlive keeps the TCP connection between the client and the server open, allowing multiple HTTP requests to be sent over the same connection. This eliminates the cost of establishing a new connection for each request and improves performance. However, misconfiguring KeepAlive settings can unnecessarily consume server resources and negatively impact performance.

Important KeepAlive Settings:

  • KeepAlive: On or Off.
  • KeepAliveTimeout: The duration the connection remains open (seconds).
  • MaxKeepAliveRequests: The maximum number of requests that can be sent over a connection.

Recommended Settings:


KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 100

Notes:

  • KeepAlive On: Enables the KeepAlive feature.
  • KeepAliveTimeout 5: The connection is closed if it is not active for 5 seconds. A shorter time allows the server to use resources more efficiently.
  • MaxKeepAliveRequests 100: A maximum of 100 requests can be sent over one connection. This prevents the server from being overloaded.

Step-by-Step KeepAlive Configuration:

  1. Opening the Apache Configuration File:
    nano /etc/httpd/conf/httpd.conf

    (or /etc/apache2/apache2.conf)

  2. Finding or Adding KeepAlive Settings:

    Add the recommended settings above or update the existing settings.

  3. Restarting Apache:
    systemctl restart httpd

Visual Explanation: (Textual Explanation)

Imagine a diagram. In the diagram, when the KeepAlive feature is off, a new TCP connection is established for each HTTP request. This causes a significant delay for a large number of requests. When the KeepAlive feature is on, a connection is established for the first request, and subsequent requests are sent over the same connection. This reduces latency and improves performance.

How to Optimize Apache Modules? How to Disable Unnecessary Modules?

Apache uses modules for various functions. However, each module consumes resources. Disabling unused or unnecessary modules reduces the server's resource consumption and improves performance. To determine which modules are needed, you need to analyze your website's needs.

Commonly Used Apache Modules:

  • mod_rewrite: Used for URL redirection and rewriting.
  • mod_ssl: Used for SSL/TLS encryption.
  • mod_deflate: Used for compression (Gzip).
  • mod_expires: Used for caching.
  • mod_headers: Used to manipulate HTTP headers.
  • mod_php: Used for PHP support. (PHP-FPM is recommended)

Disabling Unnecessary Modules:

To disable Apache modules, the a2dismod command is usually used (on Debian/Ubuntu systems). On CentOS/RHEL systems, you may need to manually disable module configuration files.

Step-by-Step Module Disabling (Debian/Ubuntu Example):

  1. Identify Unnecessary Module: For example, let's assume the mod_info module is unnecessary.
  2. Disable the Module:
    a2dismod info
  3. Restart Apache:
    systemctl restart apache2

CentOS/RHEL Example:

  1. Find the Module Configuration File: For example, find the mod_info.conf file. It is usually located in the /etc/httpd/conf.modules.d/ directory.
  2. Rename or Delete the File: You can disable the file by renaming it (e.g., mod_info.conf.disabled) or delete it (be careful!).
  3. Restart Apache:
    systemctl restart httpd

Important Note: Before disabling modules, make sure it does not affect the functionality of your website. Accidentally disabling an important module may cause your website to not work.

How to Do Caching? What Caching Methods Are Available?

Caching is one of the most effective methods to improve the performance of your website. Caching allows static content (images, CSS files, JavaScript files, etc.) to be stored on the client side (browser) or on a cache server instead of the server. This reduces the load on the server and shortens loading times.

Different Caching Methods:

  • Browser Caching: Web browsers store static content locally. This prevents the same content from being downloaded repeatedly.
  • Server-Side Caching: The server caches dynamic content (results of database queries, templates, etc.). This reduces the database load and shortens response times.
  • CDN (Content Delivery Network): CDNs store your website's content on servers around the world. This allows users to access content faster, especially in geographically remote regions.
  • Object Caching (Memcached, Redis): Especially for dynamic websites, it is used to store the results of database queries or other frequently accessed data in RAM.

Browser Caching with Apache (mod_expires and mod_headers):

The mod_expires and mod_headers modules are used to configure browser caching.

Step-by-Step Browser Caching Configuration:

  1. Enabling the mod_expires Module: (If necessary)
    a2enmod expires
  2. Editing the Apache Configuration File: .htaccess or httpd.conf
  3. Adding Caching Rules:
    
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType image/jpeg "access plus 1 year"
      ExpiresByType image/gif "access plus 1 year"
      ExpiresByType image/png "access plus 1 year"
      ExpiresByType text/css "access plus 1 month"
      ExpiresByType application/javascript "access plus 1 month"
    </IfModule>
    
  4. Restarting Apache:
    systemctl restart apache2

Explanation:

  • ExpiresActive On: Enables the caching feature.
  • ExpiresByType: Defines caching durations for specific file types. For example, image/jpeg files are cached for 1 year.

How to Perform Compression? What is the Difference Between Gzip and Brotli?

Compression reduces the size of web pages, decreasing bandwidth usage and shortening loading times. Gzip and Brotli are two popular algorithms used to compress web pages. Brotli is a newer and more effective compression algorithm compared to Gzip.

Compression Algorithm Advantages Disadvantages Suitable Situations
Gzip Widely supported, easy to configure Lower compression ratio compared to Brotli Situations where older browsers need to be supported
Brotli Higher compression ratio, faster loading times Less widespread support, higher CPU consumption Situations targeting modern browsers where performance is critical

Gzip Compression with Apache (mod_deflate):

Step-by-Step Gzip Configuration:

  1. Enabling the mod_deflate Module:
    a2enmod deflate
  2. Editing the Apache Configuration File: .htaccess or httpd.conf
  3. Adding Compression Rules:
    
    <IfModule mod_deflate.c>
      AddOutputFilterByType DEFLATE text/plain
      AddOutputFilterByType DEFLATE text/html
      AddOutputFilterByType DEFLATE text/xml
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE application/javascript
      AddOutputFilterByType DEFLATE application/xml
      AddOutputFilterByType DEFLATE application/xhtml+xml
      AddOutputFilterByType DEFLATE application/rss+xml
      AddOutputFilterByType DEFLATE application/atom+xml
    </IfModule>
    
  4. Restarting Apache:
    systemctl restart apache2

Brotli Compression with Apache (mod_brotli):

Brotli is an algorithm that provides newer and better compression compared to Gzip. It is used with the mod_brotli module in Apache.

Step-by-Step Brotli Configuration:

  1. Installing and Enabling the mod_brotli Module:
    a2enmod brotli
  2. Editing the Apache Configuration File: .htaccess or httpd.conf
  3. Adding Brotli Compression Rules:
    
    <IfModule mod_brotli.c>
        AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css application/javascript application/x-javascript application/xml application/json
        BrotliFilterQuality 11
        BrotliFilterLength 512
    </IfModule>
    
  4. Restarting Apache:
    systemctl restart apache2

Important Note: Brotli may not be supported by older browsers. Therefore, using both Gzip and Brotli together can provide the best result. This allows modern browsers to use Brotli, while older browsers use Gzip.

 

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(4143 times viewed / 20 people found it helpful)

Call now to get more detailed information about our products and services.

Top