Apache is the most widely used open-source web server. As per Netcraft webserver survey of December 2016, Apache has a market share of 20.41% among active websites.
Learn to host your own website with Apache, a solid, well-known, and easy-to-configure web server. Apache is an open source web server that’s available for Linux servers free of charge. The vast majority of Apache HTTP Server instances run on a Linux distribution, but current versions also run on Microsoft Windows, OpenVMS, and a wide variety of Unix-like systems. Past versions also ran on NetWare, OS/2 and other operating systems, including ports to mainframes.
With websites getting complex and businesses growing competitive, one of the primary concerns for hosting providers is to find a balance between web server density and website performance.
To reap the cost benefits, server owners need to host maximum number of websites in the web server. At the same time, they must ensure the guaranteed speed and uptime for their customer websites.
How to speed up Apache web server?
As we all know, having enough hardware resources is a must for running an efficient web server. A fast CPU and adequate memory (RAM) are the basic necessities for a high-speed Apache web server.
But you cannot guarantee a good performance out of your webserver with the hardware alone, or by adding more CPU or RAM. Moreover, investing too much on hardware isn’t economically a feasible solution either.
That’s where Apache performance tuning comes into picture. With your existing hardware resources, it is possible to speed up Apache by about 50%, by tweaking the configuration settings of Apache.
Through our web server management services, Bobcares helps server owners deliver high uptime and performance for their websites. Here we’ll shed some light into how we do that using performance tuning.
5 step process to speed up Apache
To speed up Apache, it can be tweaked at two stages –
- During compile-time, which includes the settings used during webserver install.
- At run-time, which are the parameters that have effect while running the webserver.
1. Compile-time options to speed up Apache
Many often server owners install Apache using automated tools such as RPM or yum. But a flaw with those options is that it would be a full install, a minimal install or an install based on a predefined configuration.
While predefined or minimal installs may not give all the required features, going for a full option install may load up the webserver files and slow it down. That’s why its important to go for a custom compilation, which we’ll discuss here.
a. Load only the required modules
In an Apache webserver, functionalities are covered by including modules relevant for each function. These modules can be of two types – Static and Dynamic (shared).
To list the modules supported by your Apache webserver, use the command ‘apachectl -M’, as shown here.
While static modules are compiled into the httpd binary, dynamic modules are loaded only during run-time.
Having more static modules in the httpd binary can make it faster, but requires recompiling Apache everytime a change is needed.
As a result, Dynamic modules or DSOs (Dynamic Shared Objects) are now preferred by server owners, as they can be compiled separately and loaded during run-time.
But having more dynamic or shared modules can slow down your Apache webserver by about 50%, and can affect the website speed.
So, caution has to be exercised while choosing the modules needed for your Apache webserver. To improve the server speed and performance, we run Apache with only the minimal required modules, as it reduces the memory footprint.
Static Vs Dynamic modules – Key differences
b. Choose appropriate MPM
In Apache webserver, there are MPMs (Multi-Processing Modules) that handle the webserver connections that come to the server. MPM handles tasks such as binding to network ports on the machine, accepting connections and creating child processes.
MPMs are of two types – Prefork and Worker. In Prefork MPM, each httpd process handles one connection each. It is more fault-tolerant and secure compared to Worker, but takes up more memory and resources.
Using Worker MPM, Apache runs as a multi-threaded web server, with one thread handling each connection. This makes it suitable to handle more traffic faster and with less resource usage.
By default, most Apache software comes with the Prefork module. To speed up Apache in high-traffic servers, we switch to Worker MPM in our servers. You can identify your webserver MPM using the command:
Identify the MPM in your Apache webserver
In Apache 2.4, there is support for an experimental MPM – Event MPM – that can handle multiple tasks with one thread. Hence it is even faster than the Worker MPM in handling high traffic sites with minimum memory.
Depending on the traffic and resources in your webserver, you would have to choose between Worker and Prefork MPMs, and this setting can be changed by recompiling Apache.
2. Speed up Apache with run-time tweaks
With increase in customer base and website traffic over time, the performance of the Apache webserver may be affected. The compile-time settings may not be sufficient for the smooth functioning of Apache.
To optimize the run-time settings of Apache server, it is important to audit the performance regularly and then tweak the configuration settings. The most important parameters we optimize to speed up Apache are:
a. DNS lookup
Apache can try to find out the hostname of every IP that connects to it. This add delay in processing request and also lead to wastage of resources. To prevent that, we set ‘HostnameLookups‘ to “0” (Off).
When using ‘Allow from’ or ‘Deny from’ directives, we use IP address instead of a domain name or a hostname. Otherwise a double DNS lookup is performed, which further slows down the webserver.
b. AllowOverride
If ‘AllowOverride‘ is set, then Apache will attempt to open ‘.htaccess’ file in each directory that it visits. These additional file system lookups add to the latency of webserver.
So, we ideally turn it off by setting the value as ‘None’. If ‘.htaccess’ over-riding is required for a particular directory, we enable it for that directory alone.
c. FollowSymLinks and SymLinksIfOwnerMatch

Symlinks or symbolic links are file shortcuts. The apache directive ‘FollowSymLinks‘ instructs the webserver to check for symlinks and follow them. If this is ‘Off’, apache would have to issue additional checks, which would slow it down.
If ‘SymLinksIfOwnerMatch‘ directive is set, then the server will follow symbolic links only if the target file or directory is owned by the same user as the link. This check will also affect speed of apache.
For maximum performance, it is ideal to enable ‘FollowSymLinks’ and disable ‘SymLinksIfOwnerMatch’. But this can lead to security issues too, so we make the final decision after weighing both the speed and security requirements.
d. Content Negotiation
Content negotiation allows client to choose the data format from the webserver resources they are requesting. We recommend to avoid content negotiation for fast response.
If at all content negotiation is required for the site, we use ‘type-map‘ files rather than ‘Options MultiViews‘ directive. With MultiViews, Apache has to scan the directory for files, which adds to its latency.
Running A Basic Apache Web Server Interview
e. MaxClients
The ‘MaxClients‘ sets the limit on the number of simultaneous requests that can be supported by Apache webserver. If its value is too low, the connections will be put on queue and won’t be processed.
But too high a value can overload the memory and affect the speed of Apache responses. So we set an ideal value that is calculated based on the available RAM and the process size.
f. MinSpareServers, MaxSpareServers and StartServers
MaxSpareServers and MinSpareServers determine the number of child processes to be kept idle, waiting to handle apache requests. These values are important because creating child processes requires effort.
If the MinSpareServers is too low and a bunch of requests come in, then Apache will have to create more child processes to serve the requests. This will make it difficult to serve the client requests immediately.
MaxSpareServers shouldn’t be set too high, as it can cause resource problems since the idle child processes consume resources. We set these two values within optimal limits to balance the resource usage and performance.
StartServers directive sets the number of child server processes created on startup. If there are a lot of requests and Apache is restarted frequently, set this to a relatively high value.
g. MaxRequestsPerChild
The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child process will handle. With its default setting, the child process will never expire.
But this can lead to memory leakage and poor performance. Setting the value too low can cause overhead creating new processes. So we set a value in the range of a few thousands to speed up Apache.
h. KeepAlive and KeepAliveTimeout
‘KeepAlive‘ is used to keep a single connection alive to transfer all the files to load a page. This saves the time in establishing a new connection for each file and helps to speed up Apache.
‘KeepAliveTimeout’ determines how long to wait for the next request. We set this to 2-5 seconds in low-traffic and 10 seconds in high-traffic webservers. If set too high, child processes may end up wasting resources waiting for an idle client.
i. Timeout
The ‘TimeOut‘ setting determines how long Apache will wait for a vistor 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.
Determining the values for Apache configuration settings is subjective to the web-traffic volume and the server resources. The values discussed here are not absolute and can vary with the production server features.
3. HTTP Compression & Caching
HTTP compression helps to speed up Apache web servers and improve the bandwidth utilization. The server applies gzip or deflate encoding method to the response before it is sent to the client.
Client then decompresses this payload. HTTP Compression can be enabled in Apache using ‘mod_deflate’ module. Payload is compressed only if the browser requests compression, otherwise uncompressed content is served.
In caching, a copy of the data is stored at the client or a proxy server so that it need not be retrieved directly from the server. Caching frequently accessed files will save bandwidth, decrease server load and speed up Apache processing.
Apache has Cache-control directives to control the caching rules. The modules mod_expires and mod_headers handle cache control through HTTP headers sent from the server.
Also there is server side caching, in which the frequently accessed contents are stored in memory so that it can be served fast. The module mod_cache can be used for server side caching.
There are many other caching software such as memcached and Varnish,which we configure alongside the Apache webserverto speed it up further.
4. Separate server for static and dynamic content
Apache processes that handle dynamic content takes about 3-20 MB of RAM, whereas one that serves static content requires only 1MB memory. A process that handles dynamic content can later serve static content.
This can lead to wastage of memory, which slows down high-traffic webservers. For efficient memory usage, we use separate webservers to handle static and dynamic website contents.
For instance, we use a minimal Apache webserver as the front-end server to serve static contents. Requests for dynamic contents are forwarded to the custom Apache webserver which is compiled with all the required modules.
This request forwarding is accomplished using modules such as mod_proxy and mod_rewrite and the client will feel that the requests are handled by a single webserver.

Using the two webservers, we are thus able to speed up Apache by handling static contents faster without much memory usage, thereby allocating more memory to handle resource-intensive dynamic contents.
5. Tweak MySQL and PHP settings
Rarely do webservers function alone. In most scenarios, there would be a database server such as MySQL and scripting language support such as PHP to accompany the Apache webserver.
It is equally important to optimize the database server to avoid bottle-necks and to improve the performance of PHP products using an accelerator or caching mechanism such as Zend OPcache.

MySQL can be tweaked with options such as table fragmentation and fixing the configuration settings – max connections, buffer size, query cache size, pool size and so on.
Conclusion
Configuring Apache for maximum performance is tricky, there are no hard and fast rules or ‘one-size fits all’ values. Understanding the web server requirements is vital before experimenting with the settings.
Optimizing the website content and the applications running in them, efficient coding and theme designs are also vital to reduce the website content size, which helps to speed up Apache webserver.
Apache Web Server Windows
While certain servers may require specific Apache webserver version for their functioning, its always advisable to go for the latest Apache and kernel versions for both security and feature sets.
We monitor the website performance using tools like ‘ab‘ and httperf regularly to check the effectiveness of apache tuning performed and to speed up Apache by further tweaking, if required.
At Bobcares, we also design and implement custom webserver architecture using NginX, Apache, etc. to ensure high available and high speed infrastructure for our customers.
If you’d like to know how to manage your webservers efficiently for your business purposes, we’d be happy to talk to you.
The Raspberry Pi is a very neat device. I was very excited to get my own a few months back. My plan was to run it for Plex on my unused monitor. Later I purchased the Google ChromeCast which replaced the Pi and it has been collecting dust ever since. Now I decided to make use of the Raspberry Pi to run a web server for working on my projects locally. Let’s get started!
Apache Installation
First, we need to update & upgrade the system with the following codes
Then we need to install apache2 package for Apache web server
You can test your web server running from the Raspberry Pi’s browser typing “localhost”. You should see a placeholder page showing that the server works fine. For testing on a device on your connected network, you will need to visit the host IP of your Raspberry Pi. Check the IP typing the following code
PHP Installation

Now that the Apache Web Server is running, you can run basic static files. We need to install PHP for running dynamic web pages. Type the following command to install required packages for PHP
MySQL Installation
The next thing we need to install is MySQL server for the database. Here is the code to install it.
Be sure to remember the root password that you enter while installing MySQL Server, you will need that later.
For MySQL interacting with Python, we need to install another package
phpMyAdmin Installation
Now we are going to install phpMyAdmin. Better GUI for managing databases
You will be asked to enter the password for root of MySQL server. Enter that and also give a password for phpMyAdmin (it can be different or same as the other one)
Now we will need to make some changes on apache2.conf file for phpMyAdmin
Write the following line at the bottom of the file and save the file (Ctrl + X > Y > Enter).
Now Apache needs to be restarted to run everything in order to the changes.
Yes! phpMyAdmin should be accessible from “localhost/phpmyadmin” or “YOUR_RASPBERRY_PI_IP/phpmyadmin” on the browser.
FTP Server Installation
We are close to having all the things for a good web server. Now we need to install FTP. I used ProFTPD for FTP.
This will ask you to choose init.d or standalone, choose any one of them but I used standalone for this tutorial.
Next, we are going to change the config of proftpd.
You need to change the following lines. The ServerName should be the IP of your Raspberry Pi. Here we used 192.168.1.88. Yours can be different.
Uncomment the # in front of DefaultRoot text. This is a good practice.
Next, we restart proftpd service
To make sure that FTP service runs automatically at startup, enter the following code
Now we need to add a user for FTP. I am using “real” as the username. You can choose anything you like.
Set password the user with the following command
Assign the “/var/www/html/” directory to the user. This is the directory where the files will need to be added and the user will see this directory when they log in using FTP client. Ignore the message that says the directory already exists
Run the following commands to give permissions to the user on the html folder.
FTP setup is done at this point. However, I found it is easier for me to do one extra step to avoid permissions. I edited apache2.conf file to make Apache use the user and group that we created.
Look for the following line and add # in front of User and Group lines. After editing, it should look like the following
Now you can enjoy your very own web server running on a Raspberry Pi! Share your thoughts on the comment section. If you face any issues, let me know as well 😀
