This How-To guides you through the steps to install and configure the most popular and powerful Apache-2.2.8 web server with PHP-5.2.5 and Mysql-5.0.45.

This How-To can be used either on Linux with Kernel version 2.4 and higher or on FreeBSD-6.x systems.

From wikipedia, the definition of a web server is as follows:

A computer program that is responsible for accepting HTTP requests from clients, which are known as web browsers (e.g. Firefox, Internet Explorer), and serving them HTTP responses along with optional data contents, which usually are web pages such as HTML documents and linked objects (images, etc.).

Without Web servers, the Internet would just be as dull as sending and receiving emails.

It is the web server which provides the content and information that we are used to seeing these days. It’s the web server’s job to deliver both static and dynamic contents to end-users via browsers such as Mozilla Firefox and Internet Explorer.

Apache is to web servers what Bind is to DNS servers. Apache is a high performance and scalable web server notable for playing a key role in the initial growth of the World Wide Web. According to the data provided by news.netcraft.com, 50% of all web sites are running on Apache web servers.

In this guide, we will install and configure a simple Apache-2.2.8 web server with PHP-5.2.4 and Mysql-5.0.45.

MySQL is a robust Relational Database Management System (RDBMS) that relies on Structured Query Language (SQL) for processing the data in the database.

MySQL is most commonly used for Web applications and for embedded applications and has become a popular alternative to proprietary database systems such as Oracle and Sybase because of its speed and reliability.

PHP is a reflective programming language originally designed for producing dynamic web pages.PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications.

PHP generally runs on a web server, taking PHP code as its input and creating Web pages as output.

The following guide details the installation and configuration of this 3 powerful components.

Installing Mysql-5.0.45

(1.) Create the necessary mysql user and mysql group

groupadd mysql
useradd -g mysql mysql

(2.) Download Mysql
cd /usr/local/src

wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.45.tar.gz/from/http://mirror.trouble-free.net/mysql_mirror/

(3.) Unzip the sources

tar zxvf mysql-5.0.45.tar.gz

(4.) Got to source directory and run configure

cd mysql-5.0.45

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

(5.) Make and Install

make

make install

(6.) Copy the main my.cnf file and change the necessary permissions and run Mysql

cp support-files/my-medium.cnf /etc/my.cnf

cd /usr/local/mysql

chown -R mysql .

chgrp -R mysql .

bin/mysql_install_db –user=mysql

chown -R root .

chown -R mysql var
bin/mysqld_safe –user=mysql &
If all goes well, Mysql is now installed and should be running!!

Note: If you face problems such as getting configuration and compilation errors, check your permissions. 95% of all problems can be solved either by installing dependencies and development libraries. Google is your friend as always.

Installing and configuring Apache-2.2.8

(1.) Download Apache

cd /usr/local/src

wget http://veritris.com/mirrors/apache/httpd/httpd-2.2.8.tar.gz

(2.) unzip the sources

tar zxvf httpd-2.2.8.tar.gz

(3.) Configure Apache

cd httpd-2.2.8

./configure

–prefix=/usr/local/httpd \
–enable-cache \
–enable-disk-cache \
–enable-mem-cache \
–enable-proxy \
–enable-proxy-http \
–enable-proxy-ftp \
–enable-proxy-connect \
–enable-so \
–enable-cgi \
–enable-info \
–enable-rewrite \
–enable-speling \
–enable-usertrack \
–enable-deflate \
–enable-mime-magic

(4.) Make and Install

make

make install

That’s it. Apache should now be installed in /usr/local/httpd ! Note: If you face problems such as getting compilation errors, check your permissions. 95% of all problems can be solved either by installing dependencies and development libraries. Google is your friend as always.

Installing and Configuring PHP

(1.) Download PHP

cd /usr/local/src

wget http://www.php.net/get/php-5.2.5.tar.gz/from/au2.php.net/mirror

(2.) Unzip the sources

tar zxvf php-5.2.5.tar.gz

(3.) Configure PHP for Apache and Mysql support

./configure

–with-apxs2=/usr/local/httpd/bin/apxs \
–with-mysql=/usr/local/mysql \
–prefix=/usr/local/httpd/php \
–with-config-file-path=/usr/local/httpd/php \
–enable-force-cgi-redirect \
–disable-cgi \
–with-zlib \
–with-gettext \
–with-gdbm

(4.) Make and Install

make

make install

(5.) Configure PHP configuration

cp php.ini-dist /usr/local/lib/php.ini

(6.) Edit your httpd.conf to load the PHP module

vi /usr/local/httpd/conf/httpd.conf

#Added the following in the relevant section

LoadModule php5_module modules/libphp5.so
(7.) Tell Apache to parse certain extensions as PHP and also to parse .phtml and phps extensions

vi /usr/local/httpd/conf/httpd.conf

#Added the following in the relevant sections

AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

(8.) Start your Apache-2.2.6 server

/usr/local/httpd/bin/apachectl start

Note: If you face problems such as getting configuration and compilation errors, check your permissions. 95% of all problems can be solved either by installing dependencies and development libraries. Google is your friend as always.

Testing PHP installation

(1.) Create the following info.php file in the default htdocs directory

vi /usr/local/httpd/htdocs/info.php

##Copy and paste the following text

<?php
phpinfo();
?>

(2.) Save the file and start your web browser to point to your local web server. If this server is a remote server, simply enter it’s IP address in place of localhost

http://localhost/info.php

You should be able to see detailed information about your PHP installation, Apache environment and PHP extensions loaded, etc.

Apache 1.3.X
tar xzvf  openssl-0.9.7d.tar.gz
cd openssl-0.9.7d
./config --prefix=/usr/local --openssldir=/usr/local/openssl
make
make test
make install

tar xzvf mod_ssl-2.8.16-1.3.29.tar.gz
cd mod_ssl-2.8.16-1.3.29
./configure \
              --with-apache=../apache_1.3.29 \
              --with-ssl=../openssl-0.9.7d \
              --prefix=/usr/local/apache \
              --enable-shared=ssl \
tar xzvf mod_perl-1.26.tar.gz
cd mod_perl-1.26
perl Makefile.PL \
               APACHE_SRC=../apache_1.3.29/src \
               DO_HTTPD=1 \
               USE_APACI=1 \
               PREP_HTTPD=1 \
               EVERYTHING=1 \

        $ make
        $ make test
        $ make install

 # adduser apache

Note the UID AND GID

tar xzvf apache_1.3.29.tar.gz
cd apache_1.3.29

SSL_BASE=../openssl-0.9.7d \
./configure --prefix=/usr/local/apache \
     --server-uid=apache \
     --server-gid=apache \
     --enable-module=ssl \
     --enable-shared=ssl \
     --enable-module=auth_dbm \
     --enable-module=auth_db \
     --enable-module=auth_anon \
     --enable-module=digest \
     --enable-module=expires \
     --enable-module=so \
     --enable-module=headers \
     --enable-module=usertrack \
     --enable-module=env \
     --enable-module=rewrite \
     --enable-suexec \
     --suexec-caller=apache \
     --suexec-uidmin=500 \
     --suexec-gidmin=500 \
     --activate-module=src/modules/perl/libperl.a \

make
make certificate TYPE=custom

make install

##DSO
./configure \
                --with-apxs=/usr/local/apache/bin/apxs \
                --enable-versioning \
                --with-mysql \
                --enable-track-vars

make
make install

#add to httpd.conf

#done auto by make install
#LoadModule php4_module libexec/libphp4.so
#LoadModule php4_module modules/libphp4.so
#AddModule mod_php4.c

AddType application/x-httpd-php .php .php3
AddType application/x-httpd-php-source .phps

cp php.ini-recommended /usr/local/lib/php.ini

Load Balancing Your Web Site

http://www.webtechniques.com/archives/1998/05/engelschall/

http://www.ddj.com/architect/184414169?pgno=1
http://www.howtoforge.com/load_balancing_apache_mod_proxy_balancer

Mirror website
wget -m -k -K -E http://url/of/web/site

find the ip address by location and redirect the mirror site
http://www.hostip.info/use.html
Php code to redirect to mirror server country wise

<?php

/* ipaddresses.txt
– 192.168.1.105 (Single IP)
– 192.168.1.* (IP Range with *)
– 192.168.1.100-110 (IP range with -)
– 192.168.?.* (IP range with ?)
*/
error_reporting(0);

function chkiplist($ip) {
# read in the ip address file
$lines = file(“ipaddresses.txt”);
# set a variable as false
$found = false;
# convert ip address into a number
$split_it = split(“\.”,$ip);
$ip = “1” . sprintf(“%03d”,$split_it[0]) .

sprintf(“%03d”,$split_it[1]) . sprintf(“%03d”,$split_it[2]) .

sprintf(“%03d”,$split_it[3]);

# loop through the ip address file

foreach ($lines as $line) {

# remove line feeds from the line

$line = chop($line);

# replace x with a *

$line = str_replace(“x”,”*”,$line);

# remove comments

$line = preg_replace(“|[A-Za-z#/]|”,””,$line);

# set a maximum and minimum value

$max = $line;

$min = $line;

# replace * with a 3 digit number

if ( strpos($line,”*”,0) <> “” ) {

$max = str_replace(“*”,”999″,$line);

$min = str_replace(“*”,”000″,$line);

}

# replace ? with a single digit

if ( strpos($line,”?”,0) <> “” ) {

$max = str_replace(“?”,”9″,$line);

$min = str_replace(“?”,”0″,$line);

}

# if the line is invalid go to the next line

if ( $max == “” ) { continue; };

# check for a range

if ( strpos($max,” – “,0) <> “” ) {

$split_it = split(” – “,$max);

# if the second part does not match an ip address

if ( !preg_match(“|\d{1,3}\.|”,$split_it[1]) ) {

$max = $split_it[0];

}

else {

$max = $split_it[1];

};

}

if ( strpos($min,” – “,0) <> “” ) {

$split_it = split(” – “,$min);

$min = $split_it[0];

}

# make $max into a number

$split_it = split(“\.”,$max);

for ( $i=0;$i<4;$i++ ) {

if ( $i == 0 ) { $max = 1; };

if ( strpos($split_it[$i],”-“,0) <> “” ) {

$another_split = split(“-“,$split_it[$i]);

$split_it[$i] = $another_split[1];

}

$max .= sprintf(“%03d”,$split_it[$i]);

}

# make $min into a number

$split_it = split(“\.”,$min);

for ( $i=0;$i<4;$i++ ) {

if ( $i == 0 ) { $min = 1; };

if ( strpos($split_it[$i],”-“,0) <> “” ) {

$another_split = split(“-“,$split_it[$i]);

$split_it[$i] = $another_split[0];

}

$min .= sprintf(“%03d”,$split_it[$i]);

}

# check for a match

if ( ($ip <= $max) && ($ip >= $min) ) {

$found = true;

break;

};

}

return $found;

}; # end function

$country = “”;
$country1 = “”;
$cxContext-“”;
$site = “http://mail.niec.edu.np/home/index.php”;
$port = 80;
$IP = $_SERVER[‘REMOTE_ADDR’];

if (!empty($IP))
{
if(chkiplist($IP))
{
header(“Location: http://mail.niec.edu.np”);
}
else
{
$country = file_get_contents(“http://api.hostip.info/country.php?ip=”.$IP);
if(!empty($country)&& $country==”NP”)
{
$country1 = file_get_contents(“http://mail.niec.edu.np/check.php”);

if(!empty($country1)&& $country1==”nepal”)
{
header(“Location: http://mail.niec.edu.np”);
}
else
{
header(“Location: home/”);
}
}
else
{
header(“Location: home/”);
}
}
}
else
{
header(“Location: home/”);
}
?>
For more information

http://sourceforge.net/search/?type_of_search=soft&words=ip+to+country+php

Leave a Reply