Apache
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.
Post sort order: Post Date (Newest First) | Post Date (Oldest First) | Alphabetical | Date Updated
Turn 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)".
Remove 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.
Password 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...
Disable 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.
Apache 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.
Using 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.
Setting 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.
Disabling 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.
.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.
Viewing 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.
Content-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.
Get 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.
Set 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.
Apache 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.
Force 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.
Aliasing 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.
Changing 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.
Changing 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.
Redirecting 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.
Apache - 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"
Compressing 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.
Use 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.
Seg 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"
Installing 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.
PHP 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"
Default 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.
Installing 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.
Overriding 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.
Using 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.
Howto Restart Apache
Posted December 22nd, 2004 in Apache (Updated March 19th, 2007)
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.
Sablotron 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.
Virtual 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.
