当前位置首页 > Apache知识

搭建LNAMP环境(三)-源码安装Apache2.4

阅读次数:338 次  来源:admin  发布时间:

上一篇:搭建LNAMP环境(二)- 源码安装Nginx1.10

1.yum安装编译apache需要的包(如果已经安装,可跳过此步骤)

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

2.创建apache用户组和用户

groupadd apache
useradd -r -g apache -s /sbin/nologin -M apache

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

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

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

这里用的是 httpd-2.4.23.tar.gz ,apr-1.5.2.tar.gz ,apr-util-1.5.4.tar.gz

apache下载地址: http://apache.fayea.com/httpd/httpd-2.4.23.tar.gz

apr下载地址: http://apache.fayea.com/apr/apr-1.5.2.tar.gz

apr-util下载地址: http://apache.fayea.com/apr/apr-util-1.5.4.tar.gz

4.进入src/目录

cd /usr/local/src/

5.解压apache源码包及依赖包

tar -zxf httpd-2.4.23.tar.gz
tar -zxf apr-1.5.2.tar.gz
tar -zxf apr-util-1.5.4.tar.gz

6.编译安装apr

cd /usr/local/src/apr-1.5.2

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

make && make install

注:如果./configure时出现报错:

error info:rm: cannot remove `libtoolT': No such file or directory

解决方法:

打开configure文件

vim configure

找到

$RM "$cfgfile"

改为

$RM -f "$cfgfile"

保存后再次执行即可

7.编译安装apr-util

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

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

make && make install

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

cd /usr/local/src/httpd-2.4.23

./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/

make && make install

9.修改apache配置文件httpd.conf

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

10.修改为下面内容,保存退出

#如果前面已经安装了nginx,为防止端口冲突,这里改为其他端口
Listen 8088

#用户组和用户改为apache
User apache
Group apache

#ServerName www.example.com:80
ServerName 127.0.0.1

11.修改apache目录权限

chown -R apache:apache /usr/local/apache

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

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

13.修改脚本httpd

vim /etc/init.d/httpd

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

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

第一行3个数字参数意义分别为:哪些Linux级别需要启动httpd(3,4,5);启动序号(85);关闭序号(15)

15.将apache加入系统服务

chkconfig --add httpd

16.修改服务的默认启动等级

chkconfig httpd on

17.启动apache

service httpd start

访问URL,如:http://192.168.8.9:8088/

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

Apache安装完毕!

下一篇:搭建LNAMP环境(四)- 源码安装PHP7

上一篇:ApacheSolr访问权限控制
下一篇:NGINX:查看并发连接数