apache编译安装 httpd 2.2 httpd 2.4

时间:2021-01-11 00:37:28

#apache编译安装
#httpd 2.2 , httpd 2.4

#!/bin/sh
#apache编译安装
#httpd 2.2 , httpd 2.4
#centos #rpm -e httpd*
Ve=2.2
[ $ = 2.4 ] && Ve=2.4 || Ve=2.2 #设置安装版本2.2或2. #目录
Ddir=/it/tools #定义下载目录
Sdir=/www/server #定义安装目录
Adir=$Sdir/apache$Ve
[ ! -d $Ddir ] && mkdir -p $Ddir
mkdir -p $Adir echo '#安装需要的库'
yum install make gcc gcc-c++ pcre pcre-devel zlib* -y
yum install expat-devel -y #安装apr-util需要
#yum install apr apr-util -y
yum install wget lrzsz -y
yum install openssl openssl-devel -y # echo '#添加用户'
# useradd apache -s /sbin/nologin -M
# id apache echo "#下载"
cd $Ddir
wget http://mirrors.aliyun.com/apache/apr/apr-1.6.2.tar.gz
wget http://mirrors.aliyun.com/apache/apr/apr-util-1.6.0.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
[ $Ve = 2.4 ] && {
wget http://mirrors.aliyun.com/apache/httpd/httpd-2.4.27.tar.gz ;
}|| {
wget http://mirrors.aliyun.com/apache/httpd/httpd-2.2.34.tar.gz ;
} echo "解压"
tar -xf apr-.*.tar.gz
tar -xf apr-util-.*.tar.gz
tar -xf pcre-.*.tar.gz
tar -xf httpd-$Ve.*.tar.gz
[ $? = ] || { echo "解压出现问题 !";exit; } echo "#安装"
mkdir -p $Sdir/http/{apr,apr-util,pcre}
cd $Ddir
#apr
cd apr-.*
./configure --prefix=$Sdir/http/apr/
[ $? = ] || { echo "编译出现问题 !";exit; }
make && make install
cd ..
#apr-util
cd apr-util-.*
./configure --prefix=$Sdir/http/apr-util/ --with-apr=$Sdir/http/apr/
[ $? = ] || { echo "编译出现问题 !";exit; }
make && make install
cd ..
#pcre
cd pcre-.*
./configure --prefix=$Sdir/http/pcre/
[ $? = ] || { echo "编译出现问题 !";exit; }
make && make install
cd .. #httpd
cd $Ddir/httpd-$Ve.*
#./configure --help
./configure \
--prefix=$Adir \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite \
--with-apr=$Sdir/http/apr/ \
--with-apr-util=$Sdir/http/apr-util/ \
--with-pcre=$Sdir/http/pcre/ \
ap_cv_void_ptr_lt_long=no
#
[ $? = ] || { echo "编译出现问题 !";exit; }
echo 编译安装
make -j4 && make install
echo '#编译模块查看'
$Adir/bin/apachectl -l pkill `netstat -antp|grep |awk -F '/' '{ print $2}'` &>/dev/null #关闭80端口进程
echo "ServerName localhost:80">>$Adir/conf/httpd.conf
echo '#启动apache'
$Adir/bin/apachectl start
echo '#查看'
netstat -antp|grep httpd
ps -ef|grep http|grep -v "grep"
echo "$Adir/bin/apachectl { start|restart|stop }" # 加入系统服务,开机启动
sed -i -e '2 i #chkconfig: 2345 70 60 \n#description: apache' $Adir/bin/apachectl
# ln -s $Adir/bin/apachectl /etc/init.d/httpd
# echo "$Adir/bin/apachectl start">>/etc/rc.local
# chkconfig --add httpd
# chkconfig httpd on
# chkconfig --list httpd # # #添加环境变量
# echo "export PATH=$Adir/bin:$PATH">>/etc/profile.d/httpd.sh
# . /etc/profile.d/httpd.sh # #添加库文件至系统
# echo "$Adir/include/">>/etc/ld.so.conf.d/httpd.conf
# ldconfig # #man文档添加至系统
# man -M $Adir/man httpd
# echo "MANPATH $Adir/man">>/etc/man.config # #隐藏头文件版本
# echo "#隐藏头文件版本
# ServerTokens ProductOnly
# ServerSignature Off
# ">>$Adir/conf/httpd.conf #php 测试
echo '<?php phpinfo(); ?>'>$Adir/htdocs/test.php
# other
#--sysconfdir=/etc/httpd \ #Apache配置php
#php编译时,需要有参数--with-apxs2=/apache安装目录/bin/apxs \
#php编译完成后,apache配置文件里会自动添加php模块LoadModule php5_module module/libphp5.so
#echo "Addtype application/x-httpd-php .php .phtml">>$Adir/conf/httpd.conf #开启php支持 #另一种方式,使用fcgi接口方式,传递php给独立php进程解析,配置略