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

相关内容