banner
moeyy

moeyy

一条有远大理想的咸鱼。
github
mastodon
email

Centos7手动编译安装apache

前言:现在很多人搭建 web 环境选择了一键脚本或可视化管理面板,因此我认为在使用一键脚本之前,一定要自己搭建一次, 生产环境的话,炸了都不知道怎么快速解决可就太难受了,另外就是安全性问题,这个不多谈,总之能不用就不用吧 刚好最近手边有台小内存吃灰 VPS,手动搭个 apache 做下载站吧

【1】编译安装需要 gcc 套件

yum install -y gcc gcc-c++

【2】 编译安装 Apr

官网最新版下载页面:http://apache.communilink.net/apr/

image

找到开头是 apr,tar.gz 后缀的文件,复制链接,然后 wget 它

cd /root
wget http://apache.communilink.net/apr/apr-1.6.5.tar.gz
tar zxf apr-*
cd apr-*
./configure --prefix=/usr/local/apr && make && make install

image

安装成功是这样的

【3】编译安装 Apr-util

image

找到开头是 apr-util, tar.gz 后缀的文件,复制链接,然后 wget 它

cd /root
wget http://apache.communilink.net/apr/apr-util-1.6.1.tar.gz
tar zxf apr-util*
cd apr-util*
./configure --prefix=/usr/local/apr && make && make install

如果报错 configure: error: APR could not be located. Please use the –with-apr option. ,则使用这条命令编译

./configure --with-apr=/usr/local/apr && make && make install

如果报错 xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory,则是缺少 expat-devel

yum install -y expat-devel

然后重新编译即可

image

编译成功是这样的

【4】 安装 openssl (版本不够高的话装 apache 会报错)

官网下载地址https://www.openssl.org/source/

image

我是随便找了个版本号最高的,然后 wget 它

cd /root
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar zxf openssl*
cd openssl*
./config -fpic --prefix=/usr/local/openssl && make && make install

【5】安装 pcre

官方下载页面https://ftp.pcre.org/pub/pcre/ 找个最新版本直接 wget,和上面一样,后缀要是 tar.gz

cd /root
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
tar zxf pcre-*
cd pcre-*
./configure --prefix=/usr/local/pcre && make && make install

【6】上面的这些操作都是为 Apache 准备的,接下来开始安装 Apache

Apache 的包名是 httpd 而不会 apache 官方下载页面http://apache.communilink.net/httpd/

image

找到开头是 httpd, tar.gz 后缀的文件,复制链接,然后 wget 它

cd /root
wget http://apache.communilink.net/httpd/httpd-2.4.37.tar.gz
tar zxf httpd-*
cd httpd-*
./configure --prefix=/usr/local/httpd && make && make install

某些情况下发生报错: configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ ,可以选择再 yum 安装一次 pcre

yum -y install pcre-devel

然后继续编译 /usr/local/httpd/conf/httpd.conf 是 apache 的配置文件 启动 apache 命令:

/usr/local/httpd/bin/apachectl start

启动之后,直接访问自己的 IP,应该会显示一行 “It works!”,恭喜你,搭建成功 将 apache 加入开机运行

echo "/usr/local/httpd/bin/apachectl start" >> /etc/rc.local

默认网页文件位置

/usr/local/httpd/htdocs/index.html

也都 注意:如果做到这里 httpd 已经启动但是无法访问可能造成原因有以下几种: 1. 清除浏览器缓存后再次访问。 2. 没有关闭 selinux 会出现访问不到的情况 3. 没有关闭防火墙,则需要添加 80 端口,或者可以选择关闭防火墙

本文基于《署名 - 非商业性使用 - 相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权 转载原创文章请注明,转载自: 沧水的博客 » Centos7 手动编译安装 apache

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。