Centos6.8 编译安装Apache2.4

cetos6.8源码安装apache2.4.29

apache官网: http://httpd.apache.org

具体安装步骤:

1 配置安装apache的基础环境
2 下载想要安装的版本源码包
3 解压,预编译,编译,安装
4 启动,停止,测试页面,检验是否安装成功
5 编写启动脚本,将apache添加为系统服务,设置为开机启动

=================================================================== 

1 配置安装环境:

yum -y install gcc gcc++ zlib zlib-devel 

卸载原有的Apache
rpm -qa|grep httpd
删除已经安装的所有httpd包
rpm -e --nodeps httpd-xxx-xxx.el6.xxx.x86_64

2 下载对应版本的包
wget http://mirrors.shuosc.org/apache//httpd/httpd-2.4.29.tar.gz


1)去http://httpd.apache.org/download 下载apache源码包

2)解压到/usr/src,在下载目录执行tar -zxvf httpd-x.x.x.tar.gz -C /usr/src (我用的是httpd-2.4.29.tar.gz)

3)进入目录/usr/src/httpd-2.4.29,

 # ./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl

4)出现configure: error: APR not found。解决办法:

  4.1)去apr下载地址 http://apr.apache.org/ 下载源码
  wget http://mirrors.shuosc.org/apache//apr/apr-1.6.3.tar.gz
  http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

  4.2)解压到/usr/src,在下载目录执行tar -zxvf apr-x.x.x.tar.gz -C /usr/src/ (我用的是apr- 1.6.3.tar.gz)

  4.3)进入目录/usr/src/apr-1.6.3,执行./configure --prefix=/usr/local/apr;make;make install

5)再次进入目录/usr/src/httpd-2.4.29,增加参数--with-apr=/usr/local/apr/

重新执行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/

6)出现configure: error: APR-util not found .解决办法

  6.1)去apr-util下载地址 http://apr.apache.org/ 下载源码
  wget http://mirrors.shuosc.org/apache//apr/apr-util-1.6.1.tar.gz
  http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

  6.2)解压到/usr/src,在下载目录执行tar -zxvf apr-util-x.x.x.tar.gz -C /usr/src/ (我用的是apr-util-1.6.1.tar.gz)

  6.3)进入目录/usr/src/apr-util-1.6.1,执行./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/;make;make install

  6.4)make的时候出现错误
xml/apr_xml.c:35:19: error: expat.h: No such file or directory
xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: In function ‘cleanup_parser’:
xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:365: error: ‘apr_xml_parser’ has no member named ‘xp’
  解决办法:可能是缺少expat库
    6.4.1)yum install expat-devel 安装之后再make;make install

7)再次进入目录/usr/src/httpd-2.4.29,增加参数--with-apr-util=/usr/local/apr-util/,重新执行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/

8)出现configure: error: pcre-config for libpcre not found.解决办法:

  8.1)去pcre下载地址 http://pcre.org/ 下载源码(注意:下载的时候一定不要下错了,不是pcre2 )
  wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

  8.2)解压到/usr/src,在下载目录执行tar -zxvf pcre-x.x.tar.gz -C /usr/src/ (我用的是pcre-8.40.tar.gz)

  8.3)进入目录/usr/src/pcre-8.31,执行./configure --prefix=/usr/local/pcre;make;make install

 

9)再次进入目录/usr/src/httpd-2.4.29,增加参数--with-pcre=/usr/local/pcre,重新执行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

10)出现configure: WARNING: OpenSSL version is too old;checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures;解决办法:

  10.1)openssl源码下载地址http://www.openssl.org/source/ 下载源码
  wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz

  10.2)解压到/usr/src,在下载目录执行tar -zxvf openssl-x.x.x.tar.gz -C /usr/src/ (我用的是openssl-1.0.2n.tar.gz)

  10.3)进入目录/usr/src/openssl-1.0.1c,执行./config --prefix=/usr/local/openssl shared;make;make install

 注意此处的shared选项,否则在httpd make的时候会报mod_ssl相关错误

 

11)再次进入目录/usr/src/httpd-2.4.3,增加参数--with-ssl=/usr/local/openssl,重新执行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-ssl=/usr/local/openssl ;预编译没有问题


make出现以下错误:
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/httpd-2.4.26/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/httpd-2.4.26/support'
make: *** [all-recursive] Error 1

解决办法发:centos6.8的系统使用1.6的apr 和apr-util版本太高了,需要降低版本,将apr和apr-util降为1.5的版本,在重新编译安装即可。下载地址如下:
http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz
http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

 


12)设置apache开机自动启动

首先拷贝apachectl到目录/etc/init.d/,执行命令sudo cp apachectl /etc/init.d/httpd
vim /etc/init.d/httpd 脚本首行添加以下两行
# chkconfig: 2345 71 71
# description: Apache2.4 is a world wide web server
注意:2345 是指改服务可以随系统的2345启动级别启动和停止,71 71 两个数字分别指启动顺序和停止顺序。
13)将httpd添加为开机启动
chkconfig --add httpd
这行命令的意思是在/etc/rc.d/rc*/ 添加/etc/init.d/httpd这个文件
chkconfig --list |grep httpd 查看是否将httpd添加为系统服务
chkconfig httpd on 开启开机启动httpd服务

14)去浏览器输入127.0.0.1,可以显示apache自带的网页It works。该网页的默认目录是在/usr/local/apache2/htdocs/。apache到此就安装OK了。

 

posted @ 2018-01-15 10:42  日拱一卒,聚沙成塔  阅读(1753)  评论(0编辑  收藏  举报