Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

APB v1.0 (subject to better name change)

by hacker (Priest)
on Oct 19, 2003 at 17:57 UTC ( [id://300406]=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info David A. Desrosiers, aka hacker
desrod at gnu-designs dot com
Description:

After rebuilding Apache hundreds of times on just as many boxes, each with their own tweaks and configuration options with mod_php, mod_perl, mod_ssl, MySQL and so on, I was tiring of doing it all manually. Normally you have to do the following:

  • Fetching the tarballs
  • Verifying the md5sums
  • Unpacking the tree
  • Configuring the tree
  • Building the tree
  • Testing the build
  • Installing the tree
  • ...etc.
I tried using Apache Toolbox several times, but it has quite a few flaws in design:
  • You can't instruct it to use the system-installed MySQL headers and libraries
  • It insists on building its own PHP from scratch
  • Many other libraries (gd, t1, xpm) all get built by ApacheToolbox and installed in /usr/local
  • ...and so on. Not clean, not scalable. Too intrusive to strictly-controlled systems.

Well, now I don't have to!

With this script, all you have to type is 'build', and it will fetch, verify, unpack, configure, build, test, and install Apache, PHP, mm (shared memory), mod_ssl, mod_perl, and so on for you, in your target prefix, all in one shot. You just run 'build' and it does the rest for you as DSO, with just a 14k httpd server daemon when it completes (on my test boxes).

For those wondering what this has to do with Perl, I rely on mod_perl heavily for my work, and rebuilding Apache with each new release of mod_perl, Perl, mod_ssl, and so on gets tedious. This removes that tedium, so I can get back to work, faster, with less babysitting of the code.

There are three files: build (the main script), functions (some helper routines), and source.md5 (md5sums of the target tarballs). You'll need all three in your work directory to properly run this.

Hopefully PerlMonk's wrapping won't kill this too much.

Suggestions and patches are welcome, of course.

build
##################
#
# You will need the following perl modules installed first:
#
#    MIME::Base64
#    URI
#    HTML::Parser
#    Digest::MD5
#    Bundle::libnet
#    LWP 
# 
##########################################################
#
# Sources:
# 
# Apache....: ftp://apache.mirrors.pair.com/httpd/apache_1.3.28.tar.gz
# PHP.......: http://fi.php.net/distributions/php-4.3.3.tar.gz
# MM........: ftp://ftp.ossp.org/pkg/lib/mm/mm-1.3.0.tar.gz
# mod-ssl...: http://www.modssl.org/source/mod_ssl-2.8.15-1.3.28.tar.g
+z
# mod-perl..: http://perl.apache.org/dist/mod_perl-1.29.tar.gz
#
######################################################################
+#######
APACHE=apache_1.3.28
APURL=ftp://apache.mirrors.pair.com/httpd/$APACHE.tar.gz

# Prefix where Apache is going to be installed
AP_PREFIX=/usr/local/apache

MM=mm-1.3.0
MMURL=ftp://ftp.ossp.org/pkg/lib/mm/$MM.tar.gz

PHP=php-4.3.3
PHPURL=http://fi.php.net/distributions/php-4.3.3.tar.gz

MODSSL=mod_ssl-2.8.15-1.3.28
MODSSLURL=http://www.modssl.org/source/$MODSSL.tar.gz

MODPERL=mod_perl-1.29
MODPERLURL=http://www.ibiblio.org/pub/mirrors/apache/perl/$MODPERL.tar
+.gz

##########################################################
#
# Startup stuff
#
##########################################################
# Directory of tarballs
THISDIR=`pwd`
WORKROOT=/tmp/apache
WORKDIR=$WORKROOT/work
MD5FILE=$THISDIR/source.md5

source functions

wherebe MD5SUM md5sum
wherebe TAR tar
wherebe GUNZIP gunzip
wherebe GREP grep
wherebe WGET wget
wherebe MKDIR mkdir
wherebe RM rm
wherebe MAKE make
wherebe PERL perl
wherebe SUDO sudo

echo ""

if [ ! -d $WORKROOT ]; then
   echo "FATAL ERROR: WORKROOT ($WORKROOT) did not exist, exiting now.
+."
   echo ""
   echo "Please make sure to set the WORKROOT value properly in the sc
+ript The other"
   echo "necessary directories will be created automagically if they d
+o not already"
   echo "exist. All of the building will be done inside the directory 
+you set here."
   echo "" 
   exit
fi

if [ ! -d $WORKDIR ]; then
   echo "  ERROR: WORKDIR ($WORKDIR) did not exist.. creating now."
   echo ""
   $MKDIR $WORKDIR
fi

##########################################################
#
# Fetch, unpack, and test everything
#
##########################################################
URLS=($MMURL $MODSSLURL $APURL $PHPURL $MODPERLURL)
BINS=($MM $MODSSL $APACHE $PHP $MODPERL)

for b in ${BINS[@]}; do 
    if [ ! -f $WORKROOT/$b.tar.gz ]; then
        for u in ${URLS[@]}; do
            echo "  Source not found. fetching from $u.."; 
            $WGET -c -q --progress=dot $u; 
        done;
    else
        md5check $b.tar.gz
    fi
done
echo ""

##########################################################
#
# Shared Memory Allocation
#
##########################################################
cd $WORKDIR/$MM
if [ -f $WORKDIR/$MM/config.status ]; then
    make distclean
fi
./configure --disable-shared

make
make test
sudo make install

##########################################################
#
# mod_ssl
#
##########################################################
cd $WORKDIR/$MODSSL
if [ -f $WORKDIR/$MM/config.status ]; then
    make distclean
fi

./configure                     \
--with-apache=../$APACHE        \
--with-ssl=/usr                 \
--with-mm=../$MM                \
--enable-shared=ssl


##########################################################
#
# Apache
#
##########################################################
cd $WORKDIR/$APACHE

if [ -f $WORKDIR/$APACHE/config.status ]; then
        make distclean
fi

# Fix for building on Linux, which has no ndbm.h
$PERL -pi -e 's,ndbm.h,gdbm-ndbm.h,g' $WORKDIR/$APACHE/src/modules/sta
+ndard/mod_rewrite.h

SSL_BASE=/usr\
LIBS=-lpthread                  \
EAPI_MM=../$MM                  \
./configure                     \
--prefix=$AP_PREFIX             \
--enable-module=ssl             \
--enable-module=env             \
--enable-shared=env             \
--enable-module=log_config      \
--enable-shared=log_config      \
--enable-module=log_agent       \
--enable-shared=log_agent       \
--enable-module=log_referer     \
--enable-shared=log_referer     \
--enable-module=mime            \
--enable-shared=mime            \
--enable-module=negotiation     \
--enable-shared=negotiation     \
--enable-module=status          \
--enable-shared=status          \
--enable-module=info            \
--enable-shared=info            \
--enable-module=include         \
--enable-shared=include         \
--enable-module=autoindex       \
--enable-shared=autoindex       \
--enable-module=dir             \
--enable-shared=dir             \
--enable-module=cgi             \
--enable-shared=cgi             \
--enable-module=asis            \
--enable-shared=asis            \
--enable-module=imap            \
--enable-shared=imap            \
--enable-module=actions         \
--enable-shared=actions         \
--enable-module=userdir         \
--enable-shared=userdir         \
--enable-module=alias           \
--enable-shared=alias           \
--enable-module=rewrite         \
--enable-shared=rewrite         \
--enable-module=access          \
--enable-shared=access          \
--enable-module=auth            \
--enable-shared=auth            \
--enable-module=auth_anon       \
--enable-shared=auth_anon       \
--enable-module=auth_db         \
--enable-shared=auth_db         \
--enable-module=digest          \
--enable-shared=digest          \
--enable-module=proxy           \
--enable-shared=proxy           \
--enable-module=expires         \
--enable-shared=expires         \
--enable-module=headers         \
--enable-shared=headers         \
--enable-module=usertrack       \
--enable-shared=usertrack       \
--enable-module=setenvif        \
--enable-shared=setenvif        \
--enable-shared=ssl             \
--enable-rule=SHARED_CORE       \
--enable-rule=SHARED_CHAIN      \
--enable-module=so

make
make test
# just use the defaults for now
# make certificate 
sudo make install

##########################################################
#
# compile php as DSO 
#
##########################################################
cd $WORKDIR/$PHP

if [ -f $WORKDIR/$PHP/config.status ]; then
        make distclean
fi

./configure                     \
--with-apxs=$AP_PREFIX/bin/apxs \
--disable-debug                 \
--enable-apc                    \
--enable-bcmath                 \
--enable-exif                   \
--enable-ftp                    \
--enable-gd-native-ttf          \
--enable-inline-optimization    \
--enable-libgcc                 \
--enable-magic-quotes           \
--enable-memory-limit           \
--enable-mysql                  \
--enable-sysvshm                \
--enable-track-vars             \
--enable-trans-sid              \
--enable-wddx                   \
--with-calendar=shared          \
--with-freetype-dir=/usr        \
--with-gd=/usr                  \
--with-gettext=/usr             \
--with-imap=/usr                \
--with-jpeg-dir=/usr            \
--with-kerberos                 \
--with-mysql=/usr               \
--with-openssl=/usr             \
--with-png-dir=/usr             \
--with-t1lib=/usr               \
--with-ttf                      \
--with-zlib                     \
--with-zlib-dir=/usr
make
# make test
sudo make install
cp php.ini-dist /usr/local/lib/php.ini 

##########################################################
#
# compile mod_perl DSO
#
##########################################################
cd $WORKDIR/$MODPERL

if [ -f $WORKDIR/$MODPERL/Makefile ]; then
        make distclean
fi

perl Makefile.PL                \
USE_APXS=1                      \
WITH_APXS=$AP_PREFIX/bin/apxs   \
EVERYTHING=1
make
sudo make install

functions
md5check() {

   MD5_TMP=`$GREP $1 ${MD5FILE}`
   BINDESC=`echo $MD5_TMP | awk '{print $2}'`

   echo -n "  Testing $1 for corruption... "
   if [ ! -z "$MD5SUM" ]; then

      if [ ! -z "$MD5_TMP" ]; then
         echo "$MD5_TMP" | awk '{print $1, "", $2}' | $MD5SUM -c
      fi
   fi

   if [ ! -z "$MD5_TMP" ]; then
      $GUNZIP -t $1 &>/dev/null
      if [ $? -eq 1 ]; then
         echo "  MD5 check failed, corrupt!"
      else
         echo -n "  MD5 check passed.. "
      fi
   fi

   echo -n "unpacking.. "
   $TAR zxvf $1 -C $WORKDIR &>/dev/null
   echo "done!"
}

wherebe() {
   echo -n "Checking for $2..."

   test -x $2 && export "$1"="$2"
   test -x /bin/$2 && export "$1"="/bin/$2"
   test -x /sbin/$2 && export "$1"="/sbin/$2"
   test -x /usr/bin/$2 && export "$1"="/usr/bin/$2"
   test -x /usr/sbin/$2 && export "$1"="/usr/sbin/$2"
   test -x /usr/local/bin/$2 && export "$1"="/usr/local/bin/$2"
   test -x /usr/local/sbin/$2 && export "$1"="/usr/local/sbin/$2"
   test -x $LOCAL_PATH/bin/$2 && export "$1"="$LOCAL_PATH/bin/$2"

   if [ `echo echo '$'$1'' |  /bin/sh` ]; then
      echo "`echo echo '$'$1'' |  /bin/sh`"
   else
      echo " FAILED"
      if [ $3 ]; then
         echo " -required external resourced missing"
         exit 1
      else
         echo
      fi
      exit
   fi
}

pause() {
   COUNT=$1
   for i in `seq 0 $COUNT`; do
      sleep 1;
      echo -n ".";
   done;
   echo ""
}

source.md5
2cdece7b4881d541e072de6a2b65db77  apache_1.3.28.tar.gz
fe3fede4115354155fc6185522f7c6b2  php-4.3.3.tar.gz
4bf43697983bf585905ee9a14b00dc32  mm-1.3.0.tar.gz
0f37d6efd51128f696000d73624f5aff  mod_ssl-2.8.15-1.3.28.tar.gz
1491931790509b9af06fc037d02b0e7a  mod_perl-1.29.tar.gz
Replies are listed 'Best First'.
Re: APB v1.0 (subject to better name change)
by Anonymous Monk on Oct 19, 2003 at 19:38 UTC
    I can see what it has to do with perl, but why is it not written in perl?
      Good point. When I have some time, I'll do that next. I was actually converting a script I wrote to build an ARM Canadian Cross over and realized I could repurpose it for this Apache need.

      I'll see if I can do it entirely in core on perl 5.003, and convert it to Perl if that works. If it can't be done in core on that version of Perl, I'll stick to the bash version.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://300406]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-03-28 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found