apache编译安装 httpd 2.2 httpd 2.4

Posted Elvin笔记分享

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache编译安装 httpd 2.2 httpd 2.4相关的知识,希望对你有一定的参考价值。

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

 

#!/bin/sh
#apache编译安装
#httpd 2.2 , httpd 2.4
#centos 

#rpm -e httpd*
Ve=2.2
[ $1 = 2.4 ] && Ve=2.4 || Ve=2.2 #设置安装版本2.2或2.4

#目录
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-1.*.tar.gz
tar -xf apr-util-1.*.tar.gz
tar -xf pcre-8.*.tar.gz
tar -xf httpd-$Ve.*.tar.gz
[ $? = 0 ] || { echo "解压出现问题 !";exit; }

echo "#安装"
mkdir -p $Sdir/http/{apr,apr-util,pcre}
cd $Ddir
#apr
cd apr-1.*
./configure --prefix=$Sdir/http/apr/
[ $? = 0 ] || { echo "编译出现问题 !";exit; }
make && make install
cd ..
#apr-util
cd apr-util-1.*
./configure --prefix=$Sdir/http/apr-util/ --with-apr=$Sdir/http/apr/
[ $? = 0 ] || { echo "编译出现问题 !";exit; }
make && make install
cd ..
#pcre
cd pcre-8.*
./configure  --prefix=$Sdir/http/pcre/
[ $? = 0 ] || { 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 
#
[ $? = 0 ] || { echo "编译出现问题 !";exit; }
echo 编译安装
make -j4 && make install
echo #编译模块查看
$Adir/bin/apachectl -l 

pkill `netstat -antp|grep 80|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进程解析,配置略

 


以上是关于apache编译安装 httpd 2.2 httpd 2.4的主要内容,如果未能解决你的问题,请参考以下文章

linux架构学习第二十六天之web服务搭建(apache)以及https的实现

编译安装LAMP环境:httpd-2.4+mysql5.6+php5.5

httpd安装与配置(编译安装)

apache-httpd2.4编译安装

编译安装Apache(httpd-2.4.18)

源码编译安装Apache,MySQL,PHP,LAMP构架