【20200912】Apache2.4安装笔记

1. 介绍

1.1 介绍

在linux操作系统下面,apache是非常流行的web服务器,大部分生产环境都是使用apache作为web服务器的,apache和php是亲密搭档,所以学习php编程就一定要学会安装使用apache这个web服务器软件

2. 基本信息

2.1 安装环境

CentOS:CentOS Linux release 7.6.1810 (Core)

Linux:Linux version 3.10.0-1062.el7.x86_64

GCC:gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

2.2 软件版本

apr-1.6.5.tar.gz

apr-util-1.6.1.tar.gz

httpd-2.4.46.tar.gz

2.3 验证时间

2020/09/12

3. 准备工作

3.1 本地化

如果是新环境,我们需要设置时区以保证时间显示正确

timedatectl set-timezone Asia/Shanghai

3.2 安装wget

如果环境里没有wget,通过yum安装一下

yum -y install wget

3.3 安装gcc

如果环境里没有编译工具,通过yum安装一下

yum -y install gcc gcc-c++ make

3.4 安装依赖包

这些是apache依赖的软件库

yum -y install expat-devel pcre-devel openssl-devel perl libxml* curl-devel freetype-devel autoconf

3.5 建立环境根目录

建立软件安装根目录

mkdir -p /tongfu.net/env/

3.6 建立安装包目录并进入

建立软件安装包保存目录

mkdir /packages

cd /packages

4. 安装Apache 2.4

4.1 准备

apr-1.6.5.tar.gz

apr-util-1.6.1.tar.gz

httpd-2.4.46.tar.gz

4.2 下载安装包

下载apr,apr-util,httpd软件包

wget http://mirror.bit.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://mirror.bit.edu.cn/apache/httpd/httpd-2.4.46.tar.gz

4.3 百度网盘资源

4.3.1 apr-1.6.5.tar.gz

链接: https://pan.baidu.com/s/1-tpTzQy7KeoOLO5IPLsIqA 提取码: buyx

4.3.2 apr-util-1.6.1.tar.gz

链接: https://pan.baidu.com/s/14N5yMQKQQTOACrl4--PutA 提取码: f2fk

4.3.3 httpd-2.4.46.tar.gz

链接: https://pan.baidu.com/s/1BeLWykiEc0_9Txp7AH974g 提取码: uu7m

4.4 安装apr

tar xzvf apr-1.6.5.tar.gz

cd apr-1.6.5

./configure --prefix=/tongfu.net/env/apr-1.6.5

make && make install

cd ..

4.5 安装apr-util

tar xzvf apr-util-1.6.1.tar.gz

cd apr-util-1.6.1

./configure --prefix=/tongfu.net/env/apr-util-1.6.1 \

--with-apr=/tongfu.net/env/apr-1.6.5/bin/apr-1-config 

make && make install

cd ..

4.6 安装httpd

tar xzvf httpd-2.4.46.tar.gz

cd httpd-2.4.46

./configure --prefix=/tongfu.net/env/httpd-2.4.46 \

--with-apr=/tongfu.net/env/apr-1.6.5 \

--with-apr-util=/tongfu.net/env/apr-util-1.6.1 \

--with-pcre \

--enable-so \

--enable-rewrite \

--enable-ssl

make && make install

cd ..

4.7 初始化

打开 httpd.conf 配置文件

将 ServerAdmin 设置为 [email protected]

将 ServerName 设置为 localhost

将 Listen 设置为 8080

[root@tfdev]# vi /tongfu.net/env/httpd-2.4.46/conf/httpd.conf

ServerAdmin webmaster@localhost

ServerName localhost

Listen 8080

注意:为什么我们要把Apache的端口设置为 8080 呢?因为一般情况下Apache都是工作在Nginx后面的

4.8 启动

启动apache

/tongfu.net/env/httpd-2.4.46/bin/apachectl start

4.9 自动启动

添加系统服务脚本

[root@tfdev]# cat > /lib/systemd/system/httpd.service <

[Unit]

Description=httpd

After=network.target

[Service]

Type=forking

ExecStart=/tongfu.net/env/httpd-2.4.46/bin/apachectl start

ExecReload=/tongfu.net/env/httpd-2.4.46/bin/apachectl restart

ExecStop=/tongfu.net/env/httpd-2.4.46/bin/apachectl stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

EOF

使用 systemctl 管理 httpd 服务

systemctl enable httpd # 设置自动启动

systemctl start httpd # 启动服务

systemctl stop httpd # 停止服务

systemctl restart httpd # 重启服务

4.10 关闭防火墙

默认CentOS 7会开启防火墙,开发环境的话,直接将防火墙关掉就可以了

systemctl stop firewalld

systemctl disable firewalld

5. 测试

5.1 curl测试

通过curl命令测试

[root@fdev]# curl 'http://localhost:8080/'

It works!

5.2 浏览器测试

通过浏览器测试

【20200912】Apache2.4安装笔记 第 1 页 - 鬼谷子叔叔的主页 - 同福网 - TONGFU.net

你可能感兴趣的:(【20200912】Apache2.4安装笔记)