ApacheApache

Information and howtos about the Apache web server

Apache is an open source web server that runs on a variety of platforms including various UNIX flavours, Novell Netware and Microsoft Windows. It is used to run more websites on the Internet than any other webserver and has done so since 1996, as reported by the Netcraft Webserver Survey. The Apache webserver can be downloaded in binary and source form from the Apache website. Check out file data recovery.

Post sort order: Post Date (Newest First) | Post Date (Oldest First) | Alphabetical | Date Updated

Apache ignoring RewriteRule when no extension in filenameApache ignoring RewriteRule when no extension in filename

Posted June 16th, 2011 in Apache

In the process of moving a LAMP web application from its old sever (with CentOS 5) to a brand newly installed server (with Debian 6) I found I was having a weird issue with Apache. I had a rewrite rule so e.g. foo/1/2/3 would rewrite to foo.php?a=1&b=2&c=3 but the rewrite rules didn't appear to be working although the foo.php file was being served, despite the fact there was no extension present in the URL and there was a bunch of other stuff after the filename.

Read more »

Password protect a hotlinked file with ApachePassword protect a hotlinked file with Apache

Posted November 24th, 2010 in Apache

In one of my posts I have an AJAX loading image to demonstrate showing a loading image while waiting for an AJAX request to run. For some reason a bunch of people have decided to hotlink the loading image from my site, rather than generate their own from ajaxload.info and host it themselves.

There are many websites out there offering how to prevent hotlinking by using rewrite rules to show either a different image or make it forbidden (here's a good tutorial ) but I decided to do it differently and pop up a username and password dialog instead.

Read more »

Apache .htaccess recipes, tips and tricksApache .htaccess recipes, tips and tricks

Posted November 19th, 2010 in Apache (Updated November 24th, 2010)

This is a summary post containing a list of the articles from this blog containing recipes, tips and tricks for using Apache's .htaccess files.

Read more »

Allowing and denying access by IP address with ApacheAllowing and denying access by IP address with Apache

Posted November 19th, 2010 in Apache

Apache's configuration allows access to be restricted by IP address in both the main configuration file, virtualhost directives and .htaccess files. It can be useful to deny access to specific IP addresses, for example to keep a bad robot out; and it can equally be useful to deny access to all IP addresses but allow a select few in, for example to restrict access for a specific area of a website (e.g. the admin) to a specific number of IP address. This post shows how to do both.

Read more »

Stop logging "internal dummy connection" in ApacheStop logging "internal dummy connection" in Apache

Posted November 16th, 2010 in Apache

Apache 2.x keeps child processes alive by creating internal connections which appear in the log files as "internal dummy connection" on the IP address ::1 or 127.0.0.1. If you ever monitor Apache log files you'll see a lot of these in the log files. This post shows how to prevent logging for these two IP addresses so your log files won't get filled up with these.

Read more »

Password protection with Apache but allow from an IP addressPassword protection with Apache but allow from an IP address

Posted August 11th, 2010 in Apache

I have posted how to password protect a directory and remove password protection from a subdirectory with Apache and in this post look at how to have a password for all users except those from a defined IP address or set of IP addresses.

Read more »

Turn off PHP on ApacheTurn off PHP on Apache

Posted July 14th, 2010 in Apache and PHP

This post is a response to a question asked on my "Disable PHP in a directory with Apache .htaccess" article asking how to disable PHP completely in Apache, or as it was asked: "Could you tell me how can I turn off PHP on Apache (Run Apache without PHP)".

Read more »

Remove password protection from a subdirectory with ApacheRemove password protection from a subdirectory with Apache

Posted June 30th, 2010 in Apache

When a directory is password protected with Apache either with a .htaccess file or in the main Apache configuration, all subdirectories are also password protected. This post shows how to remove password protection from a subdirectory and from an individual file.

Read more »

Password protect a directory with ApachePassword protect a directory with Apache

Posted June 29th, 2010 in Apache

This post is more of a self-reference than anything because there are probably fifty million other posts on the Internet showing how to password protect a directory with an Apache .htaccess file...

Read more »

Disable PHP in a directory with Apache .htaccessDisable PHP in a directory with Apache .htaccess

Posted March 29th, 2010 in Apache and PHP

If you have a directory which users can upload files into it's a good idea for security reasons to disable server-side parsing of scripts such as PHP. This post shows a couple of options using Apache's .htaccess files.

Read more »

Apache and icons directoryApache and icons directory

Posted March 28th, 2010 in Apache

Default installations of Apache usually alias /icons to Apache's icons directory which cannot be overridden in an .htaccess file. If you do not control the Apache configuration of a server, and for maximum compatibility, it is always best to never have an /icons directory at a website's root level.

Read more »

Using Apache mod_expires to control browser cachingUsing Apache mod_expires to control browser caching

Posted March 21st, 2010 in Apache

Apache's mod_expires module allows settings by file type to control how long browsers cache files. This is useful for ensuring browsers cache image, Javascript and/or CSS files without making additional unecessary requests when loading pages.

Read more »

Setting 503 Service Temporarily Unavailable headers with Apache .htaccessSetting 503 Service Temporarily Unavailable headers with Apache .htaccess

Posted March 14th, 2010 in Apache and PHP

When temporarily taking down a website to perform maintenance, it's a good idea to return a "503 Service Temporarily Unavailable" header so search engines know to come back later. This post shows how to set this header using an Apache .htaccess file, and also how to show a response page to users with PHP so they know to try again later.

Read more »

Disabling PHP short tags in an Apache .htaccess fileDisabling PHP short tags in an Apache .htaccess file

Posted March 11th, 2010 in Apache and PHP

PHP code in a script is commonly delimited by opening <?php and closing ?> tags but there are also the older short open tags like this <? There are instances where you may need to disable short tags as shown in this post and using an Apache .htaccess file.

Read more »

.htaccess condition to prevent missing CSS, JS, image urls being parsed by SilverStripe.htaccess condition to prevent missing CSS, JS, image urls being parsed by SilverStripe

Posted February 21st, 2010 in Apache and SilverStripe

The default .htaccess file for SilverStripe runs all URLs that do not belong to actual files on the filesystem through the Sapphire framework. This means that if a request is made for a CSS file that does not exist, for example, it will be run through SilverStripe/Sapphire, which is not really necessary.

Read more »

Viewing live Apache logs with tail, grep and egrepViewing live Apache logs with tail, grep and egrep

Posted January 24th, 2010 in Apache

There are times you may need to monitor what's happening on an Apache web server as is happens. This can be done from the command line using a combination of the tail command, which outputs the last part of a file, and grep or egrep which are used for regular expression pattern matching.

Read more »

Content-type for Javascript with ApacheContent-type for Javascript with Apache

Posted January 19th, 2010 in Apache and Javascript

I was making some changes to an Apache configuration this morning to ensure mod_deflate was compressing CSS and Javascript files and discovered I'd either documented the content-type for Javascript incorrectly, or the Apache version and Linux distro I used at the time served Javascript differently.

Read more »

Get Apache to parse .html files as PHPGet Apache to parse .html files as PHP

Posted January 10th, 2010 in Apache and PHP

When PHP is installed in Apache files with the .php extension are interpreted as PHP scripts. It is possible to make any file extension be parsed as PHP including .html.

Read more »

Set PHP configuration options with an Apache .htaccess fileSet PHP configuration options with an Apache .htaccess file

Posted April 16th, 2009 in Apache and PHP (Updated May 28th, 2009)

PHP has a large number of configuration option which can be set in the php.ini file, Apache <virtualhost> blocks, .htaccess files and ini_set(). This post looks at how to set PHP configuration options with Apache's .htaccess files.

Read more »

Apache does not log HTTP status set with PHP header when using mod_rewrite in .htaccess filesApache does not log HTTP status set with PHP header when using mod_rewrite in .htaccess files

Posted April 5th, 2009 in Apache and PHP (Updated April 6th, 2009)

I discovered something rather annoying the other day relating to setting HTTP response codes with PHP's header() function, Apache's mod_rewrite and associated webserver logging. If anyone knows of a solution to the issue I have discovered below I'd love to know it.

Read more »

Force reload of updated CSS and Javascript files with unique filenamesForce reload of updated CSS and Javascript files with unique filenames

Posted March 20th, 2009 in Apache, HTML and CSS, Javascript and PHP

When a CSS or Javascript file is changed the visitor's browser needs to get the latest copy of the file to reflect the changes, but it will have been cached and may cause rendering or functionality issues depending on the changes. To force reloading of the CSS and Javascript file the files should be renamed each time they are changed; this can be automated by using PHP to add the timestamp of the file into the filename.

Read more »

Aliasing images to a remote server with .htaccessAliasing images to a remote server with .htaccess

Posted April 19th, 2008 in Apache

When maintaing a website for a customer where there are several gigabtyes of product images that change frequently, it can be annoying to have to keep a local copy of all those images, particularly when bandwidth usage is taken in to consideration. Using .hatccess files on Apache with a clever use of rewrite rules, it is possible to still reference the images files as if they are on the local webserver but they are really served off the remote server. This makes the local development copy of the website look just like the remote one without having to worry about keeping the images in sync. This post looks at how to do this.

Read more »

Changing the .htaccess filename in ApacheChanging the .htaccess filename in Apache

Posted April 17th, 2008 in Apache

Apache allows the use of .htaccess files which can change certain configuration options in a per-directory basis. By default .htaccess files are named .htaccess but it is possible to use a different name either for the whole server, or on a virtual host by virtual host basis. This post looks at how to change the filename used.

Read more »

Changing Apache log rotation behaviour on CentOS / RHELChanging Apache log rotation behaviour on CentOS / RHEL

Posted March 22nd, 2008 in Apache

On a default install of CentOS or Red Hat Enterprise Linux, the log rotation script will automatically rotate the Apache log file each day and then reload the httpd service. This post looks at how to prevent this action from occuring automatically, or to change the behaviour to rotate the log files if your naming convention for log files is different from the default.

Read more »

Redirecting an existing RSS feed to FeedburnerRedirecting an existing RSS feed to Feedburner

Posted December 19th, 2007 in Apache

Feedburner can host an RSS feed for you and provide useful statistics about the readers. If you already have an RSS feed running locally on your site, you can change the feed location to a Feedburner one and set up permanent redirects in Apache so that existing readers will be counted by Feedburner. I did this recently for my Linux CD Mall website, because I was interested to see how many readers I have utilising the feed. Until moving the RSS feed to Feedburner I had no idea how many there were.

Read more »

Apache - Permission denied: Failed to acquire SSL session cache lockApache - Permission denied: Failed to acquire SSL session cache lock

Posted November 15th, 2007 in Apache

I've set up a CentOS 5 Apache web server for a customer where we run the web server as user different from the default user "apache" (often "nobody" is used as well). The application runs through SSL using mod_ssl, and when accessing SSL secured pages errors like these would appear in the error log:

"[Wed Nov 14 11:16:49 2007] [warn] (13)Permission denied: Failed to acquire SSL session cache lock [Wed Nov 14 11:16:49 2007] [warn] (13)Permission denied: Failed to release SSL session cache lock"

Read more »

Compressing files on Apache with mod_deflateCompressing files on Apache with mod_deflate

Posted November 6th, 2007 in Apache (Updated June 25th, 2008)

It's possible with the Apache web server to compress files that are sent to the browser so less bandwidth is consumed and the load time should generally be faster. The module in Apache 2.0 and up is called mod_deflate.

Read more »

Use of www in website addressesUse of www in website addresses

Posted October 22nd, 2007 in Apache

Tim Berners-Lee is the creator of the "World Wide Web" and the www prefix used in so many website addresses was his "fault" :) It made sense at the time to have a different prefix for domains for different services such as ftp, email, websites and more. However, websites came to use both the www and non-www prefix for accessing them (eg www.example.com and example.com) and the www part has therefore become somewhat redundant.

This article looks at why I use the www version of the domain name as the primary domain name for my websites, and redirect traffic from the non-www version to the www version.

Read more »

Seg fault or similar nasty error detected in the parent processSeg fault or similar nasty error detected in the parent process

Posted September 27th, 2007 in Apache

One of the servers I manage runs CentOS 5.0 with Apache 2.2 and PHP 5.1.6, and uses PHP's APC 3.0.14 (Alternative PHP Cache). We process the logs using AWStats every 15 minutes, and rotate the logs on a daily basis. However, after two or three days of working correctly, Apache would crash and we'd get the following in the log files: "seg fault or similar nasty error detected in the parent process"

Read more »

Installing AWStats on CentOSInstalling AWStats on CentOS

Posted September 26th, 2007 in Apache and Linux/Unix/BSD

AWStats provides a useful overview of website statistics from your Apache log files. There is no automatic way to install AWStats on CentOS using yum, so this article looks at how to install AWStats on CentOS. The instructions below should also work on other Linux distributions that do not have an automatic way of installing AWStats.

Read more »

PHP Error Class 'SoapClient' not foundPHP Error Class 'SoapClient' not found

Posted September 25th, 2007 in Apache and PHP

I've often found that something gets left out or forgotten when moving a website from an old server to a new install. I've just finished migrating one of my customer's sites to a new CentOS 5.0 install with Apache 2.2 and PHP 5.1.6, and there's one single PHP script in the site which uses the SoapClient class.

Naturally I'd forgotten to test this particular function until after the migration was complete, and was wondering why the script had failed. A quick look in the Apache error log file revealed the following error message: PHP Fatal error: "Class 'SoapClient' not found"

Read more »

Default virtualhost's secure certificate used with mod_sslDefault virtualhost's secure certificate used with mod_ssl

Posted September 21st, 2007 in Apache

After getting mod_ssl for Apache installed on CentOS 5 yesterday, I discovered when I actually went to test the site through the SSL server that it wasn't actually configured correctly and wasn't using the real secure certificate. Firefox and other web browsers alterted me that the certificate wasn't valid or was from an invalid or unknown certificate authority, despite actually having a valid certificate.

Read more »

Installing mod_ssl on Apache on CentOS 5Installing mod_ssl on Apache on CentOS 5

Posted September 20th, 2007 in Apache (Updated May 21st, 2010)

I was moving a customer's website from its old dedicated web server to a shiny new one, installing CentOS 5 on it with Apache 2.2 and MySQL 5.0. They already had a secure certificate running on the old site, so I copied the certificate files over and the secure server settings into the appropriate configuration file.

Read more »

Overriding the AWStats LogFile Configuration OptionOverriding the AWStats LogFile Configuration Option

Posted September 7th, 2007 in Apache and Linux/Unix/BSD

I run AWStats on one of my servers and it copies files over from some of the other servers I manage every 15 minutes and processes them. However, I had a server issue yesterday with the machine that AWStats runs on, and it meant the auto process which copies the files over and runs AWStats stopped running for about 12 hours. The end result was some lost information and needing to regenerate stats for the month to date. I needed to override the AWStats LogFile configuration directive on the command line to be able to do this.

Read more »

Using Apache's Rewrite Engine with vhosts enabledUsing Apache's Rewrite Engine with vhosts enabled

Posted June 19th, 2007 in Apache (Updated April 21st, 2009)

I am currently working on a project for a customer where I'm converting it from a static html site to a database driven site with a search engine and a consultant's name find function. I am using Codeigniter for this project, which uses Apache's mod_rewrite feature, but had some issues when I uploaded the project to the customer's web host due to it being set up with vhosts.

Read more »

Howto Restart ApacheHowto Restart Apache

Posted December 22nd, 2004 in Apache (Updated November 16th, 2010)

If you have made changes to the Apache configuration file httpd.conf, or one of the other included configuration files (eg vhosts.d files), you need to reload the Apache service for the changes to take effect.

Read more »

Sablotron 1.01 Core Dumps with PHP and ApacheSablotron 1.01 Core Dumps with PHP and Apache

Posted February 12th, 2004 in Apache and PHP (Updated May 24th, 2005)

There is a known problem with the Sablotron 1.01 libraries on PHP and Apache which can cause pages to not load and core dumps on the server for some XML files when using Apache and PHP.

Read more »

Virtual Hosts and Secure CertificatesVirtual Hosts and Secure Certificates

Posted November 30th, 2003 in Apache (Updated March 19th, 2007)

The Apache web server can be configured to support SSL requests using the mod_ssl or apache-ssl modules (among others) and OpenSSL. To enable SSL on any webserver you need to have a secure certificate and a separate IP address per SSL secured domain.

Read more »