Linux Apache2安装

Apache2安装:

文件下载:

 httpd-2.4.33.tar.gz    http://httpd.apache.org/download.cgi

apr-1.6.3.tar.gz     apr-util-1.6.1.tar.gz    https://apr.apache.org/download.cgi

pcre-8.39.tar.gz     ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/


版本根据需要匹配,文章版本不同请忽略...


1)解压   tar -zxvf httpd-2.4.25.tar.gz

2)安装

./configure

报错:configure: error: APR not found.  Please read the documentation.

查阅文档以后发现需要事先安装很多的依赖

3)APR

tar -zxvf apr-1.5.2.tar.gz

./configure --prefix=/usr/local/apr

--prefix表示将apr安装到哪个目录,建议大家都加上该参数设置安装目录,以便于后续查找使用

make

make install

安装apr时运行./configure --prefix=/usr/local/apr时报如下错:

configure: error: in `/software/apr-1.5.2':

configure: error: no acceptable C compiler found in $PATH See `config.log' for more details

原因及解决办法:

你的机器里没有安装任何C语言编译器,可以安装gcc。 可以在安装盘里找到gcc相关的包进行安装,不过会比较繁琐,因为关联的包会比较多。 如果可以上网,使用yum安装是比较好的选择: yum install gcc

安装完gcc之后,再重新执行./configure --prefix=/usr/local/apr命令时就不会报错。

4)再次安装httpd

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr

报错:configure: error: APR-util not found.  Please read the documentation.

5) APR-util

tar -zxvf apr-util-1.5.4.tar.gz

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

make

如果报错

需要expat-devel  使用命令:yum -y install expat-devel

make install

6)再次安装httpd

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config

又报错:

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

7)pcre

tar -zxvf pcre-8.39.tar.gz

./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config

make

make install

安装pcre执行明令./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config时,报如下错:

configure: error: You need a C++ compiler for C++ support.

原因及解决办法:

你的机器里没有安装任何C++语言编译器,可以通过,命令yum install gcc-c++安装c++编译器。

安装完c++之后,再重新执行./configure --prefix=/usr/local/pcre --with-apr=/usr/local/apr/bin/apr-1-config命令时就不会报错。

8)再次安装httpd

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre=/usr/local/pcre/bin/pcre-config  

终于没有问题了

make

make install

9) 修改配置文件: /usr/local/apache/conf/httpd.conf

Listen 9999

启动Apache2

./apachectl -k start

报错如下:

AH00557: httpd: apr_sockaddr_info_get() failed for kgc

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

修改配置/usr/local/apache/conf/httpd.conf,增加如下内容:

ServerName localhost:9999

再次启动,启动后通过netstat -ltnp命令查看端口状态

./apachectl -k start/stop/restart 表示 启动/停止/重启

注意:如果外网不能访问,需要关闭防火墙service iptables stop

或者将对应的端口(9999)开放:

                直接编辑/etc/sysconfig/iptables文件

               1.编辑/etc/sysconfig/iptables文件:vi /etc/sysconfig/iptables
                   加入内容并保存:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
               2.重启服务:/etc/init.d/iptables restart
               3.查看端口是否开放:/sbin/iptables -L -n

猜你喜欢

转载自blog.csdn.net/qq_42237676/article/details/80902742