Friday, September 27, 2013

Set up Apache2.4.6 from source



Apache 2.4.x is probably even faster than those web servers that are well-known by their speed. for example: Nginx。
The difference between apache-2.4 and apache-2.2 is that: apache-2.4 does not include apr along with the installation package, therefore, before we install apache-2.4之, we need to download and install apr first 

Source packages we need:

/usr/local/src/Apache-2.4.6/apr-1.4.8.tar.gz
/usr/local/src/Apache-2.4.6/apr-util-1.5.2.tar.gz
/usr/local/src/Apache-2.4.6/httpd-2.4.6.tar.gz

According to the apache requirement, we MUST put the source files of apr,apr-util in the directory apache2.4.6/srclib, and we need to rename the source diretories' names to apr and apr-util.
cp -rf apr-1.4.3 ./srclib/apr
cp -rf apr-util-1.4.1 ./srclib/apr-util

Install Apache dependency library
(1) Install apr
tar -xzvf /usr/src/apr-1.4.8.tar.gz -C /usr/src/httpd-2.4.6/srclib/apr
cd /usr/src/httpd-2.4.6/srclib/apr/apr-1.4.8
./configure --prefix=/usr/local/apr
make && make install

(2) Install apr-util
tar -xzvf /usr/src/apr-1.5.2.tar.gz -C /usr/src/httpd-2.4.6/srclib/apr-util
cd /usr/src/httpd-2.4.6/srclib/apr-util/apr-util-1.5.2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install

(2) Install pcre
tar -xzvf pcre-8.33.tar.gz -C /usr/src
cd /usr/src/pcre-8.33
./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config
make && make install


Install Apache2.4.6
Switch to the apache source directory
cd /usr/src/httpd-2.4.6

Configure:
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-deflate=shared --enable-expires=shared --enable-ssl=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support --with-mpm=prefork

Compile:
make && make install 

compile arguments description:
--prefix=/usr/local/apache :specify the installation directory
--with-apr=/usr/local/apr : apr library
--with-apr-util=/usr/local/apr-util :apr-util library
--with-pcre=/usr/local/pcre : pcre library
--enable-so : allow load DSO while running (Notice: so needs to be statically compiled)
--enable-deflate=shared :compile Module deflate to DSO
--enable-expires=shared : compile Module expires to DSO
--enable-ssl=shared : compile Module ssl toDSO
--enable-headers=shared : compile Module headers to DSO
--enable-rewrite=shared : compile Module rewrite to DSO
--enable-static-support : use static link(dynamic by default) to compile all the binary supporting routines
--with-mpm=prefork : use mpm in the form of prefork

cp ./build/rpm/httpd.init /etc/init.d/httpd #使用init脚本管理httpd
chmod 755 /etc/init.d/httpd #change operation rights
update-rc.d httpd defaults
ln -s /usr/local/apache /etc/httpd  #create a link

the configuration file is:  /etc/httpd/conf/httpd.conf, the real path is /usr/local/apache/conf/httpd.conf

rm -rf /var/log/httpd/
ln -s /usr/local/apache/logs /var/log/httpd

groupadd apache #add apache group and user
useradd -g apache -s /usr/sbin/nologin apache
chown -R apache:apache /usr/local/apache

#configure firewall, open port 80
vim /etc/sysconfig/iptables 

# add a rule to port 22
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

#restart firewall
service iptables restart # 或 /etc/init.d/iptables restart

#start Apache
service httpd start # 或 /etc/init.d/httpd start





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Solutions to some errors:


(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80


do the following :

vi /etc/httpd/conf/httpd.conf

and replace the port 80 and port 443 with 
port 80--->88
port 443 --> 448 for the timebeing.

to do quick find vi the file and than presh escap key and than put the ? question mark and than type 80 or 443 . to fine other 88 entry press n on the same time. anyhow let me kick ur ass now bcoz not suppose to teach all these things now..

well when u replaced them than u simply run the command

service htttpd restart
again to confirm service httpd restart

than see if it has started 

service httpd status...
than u will see that ur webserver is started on port 88 and 448 for ssl. hummmmm

now try to browse http://ipaddressof ur linuxbox:88
http://ipadr:443

u will see that ur page is cameup...hummmmmmm but problem is not solved yet. 
this teaches us that the prblem is with the port conflict..how can u track it..

put the command

lsif :80

u will see the several process are already running on port 80 so apachea can't start on the same port. so u have to kill all these apachea process using kill -9 <processid>

my logs:
=======
[root@ns root]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
xfs 19085 apache 18u IPv4 127053 TCP *:http (LISTEN)
sh 19086 apache 18u IPv4 127053 TCP *:http (LISTEN)
sh 19087 root 18u IPv4 127053 TCP *:http (LISTEN)
su 19088 root 18u IPv4 127053 TCP *:http (LISTEN)
bash 19089 root 18u IPv4 127053 TCP *:http (LISTEN)
[root@ns root]# kil -9 19085 19086
bash: kil: command not found
[root@ns root]# kill -9 19085 19086
[root@ns root]# lsof -i :80
[root@ns root]# lsof -i :443
[root@ns root]# lsof -i :443
[root@ns root]#
[root@ns root]#
[root@ns root]#
[root@ns root]#
[root@ns root]#
[root@ns root]# apachectl sto
usage: /usr/sbin/apachectl (start|stop|restart|fullstatus|status|graceful|configtest|help)

start - start httpd
stop - stop httpd
restart - restart httpd if running by sending a SIGHUP or start if
not running
fullstatus - dump a full status screen; requires lynx and mod_status enabled
status - dump a short status screen; requires lynx and mod_status enabled
graceful - do a graceful restart by sending a SIGUSR1 or start if not running
configtest - do a configuration syntax test
help - this screen

[root@ns root]# apachectl stop
/usr/sbin/apachectl stop: httpd (no pid file) not running
[root@ns root]# apachectl start
/usr/sbin/apachectl start: httpd started
[root@ns root]# lsof -i :443
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 24957 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24958 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24959 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24960 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24961 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24962 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24963 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24964 root 19u IPv4 479222 TCP *:https (LISTEN)
httpd 24965 root 19u IPv4 479222 TCP *:https (LISTEN)
[root@ns root]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 24957 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24958 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24959 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24960 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24961 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24962 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24963 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24964 root 18u IPv4 479221 TCP *:http (LISTEN)
httpd 24965 root 18u IPv4 479221 TCP *:http (LISTEN)
[root@ns root]# service httpd status
httpd (pid 24965 24964 24963 24962 24961 24960 24959 24958 24957) is running...
[root@ns root]# ls
anaconda-ks.cfg dead.letter Linux_Backup mail Mail nsmail
[root@ns root]# cd /etc/httpd/config
bash: cd: /etc/httpd/config: No such file or directory
[root@ns root]# ls
anaconda-ks.cfg dead.letter Linux_Backup mail Mail nsmail
[root@ns root]# cd /etc/httpd
[root@ns httpd]# cd conf
[root@ns conf]# ls


Why this problem comes:
-------------------------------
this problem is comes only if u started the weberver and than made some modification or tried to load the jsp or asp support than u will find http locked when u tried to restart it .

so don't be confussed. just kill th process and than put ur configuration (original file) which has port 80 or 443.

it will work fine......

else mail me on my personal mail ilel 
pushkar_bhatkoti@rediffmail.com
yahooo: pushkarbhatkoti@yahoo.com

My mobile is : 9810774912 
I lives in New Delhi India.
cheers!!




/lib/lsb/init-functions

No comments:

Post a Comment