Apache redirects and performance issues

Where should you put a redirection rule in Apache?

This is the story: I am serving a widget for a client, on their homepage. This client has a huge amount of traffic, much more than what I normally have for my application.

So the first thing I did was to convert this widget into a static file. And serve it from Amazon. But then I had to request the client to change the name of the file to be requested. And before doing that I decided to try out the redirection myself

I started using php header() function. But I realised that using php redirection was a bit overkill.

So I switched to Apache redirection. And my first idea was to use .htaccess.

And it worked nicely. But the CPU of the server, according to New Relic was working too much. So I wondered again, how could this get better? And I remembered that Apache allows to put the redirection directives already in the virtual host configuration file. So this is what I did. I looked into /etc/apache2/sites-available and put the redirection line into the virtual host configuration.

It worked like a breeze! the server is now running like a bullet. And the apache processes, acording to top are now consuming between 1-1.5% of processing power. Beforehand it was above 4%!!

installing New Relic for PHP app

I have to say it is dead simple, just follow the instructions.

But if when you run this command


wget -O - http://download.newrelic.com/548C16BF.gpg | apt-key add -

you get this error


gpg: no writable keyring found: eof
gpg: error reading `-': general error
gpg: import from `-' failed: general error

Then you probably have a problem of access rights. So try with sudo, following this other detailed script, explained here:

https://newrelic.com/docs/php/php-agent-installation-ubuntu-and-debian