首页 Linux正文

LAMP架构之Apache 2.4(编译)

王昊 Linux 2019-07-28 263 0

LAMP架构之Apache(编译)

环境准备

#设置或停止防火墙:
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
#关闭selinux:
临时关闭:
[root@localhost ~]# setenforce 0

永久关闭(修改配置文件):
[root@localhost ~]# vim /etc/selinux/config
改成SELINUX=disabled

下载相关依赖

yum -y install gcc-c++ make pcre-devel apr-devel apr-util-devel expat-deve perl

下载所需的源码包

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.5.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget http://apache.fayea.com//httpd/httpd-2.4.38.tar.gz

apr

解压

tar xf apr-1.6.5.tar.gz

cd apr-1.6.5

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

错误提示:

rm: cannot remove 'libtoolT': No such file or directory

解决方法:

vim configure

将RM='$RM'这一行 修改为RM='$RM -f'

保存退出后,再次执行前面中断的命令

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

make && make install

cd ..

apr-util

cd apr-util-1.6.1

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

make && make install

cd ..

把插件放入http目录下

cp -r apr-1.6.5 /usr/local/httpd-2.4.38/srclib/apr

cp -r apr-util-1.6.1 /usr/local/httpd-2.4.38/srclib/apr-util

apache

tar xf httpd-2.4.38.tar.gz

cd httpd-2.4.38

./configure 
-prefix=/usr/local/apache \
-enable-so \
-with-apr=/usr/local/apache/apr/ \
-with-apr-util=/usr/local/apache/apr-util/ \
-with-pcre=/usr/local/apache/pcre/

make && make install

将httpd服务添加到系统服务

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

vim /etc/init.d/httpd

# chkconfig: 35 85 21 
# description: Apache is a World Wide Web server

注意:“ # ” 不能省略

将httpd加入到service管理器

chkconfig –add httpd

给服务脚本赋予执行权限

chmod 755 /etc/init.d/httpd

设置httpd开机启动

chkconfig httpd on

修改httpd的主配置文件

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

优化执行路径(执行程序文件的原路径不在PATH环境变量中,做个软链接使其可以执行

ln -s /usr/local/apache/conf/httpd.conf /etc/

ln -s /usr/local/apache/bin/* /usr/local/bin/

检查语法

httpd -t

检查版本

httpd -v

启动服务

systemctl start httpd

查看运行状态

systemctl status httpd.service

浏览器访问

http://IP

Apache官网:http://www.apache.org/

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论