Home ยป How to change to MPM Worker from MPM Prefork

How to change to MPM Worker from MPM Prefork

Switch from MPM Prefork to MPM Worker on WHM/Cpanel Server

The Apache HTTP server is used widely across various platforms in a wide range of environments. It is a powerful and flexible webserver. Its modular design has allowed Apache to accommodate different environments. Often the needs vary from one platform to another and among the various environments. Different platforms and environments may need different features or at least implement the same features efficiently in different manners. The Apache server includes MPMs or Multi-Processing Modules that are responsible for binding to network ports on machines, accepting requests and dispatching children to handle the requests from clients. In Apache 2.4 you can easily customize the server based on the needs of a particular site.
If your site needs higher scalability, you must choose from one of the two threaded MPMs that include MPM Worker and MPM Event. MPM Event is built on MPM worker except for a little difference. While MPMs appear just like the other modules in Apache, more than one of these MPMs cannot be loaded simultaneously. However, if your site needs higher stability or if you are dealing with older systems and software where compatibility is the main question, you should select Prefork. The default MPM in Apache 2.4 is Prefork. In most cases, compatibility is not a question, and you can easily use one of the threaded MPMs. There are three MPMs in Unix – Prefork, Worker and MPM. However, you also find one more listed alongside these three. MPM ITK is not a MPM. It requires MPM Prefork to work.
You must also switch to the latest version of WordPress and PHP if you have not updated them yet. It is good in terms of both site security and performance.

Several hosts suggest switching to a threaded MPM from the non-threaded for improved server performance.
To switch from MPM Prefork to MPM Worker, you will first need to disable Prefork. You cannot run two MPMs together and if you try to you will receive an error and warning.
To change your MPM from Prefork to Worker, login to WHM.
Search for EasyApache4 in the search box and open it.
In the EasyApache 4 interface, you will find the package that is currently installed on your server as as well as other available packages. The package that you are currently running is listed at the top.
Click on customize to make changes to your existing package.
When the interface opens, you will see the MPMs listed in the first section.
You just need to toggle the button next to MPM Prefork to uninstall it. Prefork is enabled by default on Apache 2.4
Now, you will need to toggle the button next to MPM Worker to install it. This will uninstall Prefork and install MPM Worker. You cannot keep both.

Take a look at the image below. In this image, we have the MPM Event active. If you want to switch to another, you need to toggle the blue button to uninstall it. You can also see the other MPMs listed under it. Now, you can toggle the button next to the mod_mpm_worker to use the MPM Worker.

Now, you can also check out other sections in the package like Apache modules, PHP versions, PHP extensions and extra packages or go directly to review if you do not need to make any further changes.
Click on review and it will bring before you a list of features you are about to install and uninstall and the features or modules that will remain unaffected by these changes. it will show you that the system is going to uninstall Prefork and replace it with MPM worker.
After reviewing the changes, you can click on provision to provision the required MPM with your current package. The provisioning process will take a few minutes. Once the process is completed, you will have MPM Worker installed on your server instead of MPM Prefork.

If you are using a WHM/Cpanel server, using EasyApache4 is the most recommended method for changing MPMs. It ensures that the system implements the changes correctly, leaving no chances of error. Chances of error are higher when you use another method like SSH or editing the configuration files to load specific modules.

Why switch from Prefork to Worker or Event?

Prefork is a non-threaded MPM and mostly suited for the older system or software versions. You must use it only when the question of compatibility arises or when you are dealing with non-thread-safe modules. Since Prefork is a nonthreaded MPM, each of the child processes is able to handle only one request at a time. The concurrent requests get queued and the MPM has to wait till the system is available to process each request. However, the scaled child processes will also consume a large amount of system RAM. The worker MPM on the other hand can server several requests concurrently. How the worker MPM does it is by forking Apache into several processes and there are numerous threads for each forked process and a listener thread to listen for connections. The Event MPM works in a similar manner as Worker except that it has a dedication system that it uses to dedicate a thread to handle all live connections. It allocates the child threads a request only when it is received. Once the request is finished, the thread is instantly available.

MPM worker and MPM Event are compatible with mod_cgid whereas Prefork is compatible with mod_cgi. So, when you are changing from Prefork to any of the other MPMs, EasyApache 4 uninstalls mod_cgid and installs mod_cgi also. If you do this through the commandline, you will need to uninstall mod_cgi with MPM Prefork and then install both MPM worker and mod_cgid. The same applies when you switch from MPM Worker to Prefork. You need to run a yum shell command via the command line to remove an MPM and install another. If you do not use yum shell, the system will remove ea-apache24 package. For example, if you want to switch from MPM worker to MPM Event, here is how you can do it from the command line:

yum shellremove ea-apache24-mod_mpm_workerinstall ea-apache24-mod_mpm_eventrun

Here is how you can determine which MPM to use with your system :-

  • If your system requires threads and allows for safe thread-polling, you must use the ‘Event MPM’.
  • If your system requires threads, but does not allow for safe thread-polling, you must use the ‘Worker MPM’.
  • If your system does not require threads and does not allow for safe thread-polling, you should use the ‘Prefork MPM’.