apache2/install_httpd-2.2.sh

620 lines
17 KiB
Bash
Executable File

#!/bin/bash
# httpd Apapche Webserver
#
## - CHANGE PARAMETER TO PASS YXOUR SITUATION--------
## -
VERSION=2.2.24
PHP_VERSION=5.3.26
RUBY_VERSION=1.8.6-p420
#PREFIX=/usr/local/httpd-${VERSION}
#PREFIX=/usr/local/httpd-${VERSION}_php-${PHP_VERSION}
PREFIX=/usr/local/httpd-${VERSION}_ruby-${RUBY_VERSION}
## - substitude path "/usr/local/httpd-$VERSION" to "/usr/local/apache2"
## - in apache configuration files ?
## -
subst_base_path=false
HTTPD_GROUP=www-data
HTTPD_USER=www-data
SERVER_NAME=`hostname -f`
SERVER_ADMIN="admin@warenform.de"
APACHE_LOG_DIR=/var/log/apache
DIRECTORY_INDEX="index.html index.htm index.php"
# : ${_arch:=i686}
# : ${_arch:=athlon}
: ${_arch:=k8} ## --> x86-64 instructionset
#_cflags="-O2 -march=$_arch "
## - DO NOT CHANGE ----------------------------------
## -
_httpdconf=${PREFIX}/conf/httpd.conf
_rel_confextra_path=conf/extra
_backup_suffix=".BAK"
_srcdir=/usr/local/src/apache2
_logdir=${_srcdir}/log_`basename $PREFIX`_build
_pwd=`pwd`
_builddir=${_srcdir}/`basename $PREFIX`
## -- some functions -- ##
echo_ok() {
echo -e " [ \033[32mok\033[m ]"
}
echo_failed(){
echo -e " [ \033[1;31mfailed\033[m ]"
}
echo_skipped(){
echo -e " [ \033[1;33mskipped\033[m ]"
}
## --------------------------------------------------
[ -d $_logdir ] || mkdir -p $_logdir > /dev/null 2>&1
## - Generate code for a 64-bit environment ?
## -
[ "athlon64" = "$_arch" -o "k8" = "$_arch" -o "opteron" = "$_arch" -o "athlon-fx" = "$_arch" ] && _cflags="$_cflags -m64"
cd $_srcdir
gunzip < ${_srcdir}/httpd-$VERSION.tar.gz | tar -xpf -
chown -R root.root httpd-$VERSION
mv httpd-$VERSION ${_builddir}
cd $_builddir
## - LDFLAGS="-s" --> Remove all symbol table and relocation information from the executable.
## -
echo -e "\n\tgoing to configure.."
echo -e "\t(see ${_logdir}/httpd-configure.log for more details)"
## F77="/usr/bin/g77-3.4" \
## CXXCPP="/usr/bin/g++-3.4 -E" \
## CC="/usr/bin/gcc-3.4" \
## CXX="/usr/bin/g++-3.4" \
## CPP="/usr/bin/cpp-3.4" \
##CFLAGS="$_cflags" \
LDFLAGS="-s" \
./configure --prefix=$PREFIX \
--with-included-apr \
--enable-ssl \
--enable-info \
--enable-proxy \
--enable-proxy-connect \
--enable-proxy-ftp \
--enable-proxy-http \
--enable-proxy-balancer \
--enable-deflate \
--enable-rewrite \
--enable-cache \
--enable-mem-cache \
--enable-dav \
--enable-headers \
--enable-so \
--with-dbm=db4 \
--enable-expires \
--with-berkeley-db=/usr \
> ${_logdir}/httpd-configure.log 2>&1 || exit 1
## --enable-authz-dbm \
## --enable-authn-dbm \
## --with-berkeley-db=/usr/local/BerkeleyDB.4.4.20 \
## --target=i686-pc-linux-gnu \
## --build=i686-pc-linux-gnu | tee ../httpd-$VERSION-install.log
## --disable-nls \
echo -e "\n\tgoing to compile.."
echo -e "\t(see ${_logdir}/httpd-make.log for more details)"
make > ${_logdir}/httpd-make.log 2>&1 || exit 1
echo -e "\n\tgoing to install.."
echo -e "\t(see ${_logdir}/httpd-make_install.log for more details)"
make install > ${_logdir}/httpd-make_install.log 2>&1 || exit 1
## - do some post-installatin tasks..
## -
echo
echo -e "\t-----------------------------"
echo -e "\t-- post installation tasks --"
echo -e "\t-----------------------------"
if [ -f $_httpdconf ];then
cp $_httpdconf $_httpdconf.ORIG
if $subst_base_path ; then
## - set BasePath to httpd.conf
## -
echo ""
echo -e "\tsubstitute \"$PREFIX\" with \"/usr/local/apache2\""
echo -e -n "\tin file $_httpdconf.."
sed -i$_backup_suffix -e "s#$PREFIX#/usr/local/apache2#g" $_httpdconf
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
## - set BasePath to all conf files in conf/extra
## -
if [ -d $PREFIX/$_rel_confextra_path ]; then
cd $PREFIX/$_rel_confextra_path
_files=`ls *.conf`
for _file in $_files ;do
echo ""
echo -e "\tsubstitute \"$PREFIX\" with \"/usr/local/apache2\""
echo -n -e "\t in file $_file.."
sed -i$_backup_suffix -e "s#$PREFIX#/usr/local/apache2#g" $_file
if [ "0" = $? ]; then
echo_ok
rm -f $_file$_backup_suffix
else
echo_failed
fi
done
fi
fi
## - set User
echo ""
echo -n -e "\tset User to \"$HTTPD_USER\".."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*User ).*)$&## \1\n\2${HTTPD_USER}&g" \
$_httpdconf
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
## - set Group
echo ""
echo -n -e "\tset Group to \"$HTTPD_GROUP\".."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*Group ).*)$&## \1\n\2${HTTPD_GROUP}&g" \
$_httpdconf
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
## - set ServerAdmin
## -
echo ""
echo -n -e "\tset ServerAdmin to \"$SERVER_ADMIN\".."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*ServerAdmin ).*)$&## \1\n\2${SERVER_ADMIN}&g" \
$_httpdconf
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
## - set ServerName
## -
echo ""
echo -n -e "\tset ServerName to \"$SERVER_NAME\".."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*)#?(ServerName ).*)$&## \1\n\2\3${SERVER_NAME}&g" \
$_httpdconf
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
## - set DirectoryIndex
## -
echo ""
echo -n -e "\tset DirectoryIndex to \"$DIRECTORY_INDEX\".."
sed -i$_backup_suffix -r \
-e "s&^([ ^t]*)(DirectoryIndex )(.*)$&\1## \2\3\n\1\2${DIRECTORY_INDEX}&g" \
$_httpdconf
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
## - set log-directory and concerning entries
## -
echo ""
echo -n -e "\tset log-directory to $APACHE_LOG_DIR\".."
mkdir -p $APACHE_LOG_DIR > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
echo ""
echo -n -e "\tset ErrorLog.."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*ErrorLog ).*)$&## \1\n\2${APACHE_LOG_DIR}/error_log&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
echo ""
echo -n -e "\tset CustomLog.."
sed -i$_backup_suffix -r \
-e "s&^([ ^t]*)(CustomLog )(.*)$&\1## \2\3\n\1\2${APACHE_LOG_DIR}/access_log combined&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
rm -f $_httpdconf$_backup_suffix
else
echo_failed
fi
else
echo_failed
fi
else
echo_failed
fi
fi
mkdir -p $PREFIX/conf/vhosts
cat <<EOF >>$_httpdconf
ServerSignature Off
ServerTokens ProductOnly
include conf/vhosts/*.conf
EOF
## - Listen on certain ip(s) ?
## -
_ips=""
_substitute=""
_substitute_ssl=""
echo ""
echo "if you want the webserver to listen on certain ip(s)"
echo "put a blank seperatet list an type <return>"
echo "otherwise leaf blank and type <return>"
echo ""
echo -n "put in ip(s): "
read _ips
if [ ! "X" = "X$_ips" ]; then
echo ""
echo -e "\tInsert Listen directive(s) - Port 80 - for ip-address(es)"
echo -n -e "\t\"$_ips\" in file $_httpdconf.."
for _ip in $_ips ; do
_substitute="Listen $_ip:80\n$_substitute"
_substitute_ssl="Listen $_ip:443\n$_substitute_ssl"
done
sed -i$_backup_suffix -r -e "s#^(Listen 80.*)#\#\# \1\n$_substitute#g" $_httpdconf > /dev/null 2>&1
if [ "0" = "$?" ];then
echo_ok
rm $_httpdconf$_backup_suffix
else
echo_failed
fi
fi
## - enable ssl ?
## -
_ssl=""
echo
echo -n "do you want to enable ssl conections for the given ip(s) [y/n]: "
read _ssl
if [ "y" = "$_ssl" -o "Y" = "$_ssl" -o "Yes" = "$_ssl" -o "yes" = "$_ssl" ];then
_notice=""
## - copy certification files if present..
if [ -f $_srcdir/server.crt -a -f $_srcdir/server.key ];then
cp $_srcdir/server.crt $PREFIX/conf/
cp $_srcdir/server.key $PREFIX/conf/
else
_notice="CERTIFICATES NOT PRESENT"
fi
## - include httpd-ssl.conf
_file=httpd-ssl.conf
if [ -f ${PREFIX}/${_rel_confextra_path}/${_file} ]; then
echo
echo -n -e "\tinclude file \"$_file\".."
sed -i$_backup_suffix -r \
-e "s&[ ^t]*#([ ^t]*#*[ ^t]*)*(Include $_rel_confextra_path/$_file).*$&\2&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = "$?" ];then
rm $_httpdconf$_backup_suffix
echo_ok
if [ ! "X" = "X$_notice" ];then
echo ""
echo -e "\t[ \033[1;33m$_notice\033[m ]: \033[33m"
echo -e "\tSSL Connections are enabled but no (default) certificates"
echo -e "\tare present !! So the webserver will not start. "
echo -e "\tPut your certificate named as \"server.crt\" and the concerning"
echo -e "\tkey named as \"server.key\" into directory $PREFIX/conf/"
echo ""
echo -e "\tAlternatively you can comment in the the line containing"
echo -e "\t\"Include conf/extra/http-ssl.conf\" directive for now"
echo -e "\tto get a running webserver - without SSL enabled.\033[m"
fi
else
echo_failed
fi
fi
## - if given, setting the ip(s) to Listen
echo ""
echo -e "\tInsert Listen directive(s) - Port 443 - for ip-address(es)"
echo -n -e "\t\"$_ips\" in file ${_file}.."
if [ ! "X" = "X$_ips" ]; then
sed -i$_backup_suffix -r \
-e "s#^(Listen 443.*)#\#\# \1\n$_substitute_ssl#g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = "$?" ];then
echo_ok
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
else
echo_failed
fi
fi
## - set ServerName
## -
echo ""
echo -n -e "\tin $_file set ServerAdmin.."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*ServerName ).*)$&## \1\n\2${SERVER_NAME}&g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
else
echo_failed
fi
## - set ServerAdmin
## -
echo ""
echo -n -e "\tin $_file set ServerAdmin.."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*ServerAdmin ).*)$&## \1\n\2${SERVER_ADMIN}&g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
else
echo_failed
fi
## - set log entries
## -
echo ""
echo -n -e "\tin $_file set ErrorLog.."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*ErrorLog ).*)$&## \1\n\2${APACHE_LOG_DIR}/error_log&g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
else
echo_failed
fi
echo -n -e "\tin $_file set TransferLog.."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*TransferLog ).*)$&## \1\n\2${APACHE_LOG_DIR}/access_log&g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
else
echo_failed
fi
echo -n -e "\tin $_file set CustomLog.."
sed -i$_backup_suffix -r \
-e "s&^(([ ^t]*CustomLog ).*)$&## \1\n\2${APACHE_LOG_DIR}/ssl_request_log \\\&g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = $? ]; then
echo_ok
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
else
echo_failed
fi
fi
## - include conf files from conf/extra
## -
_file=httpd-default.conf
if [ -f ${PREFIX}/${_rel_confextra_path}/${_file} ];then
echo
echo -n -e "\tinclude file \"$_file\".."
sed -i$_backup_suffix -r \
-e "s&[ ^t]*#([ ^t]*#*[ ^t]*)*(Include $_rel_confextra_path/$_file).*$&\2&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = "$?" ];then
rm $_httpdconf$_backup_suffix
echo_ok
else
echo_failed
fi
fi
_file=httpd-info.conf
if [ -f ${PREFIX}/${_rel_confextra_path}/${_file} ];then
echo
echo -n -e "\tinclude file \"$_file\".."
sed -i$_backup_suffix -r \
-e "s&[ ^t]*#([ ^t]*#*[ ^t]*)*(Include $_rel_confextra_path/$_file).*$&\2&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = "$?" ];then
rm $_httpdconf$_backup_suffix
echo_ok
else
echo_failed
fi
echo
echo -e "\tsetup \"$_file\" to allow urls \"server-status\""
echo -n -e "\tand server-info from localhost.."
_localhost="127.0.0.0/8"
#[ "X" != "X$_ips" ] && _localhost="$_localhost $_ips"
sed -i$_backup_suffix -r \
-e "s&^([ ^t]*Allow[ ^t]?from).*$&\1 $_localhost&g" \
${PREFIX}/${_rel_confextra_path}/${_file} > /dev/null 2>&1
if [ "0" = "$?" ];then
rm ${PREFIX}/${_rel_confextra_path}/${_file}$_backup_suffix
echo_ok
else
echo_failed
fi
fi
_file=httpd-languages.conf
if [ -f ${PREFIX}/${_rel_confextra_path}/${_file} ];then
echo
echo -n -e "\tinclude file \"$_file\".."
sed -i$_backup_suffix -r \
-e "s&[ ^t]*#([ ^t]*#*[ ^t]*)*(Include $_rel_confextra_path/$_file).*$&\2&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = "$?" ];then
rm $_httpdconf$_backup_suffix
echo_ok
else
echo_failed
fi
fi
_file=httpd-multilang-errordoc.conf
if [ -f ${PREFIX}/${_rel_confextra_path}/${_file} ];then
echo
echo -n -e "\tinclude file \"$_file\".."
sed -i$_backup_suffix -r \
-e "s&[ ^t]*#([ ^t]*#*[ ^t]*)*(Include $_rel_confextra_path/$_file).*$&\2&g" \
$_httpdconf > /dev/null 2>&1
if [ "0" = "$?" ];then
rm $_httpdconf$_backup_suffix
echo_ok
else
echo_failed
fi
## - Set "LanguagePriority"
sed -i -r -e "s/^(\s*)(LanguagePriority.*)de\ *(.*)$/\1\2\3/g" ${PREFIX}/${_rel_confextra_path}/${_file}
sed -i -r -e "s/^(\s*)(LanguagePriority)(.*)$/\1\2 de\3/g" ${PREFIX}/${_rel_confextra_path}/${_file}
fi
_set_link=""
echo
echo -n "do you want to set symlink /usr/local/apache2 -> `basename $PREFIX` ? [y/n]: "
read _set_link
if [ "y" = "$_set_link" -o "Y" = "$_set_link" -o "Yes" = "$_set_link" -o "yes" = "$_set_link" ];then
if [ -L /usr/local/apache2 ];then
rm -f /usr/local/apache2
fi
ln -s `basename $PREFIX` /usr/local/apache2
fi
_set_link=""
echo
echo -n "do you want to set symlink /etc/init.d/apache2 -> $PREFIX/bin/apachectl ? [y/n]: "
read _set_link
if [ "y" = "$_set_link" -o "Y" = "$_set_link" -o "Yes" = "$_set_link" -o "yes" = "$_set_link" ];then
if [ -L /etc/init.d/apache2 ];then
rm -f /etc/init.d/apache2
fi
ln -s $PREFIX/bin/apachectl /etc/init.d/apache2 > /dev/null 2>&1
fi
## mkdir $PREFIX/conf/{ssl.crt,ssl.key}
## cp $_srcdir/server.crt $PREFIX/conf/ssl.crt
## cp $_srcdir/server.key $PREFIX/conf/ssl.key
## - special for debian. set manpath entries
## -
if [ -f /etc/manpath.config ];then
if ! grep /usr/local/apache2/man /etc/manpath.config > /dev/null 2<&1 ; then
echo >> /etc/manpath.config
echo "MANDATORY_MANPATH /usr/local/apache2/man /var/cache/man" >> /etc/manpath.config
echo "MANPATH_MAP /usr/local/apache2/bin /usr/local/apache2/man" >> /etc/manpath.config
echo "MANDB_MAP /usr/local/apache2/man /var/cache/man" >> /etc/manpath.config
fi
elif [ -f /etc/man.conf];then
if ! grep /opt/apache2/man /etc/man.conf > /dev/null 2<&1 ; then
echo >> /etc/man.conf
echo "MANPATH /opt/apache2/man /var/cache/man" >> /etc/man.conf
echo "MANPATH_MAP /opt/apache2/bin /opt/apache2/man" >> /etc/man.conf
fi
fi
echo ""
echo -n -e "\tConfigure logrotation.."
if [ ! -f "/etc/logrotate.d/apache2" ]; then
cat <<EOF > /etc/logrotate.d/apache2
/var/log/apache2/*log
/var/log/apache2/*error
/var/www/*/logs/*log
/var/www/*/logs/*error {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 644 root adm
sharedscripts
postrotate
chown ${HTTPD_USER}:${HTTPD_GROUP} /var/www/*/logs/php_errors.log
chown ${HTTPD_USER}:${HTTPD_GROUP} /var/log/apache2/php_errors.log
APACHECTL="\$(which apachectl)"
if [[ -z "\$APACHECTL" ]] ; then
echo "Prog 'apachectl' not found!"
else
\$APACHECTL graceful > /dev/null
fi
endscript
}
EOF
if [ "$?" = "0" ]; then
echo_ok
else
echo_failed
fi
else
echo_skipped
fi
## - Add /usr/local/apache2/bin to the systems PATH variable
## -
_checkdir=`dirname $PREFIX`/apache2/bin
if [ -f /etc/profile ]; then
if ! grep -e "$_checkdir" /etc/profile > /dev/null 2<&1 ; then
perl -i -n -p -e "s#^([ ]*export[ ]*PATH.*$)#check_dir=$_checkdir\nif [ -d \"\\\$check_dir\" ];then\n PATH=\\\${check_dir}:\\\$PATH\nfi\n\n\1#" /etc/profile > /dev/null 2<&1
fi
fi
cd $pwd
echo
exit 0