centos 7.6安装 Apache HTTP Server
1、下载 Apache HTTP Server 2.4.58
1.1、Apache HTTP Server介绍
参考链接: https://httpd.apache.org/
Apache HTTP Server is the Number One HTTP Server On The Internet.
The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.
The Apache HTTP Server (“httpd”) was launched in 1995 and it has been the most popular web server on the Internet since April 1996. It has celebrated its 25th birthday as a project in February 2020.
The Apache HTTP Server is a project of The Apache Software Foundation.
1.2、下载安装包
官网下载链接: https://httpd.apache.org/download.cgi
下载2.4.58版本 此版本是稳定版
安装包信息:
安装包文件名:httpd-2.4.58.tar.gz
安装包sha256 哈希:503a7da4a4a27fd496037998b17078dc9fe004db32c657c96cce8356b8aa2eb6
2、安装 Apache HTTP Server 2.4.58
安装文档: https://httpd.apache.org/docs/2.4/install.html
本文选择从源码编译安装apache http server
2.1、第一步 下载依赖包
2.1.1、下载APR 和 APR-Util
ARP 全称是 Apache Portable Runtime library 就是一些底层的库文件
下载链接 https://apr.apache.org/download.cgi
文件信息
文件名:apr-1.7.4.tar.gz
sha 256 哈希:a4137dd82a185076fa50ba54232d920a17c6469c30b0876569e1c2a05ff311d9
文件名:apr-util-1.6.3.tar.gz
sha 256 哈希:2b74d8932703826862ca305b094eef2983c27b39d5c9414442e9976a9acf1983
2.1.2、下载Perl-Compatible Regular Expressions Library (PCRE)
链接: http://pcre.org/
链接: https://github.com/PCRE2Project/pcre2/releases
下载 pcre2-10.43.tar.gz
2.2、第二步 安装依赖包
2.2.1、安装APR 和 APR-Util
编译安装依赖包APR 和 APR-Util之前,需要安装libxml2-devel、expat-devel
yum install libxml2-devel
yum install expat-devel
编译安装依赖包APR
cd /path/to/apr-1.7.4.tar.gz
tar -xzvf apr-1.7.4.tar.gz
cd apr-1.7.4/
./configure --prefix=/usr/local/apr
make
make install
编译依赖包APR-Util
cd /path/to/apr-1.7.4.tar.gz
tar -xzvf apr-util-1.6.3.tar.gz
cd apr-util-1.6.3/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
2.2.2、安装Perl-Compatible Regular Expressions Library (PCRE)
解压安装包pcre2-10.43.tar.gz
查看解压目录下的 INSTALL 文件 这是安装文档
cd /path/to/pcre2-10.43.tar.gz/
tar -xzvf pcre2-10.43.tar.gz
cd pcre2-10.43/
./configure --prefix=/usr/local/pcre2
make
make install
configure截图
make截图
make install 截图
2.3、第三步 编译安装 Apache HTTP Server 2.4.58
需要注意configure apache http server 前 指定pcre的路径 并且安装pcre2-dev包
yum install pcre2-devel
解压apache http server安装包
cd /path/to/httpd-2.4.58.tar.gz
tar -xzvf httpd-2.4.58.tar.gz
cd httpd-2.4.58/
./configure --prefix=/usr/local/apache2 --with-pcre=/usr/local/pcre2/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make
configure 截图
make报错了(make如没有出现错误 直接make install即可)
fatal error: expat.h: No such file or directory
需要安装 expat-devel包
yum install expat-devel
然后再次make
make
make 截图
然后make install
make install
make install 截图
至此安装Apache HTTP Server 2.4.58 完成
查看Apache HTTP Server 版本
/usr/local/apache2/bin/httpd -version
查看apache http server 安装目录的目录结构
其中htdocs是 apache http server 的web根目录
其中index.html 的内容是 It works! 这个就是访问apache主页的显示内容
见下一节 访问访问 http://httpd-server-ip:80
3、配置 Apache HTTP Server 2.4.58 自启动
启动 Apache HTTP Server 命令
/usr/local/apache2/bin/apachectl -k start
查看启动 Apache HTTP Server 命令的 命令帮助
/usr/local/apache2/bin/apachectl -h
默认端口 80已经启动了
访问 http://httpd-server-ip:80 显示It works! 即为部署apache http server 成功
加入开机自启动
编辑 /etc/rc.local 文件
vi /etc/rc.local
在最后加入一行内容如下
nohup /usr/local/apache2/bin/apachectl -k start & >> /root/logs/httpdAutoStart.log 2>&1