CentOS 6.8 搭建LNAMP环境(三)- 源码安装Apache2.4.28

一、yum安装编译apache须要的包

yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel expat-develhtml

 二、下载apache源码包及依赖包apr和apr-util,将它们放到/usr/local/src/目录下

    源码包下载页面:http://httpd.apache.org/download.cginginx

    依赖包下载页面:http://apr.apache.org/download.cgiweb

三、进入/usr/local/src/目录,解压apache源码包及依赖包

cd /usr/local/src/apache

tar -zxvf httpd-2.4.28.tar.gz vim

tar -zxvf apr-1.6.2.tar.gz spa

tar -zxvf apr-util-1.6.0.tar.gz htm

四、编译安装apr

cd /usr/local/src/apr-1.6.2ip

./configure --prefix=/usr/local/aprssl

make && make installrem

注:若是./configure时出现报错: error info:rm: cannot remove `libtoolT': No such file or directory

 解决方法:

打开configure文件

vim configure

找到

$RM "$cfgfile"

改成

$RM -f "$cfgfile"

保存后再次执行便可

五、编译安装apr-util

cd /usr/local/src/apr-util-1.6.0

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

make && make install

六、编译安装apache(配置参数:http://httpd.apache.org/docs/2.4/programs/configure.html

cd /usr/local/src/httpd-2.4.28

./configure --prefix=/usr/local/apache --sysconfdir=/usr/local/apache/conf --enable-so --enable-cgi --enable-deflate --enable-rewrite --enable-modules=most --enable-mpms-shared=all --enable-ssl --with-ssl --with-z --with-pcre --with-zlib --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-included-apr

make && make install

注:若是./configure时出现报错:configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

解决方法:

cp -rf /usr/local/src/apr-1.6.2 /usr/local/src/httpd-2.4.28/srclib/apr

cp -rf /usr/local/src/apr-util-1.6.0 /usr/local/src/httpd-2.4.28/srclib/apr-util

再次执行便可。

七、修改apache配置文件httpd.conf

vim /usr/local/apache/conf/httpd.conf

#前面已经安装了nginx,为防止端口冲突,这里改成其余端口

找到:    Listen 80

改成:    Listen 8080

找到:    #ServerName www.example.com:80

改成:    ServerName 127.0.0.1:8080

找到:    DocumentRoot "/usr/local/apache/htdocs"     #默认web根目录 

改成:    DocumentRoot "/var/www/html"

找到:    <Directory "/usr/local/apache/htdocs">

改成:    <Directory "/var/www/html">

 

八、将apache服务脚本加入到init.d/目录

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

九、修改脚本httpd

vim /etc/init.d/httpd

在首行 #!/bin/sh 下面加入两行:

# chkconfig: 345 85 15
# description: Activates/Deactivates Apache Web Server

十、将apache加入系统服务

chkconfig --add httpd

十一、修改服务的默认启动等级(开机自启)

chkconfig httpd on

十二、启动apache

service httpd start

访问URL,如:http://192.168.198.119:8080/

注:若不能访问,则关闭防火墙

service iptables stop

页面显示正常,以下所示,则配置成功

Apache安装完毕!

相关文章
相关标签/搜索