Tag Archives: Apache
Move your .htaccess directives to httpd.conf

Move your .htaccess directives to httpd.conf

Posted 15 October 2009 | By vinu | Categories: Linux, Web Development | Comments

htaccessLast week I was searching the net for a program or application to  move some of our .htaccess directives into Apache’s configuration files. The reason I was looking for this is to improve the performance of the site. When we have directives in the .htaccess file, the performance hit on Apache on when it serves each URL is accessed.

If you have a .htaccess file in your web folders, Apache will have to parse the directives in this file and see if there are any .htaccess files in the parent folder. All this happens before your html or php file is hit by Apache. You can read more about the overheads of .htaccess in  this article. This article .htaccess vs httpd.conf by Dawid Golunski shows that he saw apache served about 6.6% less requests/second when .htaccess was used.

A quick Google search landed me on Paul Reinheimer’s blog where he’s created a php script just for this purpose. His htaccess to httpd.conf script parses all the htaccess files from the current folder and all sub-folders and creates a configuration file with the directives for you to place in your Apache’s configuration file.

Just download his script from this link, and place it in your web-root directory which you want to generate the Apache configuration file and run the following command from the command prompt:

php htaccess.php >~/site.conf

After you run that command, you should have a file site.conf in your home folder. You can open this file to get all the directives for you to place in the Apache configuration file. Once you’ve placed this in the apache configuration file, you’ll need to restart Apache for the changes to take effect. Before you restart, make sure you remove your .htaccess file from your web folders.

When I converted a Wordpress’ .htaccess file using this script, here’s the output I got

<directory var="" www="" blog="">
	<ifmodule mod_rewrite.c="">
	RewriteEngine On
	RewriteBase /
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule . /index.php [L]
	</ifmodule>
</directory>

I just put this into the apache2.conf and restarted it, removed the .htaccess from the webroot in /var/www/blog and all the rules worked as they should. As with any script, if you have more complex directives in your .htaccess, test your sites thoroughly before pushing your changes into the production server.

The only (minor) disadvantage I found with this method is that the apache server has to be restarted to make changes to your rule-sets you put in the configuration files. It seems apache just has to be reloaded and doesn’t have to be completely restarted to get the changes to the configuration to take effect (thanks Keleo for the tip). Also this conversion will not be possible if your site is running on a shared webhost where you don’t have access to the apache configuration files.

Links:
Paul Reinheimer’s Article .htaccess to httpd.conf
Paul’s htaccess.php Script
htaccess vs httpdconf – Benchmarks

Reblog this post [with Zemanta]

Hide PHP and Apache versions

Posted 02 November 2006 | By vinu | Categories: PHP, Security | Comments

If you would like to prevent Apache from exposing the version information in every request to the server, all you have to do is to put in the following lines into your apache configuration file:

ServerTokens ProductOnly
ServerSignature Off
Now that we’re not exposing the Apache version, let’s hide the PHP version also. To do this, head over to your php.ini file and set expose_php to off. This setting is on by default and when ever a php file is accessed, an X-Powered-By header is sent back through Apache.

expose_php = Off

htaccess Generator

Posted 26 May 2006 | By vinu | Categories: Uncategorized | Comments

Do you find that creating htaccess files are too complex for you? Well here’s something just for you. A htaccess generator, which provides you with options to fill up on a form. When you submit the form, you get your own htaccess file generated based on your selected options.
Link: htaccess Generator

Setting up a PHP Proxy Server

Posted 08 March 2006 | By vinu | Categories: PHP, Software | Comments

Ever been in a situation where you couldn’t access sites because your ISP or sysadmin has been blocking access. Here’s your chance to set up your own proxy server to bypass the firewalls and proxy. If you’ve got access to an external server with Apache and PHP installed, head over and get PHProxy and install it on your server.

PHProxy is a Web HTTP proxy programmed in PHP to bypass firewalls and other proxy restrictions through a Web interface very similar to the popular CGIProxy. School/country/company blocked your favorite Website?

Link: PHProxy – Anonymizing PHP Web Proxy [Edit] Changed the link since the old 404′ed

Bitrock :: Solutions :: LAMPStack

Posted 07 March 2006 | By vinu | Categories: Databases, PHP, Software | Comments

Here’s an interesting installer called from Bitrock, which allows you to create installers for your application on Windows, Mac, Linux, Solaris, IRIX, HP-UX and FreeBSD. The installer also has a LAMP stack which installs Apache, PHP and MySQL to deploy your PHP application on the client machines.

The installer is free if you’re planning to deploy an open source application.
BitRock LAMPStack is an easy to install, pre-integrated distribution of Apache, MySQL Community Edition, PHP and Python. It allows you to take advantage of the stability, low cost and high performance of the LAMP platform (Linux, Apache, MySQL, and PHP/Python) without the hassle of integrating, configuring, and supporting your own build. BitRock LAMPStack is a great way to achieve rapid, consistent deployments across a variety of Linux platforms.

Link:Bitrock :: Solutions :: LAMPStack

Configure Apache for Performance

Posted 27 February 2006 | By vinu | Categories: Uncategorized | Comments

Here’s an excellent article which outlines how you can squeeze the maximum performance from your Apache Server. The article outlines both compile time and runtime configuration options.

Apache server performance can be improved by adding additional hardware resources such as RAM, faster CPU etc. But, most of the time, the same result can be achieved by custom configuration of the server. This article looks into getting maximum performance out of Apache with the existing hardware resources, specifically on the Linux systems.
Configuring Apache for Maximum Performance | HowtoForge – Linux Howtos and Tutorials

[tags]Apache, optimization, configure, configuration[/tags]

Creating Search Engine Friendly URLs in Mambo 4.5

Posted 29 December 2005 | By vinu | Categories: PHP, Web Development | Comments

Mambo 4.5 has in-built functions to create search engine friendly URL’s. Most search engines don’t index sites with query strings in the URL. To overcome this, most CMS systems have in-build systems that allow you to clean the URL to make it search engine friendly. For example take the following URLs as an example:
http://project.com/index.php

http://project.com/index.php?option=com_view&task=view&article=4

Most search engines don’t index the inner pages with URL’s like the one above since they assumes that it’s part of index.php. All Mambo pages refer to index.php, so most of the inner contents don’t get indexed on a search engine.
[...]

Apache Performance and Security Guide

Posted 27 December 2005 | By vinu | Categories: Security | Comments

Here’s a very good article on how to optimize performance and improve security on Apache Servers.

This guide is written mostly for web administrators/developers, who want to optimize the speed and increase the security of Apache web server. Without a doubt, Apache is still one of the best web servers on the Internet. Being open source, loaded with modules that can do almost anything, Apache is a good solution for both development and production needs. This guide will help you get the best out of Apache web server by letting you control its usage with minimum resources.

Link: Nasim Mansurov » Apache Performance and Security Guide

Running PHP4 and PHP5 Concurrently

Posted 15 December 2005 | By vinu | Categories: PHP | Comments

Some of the projects are running on PHP4 and while we require PHP5’s XML handling capabilities in our newer projects. Migration of the existing projects from PHP4 to PHP5, being quite a mammoth task, is out of the question. So I started looking out on the web for solutions to this problem.

I one solution from Tobias Schlitt’s Site on how to get both versions running on the same machine as Apache 1.3 modules. The only problem with this method is that the PHP files will have to be renamed to .php4 and .php5 to figure out which version of PHP apache has to call.

Another method I found was to compile two versions of Apache on the server and uses Apache’s mod_proxy to do some magic!
Here’s a link to the article: Running PHP 4 and PHP 5 Concurrently