Linux 下 Apache 的安装与配置

1、安装APR (Apache Portable Runtime)

wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
tar -zxf apr-1.4.5.tar.gz
cd apr-1.4.5 
./configure --prefix=/usr/local/apr  
make && make install

2、安装APR-util

wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
tar -zxf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

3、安装PCRE (Perl Compatible Regular Expressions)

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
unzip -o pcre-8.10.zip
cd pcre-8.10  
./configure --prefix=/usr/local/pcre  
make && make install

4、下载 Apache

wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.37.tar.gz
tar -zxvf httpd-2.4.37.tar.gz

5、源码迁移

mv apr-1.4.5 httpd-2.4.37/srclib/apr
mv apr-util-1.3.12 httpd-2.4.37/srclib/apr-util

6、安装 Apache

cd httpd-2.4.37/
./configure --prefix=/usr/local/apache --with-included-apr --with-pcre=/usr/local/pcre --disable-proxy

make && make install

7、修改配置

vi /usr/local/apache/conf/httpd.conf

ServerName 127.0.0.1:80

 否则启动会报如下错误:

AH00557: httpd: apr_sockaddr_info_get() failed for iZ2zed10hr1jgfe2mlfegZ
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

8、启动Apache服务

/usr/local/apache/bin/apachectl restart

# 检测是否成功
curl 127.0.0.1:80
<html><body><h1>It works!</h1></body></html>

9、寻找网页根目录

find / -name httpd.conf
vi /usr/local/apache/conf/httpd.conf
DocumentRoot "/usr/local/apache/htdocs"

10、最后别忘了用 iptables 开放 80 端口供外部访问 (INPUT 和 OUTPUT 都需要)

iptables -I OUTPUT -d 0.0.0.0/0 -p tcp --sport 80 -j ACCEPT
iptables -I INPUT -s 0.0.0.0/0 -p tcp --dport 80 -j ACCEPT

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

英雄哪里出来

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值