您的位置:首页 > 运维架构 > Apache

centos7.2源码安装Apache2.4

2017-02-14 03:36 501 查看
ps:学了这么久计算机了一直是想到什么查什么,下次又要用时又忘了.总是这样无休止的循环下去,今天终于决定改变一下了,写个博客做个总结吧.

centos7.2源码安装Apache2.4

以前总是用yum安装软件,因为yum工具非常方便会帮你把依赖软件也一起装了,后来发现yum也不是那么好用,有时候死活装不上软件…..

服务器环境是centos7.2(目前最新),由于服务器重装后,现在服务器非常干净什么也没有先来做一些准备吧.

安装相关软件包gcc gcc++ zlib zlib-devel

yum -y install gcc gcc++ zlib zlib-devel#如果报错可以试试一个一个的安装


下载所需软件源码包

Apache

Apr:http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

Apr-Util:http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz(或者点击这里下载apr和apr-Util其他版本)

pcre:http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz (点击这里下载其他版本)

apache:http://apache.cs.utah.edu//httpd/httpd-2.4.25.tar.gz(点击或者这里下载其他版本)

可以使用linux的wget下载也可以在本地左面环境下载好了上传到服务器解

压软件包使用tar -xf 软件包

tar -xf  httpd-2.4.25.tar.gz #先用cd命令切换到软件包所在的目录,用ls命令查看当前目录内容


开始安装

安装apr

cd apr-1.5.2#进入解压的软件包目录里面
/*编译安装*/
./configure --prefix=/usr/local/apr/
make && make install


安装apr-Util

cd apr-1.5.4#进入解压的软件包目录里面
/*编译安装*/
./configure --prefix=/usr/local/apr-util/  --with-apr=/usr/local/apr/
make && make install


安装pcrel

cd pcre-8.40#进入解压的软件包目录里面
/*编译安装*/
./configure --prefix=/usr/local/pcre/
make && make install


安装Apache

cd httpd-2.4.25#进入解压的软件包目录里面
/*编译安装*/
./configure --prefix=/usr/local/apache24/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
make && make install


启动Apache

cd /usr/local/apache24/bin/
./apachectl start #开启:start 停止:stop 重启:restart
systemctl stop firewalld.service #顺便把防火墙关了
systemctl disable firewalld.service#不让防火墙开机自启动


添加Apache自启动

cp /usr/local/apache24/bin/apachectl /etc/rc.d/init.d/httpd
vim /etc/rc.d/init.d/httpd #编辑httpd文件


#!/bin/sh
下面添加以下两句后保存


#chkconfig: 345 70 70
#description: apache


chkconfig: 2345 70 60中的2345是指脚本的运行级别,即在2345这4种模式下都可以运行,234都是文本界面,5是图形界面X,70是指脚本将来的启动顺序号,如果别的程序的启动顺序号比70小(比如44、45),则脚本需要等这些程序都启动以后才启动。60是指系统关闭时,脚本的停止顺序号

把Apache添加到系统服务并自启

chkconfig --add httpd #加入系统服务
chkconfig httpd on #开机自启


这样就可以使用systemctl start|stop|restart httpd 启动|关|重启Apache服务了

配置文件在Apache的安装目录(也就是安装Apache时–prefix=xxxx所指定的目录)下的conf目录下的httpd.conf

vim /usr/local/apache24/conf/httpd.conf#修改Apache配置文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  服务器 centos apache