INSTALLING/CONFIGURING
APACHE V2 AND PHP V4 THROUGH SOURCE CODE AND MYSQL THROUGH YUM/RPM
IN CENTOS 6.2/RHEL5
Why compile from source
You
may ask, why we need to compile PHP and Apache from source when
binary RPMs are already available and which don't take much effort to
setup. The reason is, it provides you much more flexibility. Instead
of being dependent on other people's RPMs you can decide what PHP and
Apache functionality you want to enable. Another reason is that these
RPMs are weeks or months out of date. When compiling from source, you
can also specify the directory where software will be installed.
Also, after you see your compiled software working, it really
provides great satisfaction. Compilation process is really very
straight forward.
Before you start
Before
starting to compile Apache and PHP you must uninstall all previous
Apache and PHP related RPMs installed on your system
Then
download apache
2.0 source and PHP
source . These files have .tar.gz extension. Save these files to
any directory of your choice. I am using PHP 4.4.9 and Apache
2.0.44/64 and have these files in /usr/src
directory.
NOTE:
I faced no problems with Apache 2.0.44 and PHP 4.4.9(IN
CENT 6.2)
I
faced no problems with Apache 2.0.64 and PHP 4.4.9(IN RHEL 5)
I
have faced so many problems with Apache 2.0.44 and PHP 4.3.0 /4.3.9in
my system (CENT 6.2 64 bit)
but
it may work in another machines(like cent os 5 /RHEL5).
Most
others faced no problems with Apache 2.0.40 / 2.0.43 and PHP 4.2.3
and Apache 2.0.44 and PHP 4.3.0
YOU
MAY GET PROBLEMS WHILE USING BELOW SOURCE CODE
Compilation Process
Login as
root to follow these steps.
#cd
/usr/src |
download
source code from apache website and unzip in /usr/src
# cd
/usr/src/httpd-2.0.44 |
#./configure
--prefix=/wwwroot –enable-so
|
(OR)
#./configure
--prefix=/wwwroot --enable-so --enable-deflate --enable-expires
--enable-headers --enable-rewrite --with-included-apr
--with-included-apr-util |
First
option
--prefix
tells
configure
script that we want Apache to be installed in directory /wwwroot. If
we don't provide a prefix option than it'll be installed in default
location, which is /usr/local/apache2.
I
am installing everything in /wwwroot because:
- when a new version of PHP and Apache is released, I only have to rename /wwwroot directory to some other name like /wwwrootold and then I can install new versions in /wwwroot directory again. If new installation works properly then I can simply copy configuration files from old directory to /wwwroot.
- users new to compiling software from source, after compiling and installing it, try to find a way to uninstall the software. So, benefit of keeping everything at one place is; if someone wants to uninstall Apache and PHP then he just has to delete /wwwroot directory (After stopping Apache, if it is running).
Second
option --enable-so tells configure to enable module so,
which allows Apache to load shared modules. We need this option
because we are compiling PHP as Apache shared module.
Example
Apache configure command line looks like this.
After configure finishes we have to compile Apache.
YOU MAY
GET THIS TYPE OF ERROR
rotatelogs.c:298:
warning: implicit declaration of function ‘apr_file_link’
/usr/lib64/apr-1/build/libtool
--silent --mode=link gcc -std=gnu99 -pthread
-o
rotatelogs rotatelogs.lo /usr/lib64/libaprutil-1.la -ldb-4.7
-lexpat
-ldb-4.7
/usr/lib64/libapr-1.la -lpthread
rotatelogs.o:
In function `post_rotate':
rotatelogs.c:(.text+0x5ed):
undefined reference to `apr_file_link'
collect2:
ld returned 1 exit status
make[2]:
*** [rotatelogs] Error 1
make[2]:
Leaving directory `/
usr/local/src/
httpd-2.0.44/support'
make[1]:
*** [all-recursive] Error 1
make[1]:
Leaving directory `
/usr/local/src/
httpd-2.0.44/support'
make:
*** [all-recursive] Error 1
IF
U GET SAME ERROR THEN DOWNLOAD NEW APR AND APR-UTIL FROM INTERNET AND
THEN COPY INTO
/usr/local/src/httpd-2.4.1/srclib/
AND
UNZIP RENAME IT TO “apr and apt-util” as
shown
below
cd
/usr/local/src/httpd-2.4.1/srclib/
Installing
APR & APR-Utils dependencies :
#wget
http://mirror-cybernet.lums.edu.pk/pub/apache//apr/apr-util-1.4.1.tar.bz2 |
#wget
http://mirror-cybernet.lums.edu.pk/pub/apache//apr/apr-1.4.6.tar.bz2 |
#tar
-jxf apr-1.4.6.tar.bz2 |
#tar
-jxf apr-util-1.4.1.tar.bz2 |
#mv
apr-1.4.6 apr |
#mv
apr-util-1.4.1 apr-util |
Lets
configure it now :
#./configure
--prefix=/wwwroot --enable-so --enable-deflate --enable-expires
--enable-headers --enable-rewrite --with-included-apr
–with-included-apr-util |
ERROR:
you
may get lot of errors thats depends upon the libraries or
dependencies and other modules first see the error if you get any
errors just type
# yum
install packname* |
AGAIN
ERROR :
if
you got same error or different error some dependencies are missing
in your OS. So please check the dependencies and install it through
rpm or yum
OR)
simply
change the source code of apache and try another version in your
system and follow above process
#make |
#make
install |
This
will install Apache to /wwwroot directory. Now test your Apache
installation by starting Apache:
#
/wwwroot/bin/apachectl start-----------for starting apache |
#
/wwwroot/bin/apachectl stop -----------for stoping apache |
INSTALLING
MYSQL
you
can install mysql through yum or rpm
#yum
install mysql* |
it
will install all packages of my sql
type
below command for changing password of root user of mysql
#mysql
-u root -p |
#PASSWD:**********
-------it will ask password then enter new password |
Compiling
PHP
Change
to directory where you have downloaded PHP source.
# cd /usr/src |
Then we have to extract PHP source files from php-4.4.9.tar.gz file.
To decompress the compressed file use:
# gunzip
php-4.4.9.tar.gz |
# tar -xvf
php-4.4.9.tar |
# tar -zxvf
php-4.4.9.tar.gz
|
A new directory php-4.3.0 will be created in your current directory. For me its /usr/src/php-4.3.0.
Now change to this directory:
# cd
/usr/src/php-4.4.9 |
#./configure --prefix=/wwwroot/php
--with-apxs2=/wwwroot/bin/apxs
--with-config-file-path=/wwwroot/php --with-mysql |
After
configure
finishes. You have to type
make
to compile PHP:
# make |
It
will take several minutes to compile. After make finishes and, no
error etc. is displayed then PHP has been compiled successfully. If
any warning is displayed then, normally, you can ignore it.
After this, if Apache is running stop Apache:
#
/wwwroot/bin/apachectl stop |
Now you can execute make install from within PHP source directory to install PHP to /wwwroot/php directory:
# make
install |
make install will install PHP4 module to Apache's modules sub-directory (/wwwroot/modules) and add a line like this:
AddType
application/x-httpd-php .php
in
/wwwroot/conf/httpd.conf file
To
add this line search for word AddType in httpd.conf file. There will
be a line like this:
AddType application/x-tar .tgz
Below this line add (on a new line):
AddType
application/x-httpd-php .php
Save
this file and then start Apache:
#
/wwwroot/bin/apachectl start |
Testing
the PHP Installation
Now
create a PHP file named info.php, using any editor like vi or emacs,
in the /wwwroot/htdocs directory and enter three lines, shown below,
in this file. Directory /wwwroot/htdocs is Apache root directory.
Apache publishes all files present in this directory to web users.
This directory can be changed by editing httpd.conf file and changing
DocumentRoot
value to some other directory.
info.php
<?php
phpinfo();
?>
Save this file and then access this file using a web browser
Now
you can copy /usr/src/php-4.4.9/php.ini-dist to /wwwroot/php/
directory as php.ini.
#
cp /usr/src/php-4.4.9/php.ini-dist /wwwroot/php/php.ini |
#
/wwwroot/bin/apachectl restart |
NOTE:
AFTER
INSTALLING ALL DEPENDENCIES AND MODULES AND DEPENDENT LIBRARIES ITS
WORKING IN MY SYSTEM
IAM
NOT SURE IT MAY WORK IT MAY NOT WORK IN YOUR SYSTEM
BUT
TRY DIFFERENT DIFFERENT SOURCE CODE OF APACHE AND PHP IN YOUR SYSTEM
IT WILL WORK IN YOUR SYSTEM
FOR
MORE CLARIFICATION FOLLOW THE BELOW LINK I HAVE FOLLOWED SOMANY LINKS
BUT THIS IS THE BEST LINK
http://www.web-tech-india.com/articles/php/compiling_php_apache/
No comments:
Post a Comment