Apache

Linux Server Optimization Guide

This is a small guide on how to optimizing a linux server for performance, so that you can extract the full juice of your server. A lot of times, the default configurations are bad, and work slow- especially they matter a lot when you have low ram.

Apache2-PHP-FastCGI-SuExec

Yeah this is one of the most irritating type of thing to setup. I had a tough time with this, but ultimately got it right after a lot of researching.

Follow this tutorial and you'll successfully set the environment up - PHP running via FastCGI within an SuExec Environement in Apache 2 !

So lets start with a case study.

libphp5.so on Apache 2 is faster than CGI or FastCGI

Why this site loads so fast ? The reason is we are using Apache 2.2.10 with libphp5.so

Earlier we were using CGI.

I also tried PHP-FastCGI

Creating an automatic installer for HTTPD

This tutorial explains how to create a simple shell script with default HTTPD compile options which can install HTTPD just in one command PROVIDED you have sudo and the NOPASSWD: ALL in your username's entry in the sudoers file.

So, here's a script which can do the above task. Please note that you need not rewrite all the options given to configure while compiling first time, you can just take a copy of config.nice script which is created by configure present in the build directory. For instance, if your apache directory is /usr/local/apache2 ; then you'll find config.nice in /usr/local/apache2/build.

Actually I must say this is an extension of the config.nice file as I myself created this using config.nice Wink

Note: I have used config,nice from httpd-2.2.9's compilation, may not work for httpd-1.x or httpd-2.0.x

#!/bin/bash

# Apache Install Script
# Modified version of config.nice

# ------- PARAMETERS REQUIRED -------
# 1st Parameter - Extracted Source code directory

if [ ! $1 ]; then

echo -e "You must pass the first argument as the SOURCE CODE directory\n"

exit 1

fi

SRCDIR=$1

if [ -d $SRCDIR ] && [ $(pwd) != $SRCDIR ]; then

echo -e "Current Working Directory is $(pwd)\n\n"

echo -e "Changing Directory to $SRCDIR\n\n"

cd $SRCDIR &> /dev/null

CD_RETVAL=$?

if [ $CD_RETVAL -ne 0 ]; then

echo -e "Failed to change directory to $SRCDIR\n\n"

exit $CD_RETVAL

fi

fi

# Replacing ./configure from config.nice to $SRCDIR/configure as the configure script is in $SRCDIR
# Parameters for configure taken from config.nice

# configure by default will install in /usr/local/apache2

"$SRCDIR/configure" \
"-C" \
"--build=i686-pc-linux-gnu" \
"--host=i686-pc-linux-gnu" \
"--target=i686-pc-linux-gnu" \
"--enable-mods-shared=authn-file authn-dbm authn-dbd authn-default authn-anon authn-alias authz-host authz-groupfile authz-user authz-dbm authz-owner authz-default auth-basic auth-digest file-cache cache disk-cache mem-cache dbd ext-filter include filter substitute charset-lite deflate log-config log-forensic logio env mime-magic cern-meta expires headers ident usertrack unique-id setenvif version proxy proxy-connect proxy-ftp proxy-http proxy-ajp proxy-balancer ssl mime dav status autoindex asis info cgid cgi suexec dav-fs dav-lock vhost-alias negotiation dir imagemap actions speling userdir rewrite alias" \
"--enable-modules=so" \
"--with-mpm=worker" \
"--with-included-apr" \
"$@"

AUTOCONF_RETVAL=$?

if [ $AUTOCONF_RETVAL -ne 0 ]; then

echo -e "\n\nError\n\n"

exit $AUTOCONF_RETVAL

fi

make -f Makefile

sudo make -f Makefile install

This script will install httpd in /usr/local/apache2

Enjoy! Smile

Bugs, if found, shall be posted in comments and the same for any suggested improvements or modifications Wink

Preventing Bandwidth theft by hotlinked images

Tags:

Apache Logo

One of the biggest advantage of using Apache (httpd) as your webserver that it is extremely customisable. So here is a simple tutorial about how to prevent bandwidth theft from your image site.

This tutorial uses the mod_setenvif module.

Suppose you have a image subdomain say img.yoursite.com

Now, you want to prevent bandwidth theft. So here's a little step, Its working on my subdomain img.itech7.com, still feedback and more ideas would be appriciated.

#.htaccess (or httpd.conf part) of your subdomain 

SetEnvif Referer yoursite.com yoursite_ref


Deny from All


Allow from env=yoursite_ref

 

Syndicate content