CentOS 7 在最小化安装之后进行安装Apache服务,httpd-2.4.34

此博文是CentOS 7 在最小化安装之后进行安装Apache服务的操作步骤,httpd版本为httpd-2.4.34。

 

一、基本服务环境搭建

 

安装apache需要的基本环境:apr apr-util pcre gcc gcc-c++ expat-devel

Yum install -y gcc gcc-c++ (apr依赖于gcc)

Yum install -y expat-devel (apr-util依赖于expat-devel)

 

二、安装httpd-2.4.34以及各依赖包

 

1.编译安装apr包

 

wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz

tar -zxvf apr-1.6.3.tar.gz

cd apr-1.6.3

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

Make && make install

 

 

2.编译安装apr-tuil包

 

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz

tar -zxvf apr-util-1.6.1.tar.gz 

cd apr-util-1.6.1

./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/(此处编译需要添加之前安装的APR的路径)

make && make install

 

 

3.编译安装pcre包

 

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz

tar -zxvf pcre-8.42.tar.gz 

cd pcre-8.42

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

make && make install

 

4.编译安装httpd-2.4.34

 

wget http://mirrors.shu.edu.cn/apache//httpd/httpd-2.4.34.tar.gz

tar -zxvf httpd-2.4.34

cd httpd-2.4.34

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

Make && make install

 

 

三、Apache服务配置选项

 

1.编辑httpd.conf文件,添加本地地址为访问地址

 

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

 

#ServerName www.example.com:80(在此处添加servername)

ServerName localhost:80

 

 

2.查看防火墙状态

 

查看防火墙是否关闭,如未关闭则关闭防火墙

firewall-cmd –state

systemctl stop firewalld(此命令为临时关闭,系统重启后Firewall会重新启动,永久关闭命令为syctemctl disable firewalld)

 

 

3.启动hattd服务

 

/usr/local/apache/bin/apachectl start 

 

 

 

4.设置apache开机自动启动

 

首先拷贝apachectl到目录/etc/init.d/,执行命令

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

vim /etc/init.d/httpd 脚本首行添加以下两行 

# chkconfig: 2345 71 71 

# description: Apache is a world wide web server

注意:2345 是指改服务可以随系统的2345启动级别启动和停止,71 71 两个数字分别指启动顺序和停止顺序。

 

 

 

5.将httpd添加为开机启动

 

chkconfig --add httpd

这行命令的意思是在/etc/rc.d/rc*/ 添加/etc/init.d/httpd这个文件

chkconfig --list |grep httpd 查看是否将httpd添加为系统服务

chkconfig httpd on 开启开机启动httpd服务

 

 

 

6.修改网页页面属性

 

vim  /usr/local/httpd-2.4.34/htdocs/index.html

加属于你自己的设置页面

然后在本地浏览器中输入本地主机IP地址,如显示如下图即安装成功

12.jpg

 

posted @ 2019-04-17 17:22  飞花落叶飘雪  阅读(484)  评论(0编辑  收藏  举报