Archive for July, 2013

Php source code installation

Pre-requisite:

yum install libxml2-devel

yum install libcurl

Curl can be installed with either rpm or source code

For seource code installation of curl:

Download curl:

wget http://curl.haxx.se/download/curl-7.31.0.tar.gz

Extract:

tar -xvzf curl-7.31.0.tar.gz

Now configure with:

./configure –prefix=/usr/local/curl

Php configuration:

Download php source from

wget http://in1.php.net/get/php-5.5.1.tar.gz/from/this/mirror

Extract this

tar xvzf php-5.5.1.tar.gz

Now configuration php with:

./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-mysql –with-mysqli –enable-pdo –with-pdo-mysql –with-gd –with-pear –with-curl=/usr/local/curl –with-openssl –enable-json –enable-soap –with-config-file-path=/usr/local/php/lib

make

make install

Check the php version with

/usr/local/php/bin/php -v

Test the php configuration with php info page

Create a file with index.php at document root path which is set at httpd.conf file.

Add below code to index.php file

<php?

Phpinfo();

php?>

If phpinfo page has not been shown then add below line in httpd.conf file

These are for apache to load php modules.

LoadModule php5_module modules/libphp5.so

AddType Application/X-httpd-php .php

Now try with http://serverIP/index.php
If index.php is set as 1st priority in virtual host part in httpd.conf file, then ServerIP displays php info page on the browser. 

Pre-requisites:

yum install gcc or gcc*

yum install openssl-devel

Step 1: Download the source from http://mirrors.sonic.net/apache//httpd/

wget http://mirrors.sonic.net/apache//httpd/httpd-2.4.4.tar.gz

Step 2:  Extract this

tar xvzf httpd-2.4.4.tar.gz

Step 3: Change directory to extracted directory

cd httpd-2.4.4

Step 4: 

./configure –prefix=/usr/local/apache

While configuring, we get below error

Error:

checking for APR… configure: WARNING: APR version 1.4.0 or later is required, found 1.3.9

configure: WARNING: skipped APR at apr-1-config, version not acceptable

sed: can’t read ./srclib/apr/include/apr_version.h: No such file or directory
configure: error: failed to find major version of bundled APR

Solution:

We need to install apr and apr-util packages to resolve this issue.

Download apr and apr-util packages from

http://apr.apache.org/download.cgi

For apr package:

wget http://www.motorlogy.com/apache//apr/apr-1.4.8.tar.gz

tar xvzf apr-1.4.8.tar.gz

cd apr-1.4.8

./configure –prefix=/usr/local/src/httpd-2.4.4/srclib/apr

make

make install

For apr-util package:

http://www.motorlogy.com/apache//apr/apr-util-1.5.2.tar.gz 

cd apr-util-1.5.2

./configure –prefix=/usr/local/src/httpd-2.4.4/srclib/apr-util

make

make install

Step 5: Now configure apache

./configure –prefix=/usr/local/apache –enable-mods-shared=all –with-apr=/usr/local/src/httpd-2.4.4/srclib/apr-1.4.8 –with-apr-util=/usr/local/src/httpd-2.4.4/srclib/apr-util-1.5.2

But, while configuring this we may get below error

Error:

checking for pcre-config… false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

Solution:

pcre package needs to be installed to resolve this issue.

Download pcre:

wget http://sourceforge.net/projects/pcre/files/latest/download?source=files

pcre-8.33.tar.bz2 will be saved

To extract:

tar jxf pcre-8.33.tar.bz2

cd pcre-8.33

Now configure pcre with:

./configure –prefix=/usr/local/pcre

make

make install

Now configure apache again

./configure –prefix=/usr/local/apache –enable-mods-shared=all –with-apr=/usr/local/src/httpd-2.4.4/srclib/apr –with-apr-util=/usr/local/src/httpd-2.4.4/srclib/apr-util –with-pcre=/usr/local/pcre/

make

make install

Now configure apache again with:

./configure –prefix=/usr/local/apache –enable-mods-shared=all –with-apr=/usr/local/src/httpd-2.4.4/srclib/apr –with-apr-util=/usr/local/src/httpd-2.4.4/srclib/apr-util –with-pcre=/usr/local/pcre/

make

make install

This is how apache can be installed with source.

Now start and stop services by

/usr/local/apache/bin/apachectl start/stop

Check the apache homepage with http://serverIP/ or http://localhost/

It displays the file which is set for default document root.

The default document root is /usr/local/apache/htdocs which is set at apache configuration file (httpd.conf) located at /usr/local/apache/conf/

For init script:

create a file named httpd or apache as our convenience under the directory /etc/init.d

vi /etc/init.d/httpd

Add below line to this file

#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=/usr/local/apache/bin/httpd
pid=$httpd/logs/httpd.pid
prog=httpd
RETVAL=0

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid
}
reload() {
        echo -n $"Reloading $prog: "
        killproc $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f $pid ] ; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status"
                echo $"|fullstatus|graceful|help|configtest}"
        exit 1
esac

exit $RETVAL


Save the file and exit.

Now try this script by starting up and down the apache services

/etc/init.d/httpd start/stop/status


 Pre-requisites to install nagios

Step1:

Run these commands from a command line:

[root@localhost ~]# yum install httpd

[root@localhost ~]# yum install gcc

[root@localhost ~]# yum install glibc glibc-common

[root@localhost ~]# yum install gd gd-devel

[root@localhost ~]# yum install php

Step2:

# su –

Step3:

Create a new user for nagios 

[root@localhost ~]#  useradd -m nagios

[root@localhost ~]#  passwd nagios

It asks for new password, type the new password 

Step4:

Create a new nagcmd group for external commands

[root@localhost ~]# groupadd nagcmd

[root@localhost ~]# usermod -a -G nagcmd nagios

[root@localhost ~]# usermod -a -G nagcmd apache

Step5:

Download the nagios software and plugins 

[root@localhost ~]#  wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gz 
[root@localhost ~]#  wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

Step6:

Extract and compile nagios-3.4.4.tar.gz

[root@localhost ~]# tar -xzvf nagios-3.4.4.tar.gz

[root@localhost ~]# cd nagios-3.4.4

[root@localhost ~]# ./configure –with-command-group=nagcmd

[root@localhost ~]# make all

[root@localhost ~]# make install

[root@localhost ~]# make install-init

[root@localhost ~]# make install-config

[root@localhost ~]# make install-commandmode

Step7:

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file. Change the email address associated with the nagiosadmin contact to the address you’d like to use for receiving alerts

[root@localhost ~]# vi /usr/local/nagios/etc/objects/contacts.cfg

Step8:

Install the Nagios web config file in the Apache conf.d directory

[root@localhost ~]# make install-webconf

Step9: 

Create a nagiosadmin account for logging into the Nagios web interface

[root@localhost ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Step10:

Restart Apache

[root@localhost ~]# service httpd restart

Step11:

Compile and Install the Nagios Plugins

[root@localhost ~]#  wget nagios-plugins-1.4.16.tar.gz

[root@localhost ~]#  tar -xvzf nagios-plugins-1.4.16.tar.gz

[root@localhost ~]#  cd nagios-plugins-1.4.16

[root@localhost ~]#  ./configure –with-nagios-user=nagios –with-nagios-group=nagios

[root@localhost ~]# make

[root@localhost ~]# make install

Step12: Add Nagios to the list of system services

[root@localhost ~]#  chkconfig –add nagios

[root@localhost ~]# chkconfig nagios on

Step13:

Check for config errors

[root@localhost ~]#  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Step14:

Start Nagios

[root@localhost ~]#  service nagios start

Step15:

Login to the Web Interface using username (nagiosadmin) and password you specified earlier

From your internet browser navigate to the following URL:

http://<yourserver name or IP>/nagios

When you check this url, we should see one default server, if not seen that then execute below command

[root@localhost ~]#  chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/

Check the url again,

http://<yourserver name or IP>/nagios

 

 

For backup of a database with gunzip format:

time mysqldump -u root -p –routines databasename | gzip > filename.sql.gz

Time displays the time taken to dump the database.

For restore:

time gunzip -c dumpfilename.sql.gz | mysql -u root -p database