温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

RedHat 7怎样安装HTTPD

发布时间:2021-11-03 16:28:20 来源:亿速云 阅读:360 作者:柒染 栏目:建站服务器

这篇文章给大家介绍RedHat 7怎样安装HTTPD,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

1.查看操作系统版本

  1. [root@aws srclib]# cat /etc/redhat-release

  2. Red Hat Enterprise Linux Server release 7.4 (Maipo)

2.首先安装apr,本例子是1.6.3版本

  1. wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz

下载之后就是解压

  1. tar -xzvf apr-1.6.3.tar.gz

进入apr目录,执行configure命令,该命令本例就一个参数 ,设置安装目录

  1. cd /usr/local/src/apr-1.6.3

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

配置好之后,执行make和make install

  1. make && make install

3.安装apr-util,本例的版本是1.6.1

  1. wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2

在解压的时候有可能遇到报错:

  1. [root@aws src]# tar -jxvf apr-util-1.6.1.tar.bz2

  2. tar (child): bzip2: Cannot exec: No such file or directory

  3. tar (child): Error is not recoverable: exiting now

  4. tar: Child returned status 2

  5. tar: Error is not recoverable: exiting now

解决的办法是:

  1. yum -y install bzip2

接下来和安装apr一样,先运行configure命令

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

然后执行安装命令:

  1. make && make install

在安装过程中可能遇到如下错误:

  1. pr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo

  2. xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory

  3.  #include <expat.h>

  4.                    ^

  5. compilation terminated.

  6. make[1]: *** [xml/apr_xml.lo] Error 1

  7. make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1

解决办法是安装expat库

  1. yum install expat-devel

4.安装httpd

本例用的是2.4.29的版本

  1. wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz

同样下载后就是解压

  1. tar -xvzf  httpd-2.4.29.tar.gz

进入目录,执行configure命令

  1. ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most --with-included-apr


--enable-so的意思是启用DSO,也就是把某些功能以模块(so)的形式展现出来
--enable-mods-shared=most表示以共享的方式安装大多数功能模块,安装后会在modules目录下面看到。

如果遇到下面的报错:

  1. checking for gcc option to accept ISO C99... -std=gnu99

  2. checking for pcre-config... false

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

解决办法是:

  1. yum install -y pcre pcre-devel

最后编译和安装

  1. make

  2. make install

以上两个步骤都可以用命令echo $?来检查是否执行成功。

在make的时候可能会报错如下:

  1. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'

  2. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'

  3. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'

  4. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'

  5. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'

  6. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'

  7. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'

  8. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'

  9. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'

  10. /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'

  11. collect2: error: ld returned 1 exit status

  12. make[2]: *** [htpasswd] Error 1

  13. make[2]: Leaving directory `/usr/local/src/httpd-2.4.29/support'

  14. make[1]: *** [all-recursive] Error 1

  15. make[1]: Leaving directory `/usr/local/src/httpd-2.4.29/support'

  16. make: *** [all-recursive] Error 1

解决办法是:

  1. cp -rf /usr/local/src/apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr

  2. cp -rf /usr/local/src/apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util


5.至此httpd就安装完成了

可以用下面的命令查看安装了那些模块:

  1. [root@aws srclib]# /usr/local/apache2.4/bin/apachectl -M

  2. Loaded Modules:

  3.  core_module (static)

  4.  so_module (static)

  5.  http_module (static)

  6.  mpm_event_module (static)

  7.  authn_file_module (shared)

  8.  authn_core_module (shared)

  9.  authz_host_module (shared)

  10.  authz_groupfile_module (shared)

  11.  authz_user_module (shared)

  12.  authz_core_module (shared)

  13.  access_compat_module (shared)

  14.  auth_basic_module (shared)

  15.  reqtimeout_module (shared)

  16.  filter_module (shared)

  17.  mime_module (shared)

  18.  log_config_module (shared)

  19.  env_module (shared)

  20.  headers_module (shared)

  21.  setenvif_module (shared)

  22.  version_module (shared)

  23.  unixd_module (shared)

  24.  status_module (shared)

  25.  autoindex_module (shared)

  26.  dir_module (shared)

  27.  alias_module (shared)

  28.  php5_module (shared)

其中带有shared字样的,表示该模块为动态共享模块;static为静态模块。

动态和静态的区别是静态模块直接和主程序(/usr/local/apache2.4/bin/httpd)绑定在一起,我们是看不到的;而动态的模块都是一个个独立存在的文件,也就是modules目录下的.so文件

6.配置httpd支持php

a.编辑httpd.conf文件(/usr/local/apache2.4/conf/httpd.conf),搜索ServerName,把ServerName www.example.com:80前面的#去掉

b.找到如下内容

  1. <Directory />

  2.     AllowOverride none

  3.     Require all denied

  4. </Directory>

  5. 修改为

  6. <Directory />

  7.     AllowOverride none

  8.     Require all granted

  9. </Directory>

c.再搜索下面这一行

  1. AddType application/x-gzip .gz .tgz

  2. 在上面这行下面添加

  3. AddType application/x-httpd-php .php

d.找到下面这一段

  1. <IfModule dir_module>

  2.    DirectoryIndex index.html

  3. </IfModule>

  4. 修改为

  5. <IfModule dir_module>

  6.    DirectoryIndex index.html index.php

  7. </IfModule>

7.启动之前检查配置文件是否正确,出现Syntax OK,说明没有问题

  1. [root@aws php-5.6.30]# /usr/local/apache2.4/bin/apachectl -t

  2. Syntax OK


8.启动httpd的命令如下:

  1. /usr/local/apache2.4/bin/apachectl start

9.查看是否启动的命令如下:

  1. [root@aws srclib]# netstat -lnp | grep httpd

  2. tcp6       0      0 :::80                   :::* LISTEN      30298/httpd

10.做个简单测试,出现It works说明测试成功

  1. [root@aws srclib]# curl localhost

  2. <html><body><h2>It works!</h2></body></html>

关于RedHat 7怎样安装HTTPD就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI