+91 – 7838219999

contact@nitinfotech.com

HomeTech SolutionsLinuxInstall & Configure Apache Web Server as Event Driven Architecture

Install & Configure Apache Web Server as Event Driven Architecture

Thursday, November 21, 2024

To install and configure the Apache Web Server with an event-driven architecture, you’ll need to install the event MPM (Multi-Processing Module). The event MPM is designed to handle many concurrent connections efficiently, making it suitable for high-traffic websites.

Here’s a step-by-step guide for installing and configuring Apache with the event MPM on a Linux based system:

1. Install Apache Web server

First, install the Apache web server. On Debian-based systems like Ubuntu, you can use apt-get. On Red Hat-based systems like CentOS, you can use yum or dnf.

Debian-based systems:

sudo apt-get update 
sudo apt-get install apache2

Red Hat-based systems:

sudo yum install httpd
sudo dnf install httpd

2. Enable the event MPM

By default, Apache might be using the prefork or worker MPM. You need to switch to the event MPM.

Debian-based systems:

First, disable the current MPM (if it’s enabled) and then enable the event MPM.

sudo a2dismod mpm_prefork 
sudo a2dismod mpm_worker 
sudo a2enmod mpm_event

Red Hat-based systems:

Open the Apache configuration file and specify the event MPM.

Edit the configuration file:

sudo vi /etc/httpd/conf.modules.d/00-mpm.conf

Ensure the following line is present and uncommented:

LoadModule mpm_event_module modules/mod_mpm_event.so

Comment out the lines for prefork and worker MPMs if they exist:

# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so 
# LoadModule mpm_worker_module modules/mod_mpm_worker.so

3. Configure the event MPM

Now, configure the event MPM settings. Edit the Apache configuration file:

Debian-based systems:

sudo vi /etc/apache2/apache2.conf

Red Hat-based systems:

sudo vi /etc/httpd/conf/httpd.conf

Add or modify the configuration for the event MPM:

<IfModule mpm_event_module> 
StartServers 2 
MinSpareThreads 25 
MaxSpareThreads 75
ThreadLimit 64 
ThreadsPerChild 25 
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>

4. Restart Apache

After making these changes, restart the Apache service to apply the new configuration.

Debian-based systems:

sudo systemctl restart apache2

Red Hat-based systems:

sudo systemctl restart httpd

5. Verify the Configuration

To ensure that Apache is using the event MPM, you can use the following command:

apachectl -V | grep -i mpm

The output should indicate that the event MPM is being used, such as:

Server MPM: event

6. Optional: Tune Your Configuration

Depending on your specific needs and server load, you might need to fine-tune the event MPM settings. The parameters you can adjust include:

  • StartServers: Initial number of server processes to start.
  • MinSpareThreads: Minimum number of spare worker threads.
  • MaxSpareThreads: Maximum number of spare worker threads.
  • ThreadLimit: Maximum number of worker threads that can be created per child process.
  • ThreadsPerChild: Number of threads created by each child process.
  • MaxRequestWorkers: Maximum number of threads that will be available to serve client connections.
  • MaxConnectionsPerChild: Limit on the number of connections that an individual child server will handle during its life.

These settings should be adjusted based on your server’s hardware capabilities and the expected traffic load.

Conclusion

You have now installed and configured the Apache Web Server with an event-driven architecture using the event MPM. This setup should help you handle a large number of concurrent connections more efficiently than with the traditional prefork or worker MPMs.