In this WordPress Setup Guide, we will learn how to properly set up the Apache Server with Event MPM and PHP-FPM for optimal results.
In Apache, the event, worker, and prefork are Multi-Processing Modules (MPMs) responsible for handling requests, binding to network ports, and managing child processes. Among these, the Event MPM is specifically designed to handle high loads, allowing more simultaneous requests, which is why we will use this module for optimal performance.
Operating System Note: For this tutorial, we will be using the Debian operating system. While the steps provided are specific to Debian, they can be adapted for other Unix-based systems with slight adjustments, such as using different package managers or configuration file paths.
Install Essential Softwares
First, ensure that all the software required to set up WordPress with the Apache server is installed on your system. You can run the following command to install the necessary packages:
sudo apt install apache2 php-fpm openssh-server mariadb-server mariadb-client wget nano sudo php-mysql php-curl php-zip php-gd php-intl php-xml
The above command will install the Apache server, the PHP FastCGI Process Manager (PHP-FPM) module, the OpenSSH server for SSH access, MariaDB for database management, essential PHP modules for WordPress, and the wget
command to download WordPress.
For Alpine Linux Users
If you are using Alpine Linux, you can run the following command to install the necessary packages for proper WordPress installation:
# command for Alpine Linux users
sudo apk add apache2 php-fpm openssh openssh-server-pam mariadb mariadb-client wget nano sudo php-mysqli php-curl php-zip php-gd php-intl php-xml php82-dom php-exif php-fileinfo php-gmp php-mbstring php-iconv php-xmlreader php-xmlwriter php-simplexml php-opcache --no-cache
Note: You can omit the sudo
command if you are logged in as the root user.
Enable Required Apache Modules
On Debian-based systems, you can configure Apache2 using commands such as a2enmod
, a2dismod
, a2enconf
, a2disconf
, a2ensite
, and a2dissite
. These commands simplify enabling or disabling Apache2 modules, configurations, and sites. Run the following commands in the terminal to configure Apache with PHP-FPM:
# Enable the rewrite module
sudo a2enmod rewrite
# Enable the headers module
sudo a2enmod headers
# Enable the proxy and proxy_fcgi modules for PHP-FPM
sudo a2enmod proxy_fcgi
Check PHP-FPM Version: To determine the available PHP-FPM version for configuration, navigate to the /etc/apache2/conf-available
directory and list the files. In this example, the version is php7.4-fpm
. Once identified, enable it using the a2enconf
command:
# Configure Apache with PHP-FPM
sudo a2enconf php7.4-fpm
Configuring Without a2enmod
Some Linux distributions do not include the a2enmod
and a2enconf
commands. In such cases, you need to manually configure Apache2 files to enable Event MPM and PHP-FPM support.
Folder Structure: Debian-based distributions generally have the following folder structure:
mods-available
,conf-available
,sites-available
mods-enabled
,conf-enabled
,sites-enabled
Manual Configuration Steps: To enable a module, copy the required .load
and .conf
files from the mods-available
folder to the mods-enabled
folder:
# Navigate to the configuration directory
cd /etc/apache2
# Enable Event MPM and required modules
cp mods-available/mpm_event.load mods-enabled/
cp mods-available/mpm_event.conf mods-enabled/
cp mods-available/proxy.load mods-enabled/
cp mods-available/proxy.conf mods-enabled/
cp mods-available/proxy_fcgi.load mods-enabled/
cp mods-available/rewrite.load mods-enabled/
cp mods-available/headers.load mods-enabled/
# Enable PHP-FPM configuration
cp conf-available/php7.4-fpm.conf conf-enabled/
Apache Configuration for Alpine Linux
To set up Apache for Alpine Linux, you first need to install additional Apache2 modules. Run the following command to install the required modules:
sudo apk add apache2-ssl apache2-proxy --no-cache
By default, Apache uses the MPM prefork module. To enable Event MPM, disable the prefork module by commenting out its LoadModule
statement (add #
at the beginning). To enable any module, ensure the LoadModule
line does not start with #
. You can manually configure httpd.conf
located in the /etc/apache2/
directory with the following changes:
# Comment out the prefork module
# LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so
# Enable the Event MPM module
LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so
# Configure Event MPM settings
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>
Enable PHP-FPM Support: Create an Apache php fpm config file in the /etc/apache2/conf.d
directory and add the following configuration:
# Enable HTTP Authorization headers
<IfModule setenvif_module>
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
Configure Database for WordPress Installation
WordPress requires access to a database for storing its settings, posts, pages, and comments. We will use MariaDB, an open-source fork of MySQL, for the database.
# Start and secure MariaDB
sudo systemctl start mariadb
sudo mysql_secure_installation
Prompts during mysql_secure_installation
- Enter the root user password when prompted.
- Type y to switch to Unix socket authentication for added security.
- Type n when asked to change the root password.
- Type y to remove anonymous users.
- Type y to disable root login remotely.
- Type y to remove the test database.
- Type y to reload the privilege tables.
Set up the database and users
Open the MySQL shell:
sudo mysql -u root -A
Execute the following queries to create a secure WordPress database:
# Set the root user password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root_password';
# Create a database for WordPress
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
# Create a low-privilege user for WordPress
CREATE OR REPLACE USER 'guest'@'localhost' IDENTIFIED BY 'user_password';
# Grant privileges
GRANT ALL PRIVILEGES ON `wordpress`.* TO 'guest'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Configuring PHP-FPM
If you are using a Debian-based Linux distribution, PHP-FPM may already be configured. However, you can cross-check your php-fpm configuration in the /etc/php/7.4/fpm/pool.d/www.conf
file with the following settings:
user = www-data
group = www-data
listen = /run/php/php7.4-sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
# Uncomment the following line for better performance
pm.max_requests = 500
Installing WordPress Software
The final step is to download and install WordPress from WordPress.org. Use the wget
command to download WordPress:
wget https://wordpress.org/latest.tar.gz
After the download is complete, navigate to the server’s root directory and extract the latest.tar.gz
file. On Debian systems, change the directory to /var/www/html
and extract the file there:
# Navigate to the directory where WordPress will be installed
cd /var/www/html
# Extract the WordPress archive
tar -xzf ~/latest.tar.gz
# Change the owner and group of the WordPress directory to 'www-data'
# This allows the Apache user to write data to this directory
chown -R www-data:www-data wordpress
Creating a Site Configuration File
Create an Apache WordPress config file in the /etc/apache2/sites-available
directory. Use the nano editor or your preferred text editor:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add the following configuration to set up your WordPress site for a specific domain:
<VirtualHost *:80>
ServerName www.your-domain.com
ServerAlias your-domain.com
DocumentRoot /var/www/html/wordpress
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
</VirtualHost>
To set up WordPress for local access, comment out the ServerName
and ServerAlias
directives:
# Configuration for accessing WordPress on localhost
<VirtualHost *:80>
DocumentRoot /var/www/html/wordpress
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
</VirtualHost>
Next, you can enable HTTPS for your website. For more information on serving your website over HTTPS, refer to our tutorial on installing an SSL certificate for your website.
Enabling the Site Configuration
If the a2ensite
command is available, execute the following commands:
# Disable the default site
sudo a2dissite 000-default
# Enable the new WordPress site
sudo a2ensite wordpress
If a2ensite
is not available, manually copy the configuration from the sites-available
directory to the sites-enabled
directory and remove the default configuration file:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo cp /etc/apache2/sites-available/wordpress.conf /etc/apache2/sites-enabled/
For more details on useful Apache2 configurations, check out our post on recommended Apache HTTP Server settings.
Starting the Apache Server and Setting Up WordPress
To finalize the configuration and set up WordPress, restart the necessary services and proceed with the installation through your web browser.
# Restart the PHP-FPM service
sudo systemctl restart php7.4-fpm
# Restart the Apache server
sudo systemctl restart apache2
Visit your domain (e.g., your-domain.com
) in a web browser to complete the WordPress installation process. Refer to our guide on recommended WordPress settings to properly set up your website.
Congratulations! Your Apache, PHP-FPM, and WordPress setup is now complete, and your site is ready to go live.