Optimizing Apache Performance – Part 2

Optimizing Apache Performance Part 2

In my previous post, you saw some Apache configuration tips to optimize your Apache web server in Ubuntu. Now I am going to show you more Apache performance tuning tips and tricks. This will improve the overall performance of your Apache web server.

Mod_deflate is an Apache module that allows output from your Apache server to be compressed before being sent to the browser. This will reduce the size of the content that is required to be sent and will decrease the time and the amount of data transmitted to the browser. Mod_deflate module uses gzip compression to compress data, text, HTML, or XML files to approximately 30% of their original sizes.

In Ubuntu 14.04, by default, the mod_deflate module is included and enabled in Apache.

To confirm this, run the following command:

You should see deflate_module (shared) if mod_deflate is enabled.

apache-performance-mod-deflate

By default, the gzip compression level is 9. You can set the gzip compression level from 1 to 9 as necessary.

For example, you can set the gzip compression level to 8 by editing the “/etc/apache2/mods-enabled/deflate.conf” file.

Add the following line:

Save the file and restart Apache.

Varnish cache is an HTTP accelerator and reverse proxy for speeding up an Apache server. It is used to speed up a website by storing a copy of a page served by an Apache web server. It makes the website load faster because it stores the content in RAM.

Note: the following is only a simple example of how to install, configure and start Varnish with an Apache web server. In most cases, you will have to configure it further to suit your own needs.

Install Varnish:

First, you need to add the varnish repository to install varnish on your system.

You can do this by running the following commands:

Configure Varnish Cache:

Varnish will serve the content of the website using port 80 while getting that information from Apache on port 8080.

Now you need to change the varnish configuration file.

Change the lines from

to

Save the file and open the “default.vcl” file. This file tells varnish to look for the server content.

Now tell varnish to get the content on port 8080.

By default, Apache listens on port 80; you need to change this port to 8080.

You can change the Apache listening port from 80 to 8080 by editing the ports.conf file.

Change the value from 80 to 8080.

Save the file and restart Apache and varnish.

Now you can now check the status of varnish by running

APC (Alternative PHP Cache) is a free open-source opcode caching plugin for PHP that can help speed up your site. It caches the output of the PHP bytecode compiler in shared memory; this will reduce parsing and disk I/O overhead for later requests.

You can install APC using the following command:

To verify if APC is now enabled, you can create a info.php file.

Add the following line:

Save the file and restart Apache.

Now open that file in the browser. You should see APC enabled as shown in the below image.

apache-performance-apc

Now, you have enough knowledge to tune up an Apache web server for the best performance. You can also experiment with various available options and measure the web server performance by using tools like ab and httperf. Feel free to comment if you have any questions.

3 comments

    • It has something to do with the “Disable Old Protocol (HTTP 1.0)” section. I removed the lines
      RewriteEngine On
      RewriteCond %{THE_REQUEST} !HTTP/1\.1$
      RewriteRule .* – [F]
      from apache2.conf file and now it’s working.

      Is there a way to get this security tweak working correctly with Varnish?

Comments are closed.

Sponsored Stories