19 October 2010

Install Apache 2.2 with mod_proxy module for Tomcat 7.0.2

Installing/building Mod Proxy for integration of Apache with Tomcat
Install mod_proxy from apache source
Installing everything from source as usual results in leaner installation so that's the way I prefer to go on production servers. Also, the stop/start and restart time gives us less down time when not including dynamic shared object modules. So no dynamic modules is a plus even though it's less flexible and has a steeper learning curve.

To enable mod_proxy with necessary modules run the command below:

./configure --prefix=/usr/local/apache2.0 \
--enable-proxy \
--enable-proxy-connect \

Note: the backslash lets you spread out a single command over more than one lines, which improves readability. So after the backslash once you press return the command will not be executed.

If you need to access files using ftp then add --enable-proxy-ftp to you list of modules when executing the above command.

Dynamic vs. Static

./configure --enable-proxy=static will build mod_proxy linked statically into the resulting httpd executable; this is the default if you specify ./configure --enable-proxy. ./configure --enable-proxy=shared is necessary to build the module as a loadable shared library.

Similarly, ./configure --enable-modules=proxy will link mod_proxy statically into the executable, while ./configure --enable-mods-shared=proxy will cause it to be built as a shared library. See the Apache configure documentation for more details.

Apache configure/installation/build from source Help

run the command ./configure --help to get the below output of the options available for configuring apache before building and installing it.

`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX

By default, `make install' will install all the files in
`/usr/local/apache2/bin', `/usr/local/apache2/lib' etc.  You can specify
an installation prefix other than `/usr/local/apache2' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-v4-mapped      Allow IPv6 sockets to handle IPv4 connections
  --enable-exception-hook Enable fatal exception hook
                          Turn on debugging and compile time warnings
  --enable-pie            Build httpd as a Position Independent Executable
                          Space-separated list of modules to enable | "all" |
                          Space-separated list of shared modules to enable |
                          "all" | "most"
  --disable-authn-file    file-based authentication control
  --enable-authn-dbm      DBM-based authentication control
  --enable-authn-anon     anonymous user authentication control
  --enable-authn-dbd      SQL-based authentication control
  --disable-authn-default authentication backstopper
  --enable-authn-alias    auth provider alias
  --disable-authz-host    host-based authorization control
                          'require group' authorization control
  --disable-authz-user    'require user' authorization control
  --enable-authz-dbm      DBM-based authorization control
  --enable-authz-owner    'require file-owner' authorization control
  --enable-authnz-ldap    LDAP based authentication
  --disable-authz-default authorization control backstopper
  --disable-auth-basic    basic authentication
  --enable-auth-digest    RFC2617 Digest authentication
  --enable-isapi          isapi extension support
  --enable-file-cache     File cache
  --enable-cache          dynamic file caching
  --enable-disk-cache     disk caching module
  --enable-mem-cache      memory caching module
  --enable-dbd            Apache DBD Framework
  --enable-bucketeer      buckets manipulation filter
  --enable-dumpio         I/O dump filter
  --enable-echo           ECHO server
  --enable-example        example and demo module
  --enable-case-filter    example uppercase conversion filter
  --enable-case-filter-in example uppercase conversion input filter
  --enable-reqtimeout     Limit time waiting for request from client
  --enable-ext-filter     external filter module
  --disable-include       Server Side Includes
  --disable-filter        Smart Filtering
  --enable-substitute     response content rewrite-like filtering
  --disable-charset-lite  character set translation
  --enable-charset-lite   character set translation
  --enable-deflate        Deflate transfer encoding support
  --enable-ldap           LDAP caching and connection pooling services
  --disable-log-config    logging configuration
  --enable-log-forensic   forensic logging
  --enable-logio          input and output logging
  --disable-env           clearing/setting of ENV vars
  --enable-mime-magic     automagically determining MIME type
  --enable-cern-meta      CERN-type meta files
  --enable-expires        Expires header control
  --enable-headers        HTTP header control
  --enable-ident          RFC 1413 identity check
  --enable-usertrack      user-session tracking
  --enable-unique-id      per-request unique ids
  --disable-setenvif      basing ENV vars on headers
  --disable-version       determining httpd version in config files
  --enable-proxy          Apache proxy module
  --enable-proxy-connect  Apache proxy CONNECT module
  --enable-proxy-ftp      Apache proxy FTP module
  --enable-proxy-http     Apache proxy HTTP module
  --enable-proxy-scgi     Apache proxy SCGI module
  --enable-proxy-ajp      Apache proxy AJP module
  --enable-proxy-balancer Apache proxy BALANCER module
  --enable-ssl            SSL/TLS support (mod_ssl)
  --enable-distcache      Select distcache support in mod_ssl
                          example optional hook exporter
                          example optional hook importer
                          example optional function importer
                          example optional function exporter
  --enable-static-support Build a statically linked version of the support
                          Build a statically linked version of htpasswd
                          Build a statically linked version of htdigest
                          Build a statically linked version of rotatelogs
                          Build a statically linked version of logresolve
  --enable-static-htdbm   Build a statically linked version of htdbm
  --enable-static-ab      Build a statically linked version of ab
                          Build a statically linked version of checkgid
                          Build a statically linked version of htcacheclean
                          Build a statically linked version of httxt2dbm
  --enable-http           HTTP protocol handling
  --disable-mime          mapping of file-extension to MIME
  --enable-dav            WebDAV protocol handling
  --disable-status        process/thread monitoring
  --disable-autoindex     directory listing
  --disable-asis          as-is filetypes
  --enable-info           server information
  --enable-suexec         set uid and gid for spawned processes
  --disable-cgid          CGI scripts
  --enable-cgi            CGI scripts
  --disable-cgi           CGI scripts
  --enable-cgid           CGI scripts
  --enable-dav-fs         DAV provider for the filesystem
  --enable-dav-lock       DAV provider for generic locking
  --enable-vhost-alias    mass virtual hosting module
  --disable-negotiation   content negotiation
  --disable-dir           directory request handling
  --enable-imagemap       server-side imagemaps
  --disable-actions       Action triggering on requests
  --enable-speling        correct common URL misspellings
  --disable-userdir       mapping of requests to user-specific directories
  --disable-alias         mapping of requests to different filesystem parts
  --enable-rewrite        rule based URL manipulation
  --enable-so             DSO capability

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-included-apr     Use bundled copies of APR/APR-Util
  --with-apr=PATH         prefix for installed APR or the full path to
  --with-apr-util=PATH    prefix for installed APU or the full path to
  --with-pcre=PATH        Use external PCRE library
  --with-port=PORT        Port on which to listen (default is 80)
  --with-sslport=SSLPORT  Port on which to securelisten (default is 443)
  --with-z=DIR            use a specific zlib library
  --with-sslc=DIR         RSA SSL-C SSL/TLS toolkit
  --with-ssl=DIR          OpenSSL SSL/TLS toolkit
  --with-mpm=MPM          Choose the process model for Apache to use.
                          Enable module-file in the modules/
  --with-program-name     alternate executable name
  --with-suexec-bin       Path to suexec binary
  --with-suexec-caller    User allowed to call SuExec
  --with-suexec-userdir   User subdirectory
  --with-suexec-docroot   SuExec root directory
  --with-suexec-uidmin    Minimal allowed UID
  --with-suexec-gidmin    Minimal allowed GID
  --with-suexec-logfile   Set the logfile
  --with-suexec-safepath  Set the safepath
  --with-suexec-umask     umask for suexec'd process

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L if you have libraries in a
              nonstandard directory 
  LIBS        libraries to pass to the linker, e.g. -l
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I if
              you have headers in a nonstandard directory 
  CPP         C preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

28 September 2010

Manual Apache HTTPd 2.2 installation on Ubuntu Linux

1. get sources
wget http://mirror.ox.ac.uk/sites/rsync.apache.org//httpd/httpd-2.2.16.tar.gz

2. extract sources
tar xzfv httpd-2.2.16.tar.gz 

3. Configure various aspects of apache (you can choose where apache shall be installed and run from. These paths will be written and compiled into the binaries so this step is important).
more on this at: 

I don't want to change the default configurations so I just run:

4. To build apache:

5. To install(copy the files to the right places)
sudo make install

since I didn't configure the installation path, the default value (/usr/local/apache2) was used to install apache in.

6. Start the Apache server program

To test the server, first I go to the correct directory:
cd /usr/local/apache2/bin

then run the following command:
sudo ./apachectl -k start

7. Associate Apache webserver with a domain name
I get the following error:
httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName

The reason for this error is that a domain name is not associated with this web server so to overcome this problem, I need to edit httpd.conf:
vi /user/local/apache2/conf/httpd.conf

change the line 
#ServerName www.example.com:80

To something like (assuming you own the domain radep.com and it points at this machine):
ServerName radep.com:80

8. Restart server
then restart the server(assuming you are in /user/local/apache2/bin):
sudo ./apachectl -k restart

9. Test it from your browser
Now you can use your browser to visit radep.com
lynx radep.com

you should see the text "It works!" which is the text that is contained in the file /usr/local/apache2/htdocs/index.html

If you need to go deeper into this process check out:

or just ask me.

22 September 2010

Manually Installing Tomcat 7 on Ubuntu

Installing Tomcat 7 on Ubuntu 9.10
I prefer the manual process of installing and upgrading software on a live server as it is less likely to break things and the reversal process is easier as well. So that's the way I choose to go;

To find out which version of Ubuntu you have run the following command:
more /etc/lsb-release

On my machine the output is:

If you want to find the kernel details run (uname -a).
To find the linux distro you can also run (cat /etc/issue).

Install Java
To check if Java is installed run:

dpkg --get-selections | grep sun-java

which should output:
sun-java6-bin                                   install
sun-java6-jdk                                   install
sun-java6-jre                                   install

running the command (java -version) should give you the following output assuming the "java" executable is on your $PATH variable.

java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)

If you don't have Java installed the easiest way is run this command (sudo apt-get install sun-java6-jdk)

Tomcat 7 Installation
Download Tomcat
It's recommended to use your web browser to download Tomcat but if you know exactly which version you want and you know the url then wget would suffice.

wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.2-beta/bin/apache-tomcat-7.0.2.tar.gz

Verify download
Calculate the md5 checksum using the command (md5sum apache-tomcat-7.0.2.tar.gz) it should output:

43b5ba6aec55dd9a30957e035d0aac5f apache-tomcat-7.0.2.tar.gz

The above is just to make sure your download wasn't corrupted.

Extract Tomcat 7.0.2 Beta
To extract the content of the archive run the following command (tar xvzf apache-tomcat-7.0.2.tar.gz)

Move the tomcat folder to a location which it will sit and serve webapps. I moved it to /usr/local/tomcat, but am not sure what the best place is, maybe someone could let me know?

sudo mv apache-tomcat-7.0.2 /usr/local/tomcat/

Set JAVA_HOME variable

To check if the $JAVA_HOME environment variable has been set or not run the following command (echo $JAVA_HOME) which should output:


Tomcat requires setting the JAVA_HOME variable. You can set it in .bashrc or startup.sh. Again not sure what the best place is.

To place it in your .bashrc file.

vi ~/.bashrc

Add the following line:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

Logout of the shell for the change to take effect.

Startup Tomcat 7.0.2 Beta
Start tomcat by executing "startup.sh" script in the tomcat/bin folder.

Automatic Starting at boot
For a live server you need to make tomcat automatically start at boot up just in case you need to restart the server; Add a start/stop script to init.d script startup directory.

sudo vi /etc/init.d/tomcat

Paste in the following:

# Tomcat auto-start
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
sh /usr/local/tomcat/bin/startup.sh
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
exit 0

Make the script executable:

sudo chmod 755 /etc/init.d/tomcat

Link the start/stop script to the startup folders with a symbolic link.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

You might also want to put some symbolic links in rc0 and rc6 directories.

Or alternatively let ubuntu create the symbolic links automatically by running this command:

sudo update-rc.d tomcat defaults

which outputs:
update-rc.d: warning: /etc/init.d/tomcat missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/tomcat ...
   /etc/rc0.d/K20tomcat -> ../init.d/tomcat
   /etc/rc1.d/K20tomcat -> ../init.d/tomcat
   /etc/rc6.d/K20tomcat -> ../init.d/tomcat
   /etc/rc2.d/S20tomcat -> ../init.d/tomcat
   /etc/rc3.d/S20tomcat -> ../init.d/tomcat
   /etc/rc4.d/S20tomcat -> ../init.d/tomcat
   /etc/rc5.d/S20tomcat -> ../init.d/tomcat

The difference is that it makes sure tomcat start at each run level however in practical terms if runlevel 2 is reached tomcat will start so run level 3,4 and 5 will be ignored as tomcat would already be running from when run level 2 was reached. The nice thing about this automatic install of symbolic links is that it is easy to add/remove them. Also they add the "stop" script at run level 0 and 6 which should be done!