Linux系统如何安装Apache

发布时间:2022-01-24 10:55:00 作者:小新
来源:亿速云 阅读:174

这篇文章主要介绍了Linux系统如何安装Apache,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

Apache是一个开放 源码的Web服务器,可以运行在所有使用的计算机平台上,成为最流行的web服务器端软件。

Apache简介:

压缩包安装方式

1、下载httpd-2.4.29.tar.gz

2、上传到服务器/usr/local/software

 tar -zxvf httpd-2.4.29.tar.gz``./configure --prefix=/usr/local/apache2/ # 设置apache安装目录

若没有安装过Apr,会报错:

 checking ``for` `APR... no``configure: error: APR not found. Please read the documentation.

3、接下来安装apr,首先下载apr-1.6.3.tar.gz

4、上传到服务器/usr/local/software

 tar -zxvf apr-1.6.3.tar.gz``cd apr-1.6.3``.configure``make``make install

又会报错:

 checking ``for` `APR-util... no``configure: error: APR-util not found. Please read the documentation.

5、下载apr-util-1.6.1.tar.gz

6、上传到服务器/usr/local/software

 tar -zxvf apr-util-1.6.1.tar.gz``cd apr-util-1.6.1``./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr

此时还会报错:

 xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录`` ``#``include` ```          ``^``编译中断。``make: *** [xml/apr_xml.lo] 错误 1

7、猜测是可能缺expat的开发库

 yum install expat-devel # 中间会让你输入y``./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr``make # 成功!``make install

8、此时再回去安装apache,不仅要指定apr的路径,还要指定apr-util的路径

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

依旧报错,不少人到这里可能已经崩溃了,但这个错误跟前面遇到的类似

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

9、下载pcre-8.41.tar.gz

10、上传到服务器/usr/local/software

 tar -zxvf pcre-8.41.tar.gz``./configure

又再次报错,我保证这是最后一次了

 checking windows.h usability... no``checking windows.h presence... no``checking ``for` `windows.h... no``configure: error: You need a C++ compiler ``for` `C++ support.

10、安装c++环境

 yum install -y gcc gcc-c++``# 错了那么多次,别忘了现在的位置,接下来还是要安装pcre``./configure``make``make install

11、好了,绕了一大圈,接下来还是要安装apache

 cd ..``cd apache``./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/``make``make install

好惨啊!最后一步又报错:

 
 /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
 
 /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
 
 /usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserCre
 
 collect2: error: ld returned 1 exit status
 
 make[2]: *** [htpasswd] 错误 1
 
 make[2]: Leaving directory `/usr/local/software/apache/support'
 
 make[1]: *** [all-recursive] 错误 1
 
 make[1]: Leaving directory `/usr/local/software/apache/support'

这种报错没见过,果断网上搜索一番,答案即是:apr版本太高;

12、于是我下载了apr-util-1.5 http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

13、上传到服务器/usr/local/software

 tar -zxvf apr-util-1.5.2.tar.gz``cd apr-util-1.5.2``./configure --prefix=/usr/local/apr-util-1.5/ --with-apr=/usr/local/apr``make``make install

14、重复步骤11,唯一不同的地方就是现在配置指定的是:apr-util-1.5,这很重要!!!

 cd ..``cd apache``./configure --prefix=/usr/local/apache2/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util-1.5/``make # make时间会比较长``make install

完美结尾:

 Installing configuration files
 
 mkdir /usr/local/apache2/conf
 
 mkdir /usr/local/apache2/conf/extra
 
 mkdir /usr/local/apache2/conf/original
 
 mkdir /usr/local/apache2/conf/original/extra
 
 Installing HTML documents
 
 mkdir /usr/local/apache2/htdocs
 
 Installing error documents
 
 mkdir /usr/local/apache2/error
 
 Installing icons
 
 mkdir /usr/local/apache2/icons
 
 mkdir /usr/local/apache2/logs
 
 Installing CGIs
 
 mkdir /usr/local/apache2/cgi-bin
 
 Installing header files
 
 mkdir /usr/local/apache2/include
 
 Installing build system files
 
 mkdir /usr/local/apache2/build
 
 Installing man pages and online manual
 
 mkdir /usr/local/apache2/man
 
 mkdir /usr/local/apache2/man/man1
 
 mkdir /usr/local/apache2/man/man8
 
 mkdir /usr/local/apache2/manual
 
 make[1]: Leaving directory `/usr/local/software/apache

15、进入配置文件位置:/usr/local/apache2/conf

 cp httpd.conf httpd.conf.bak  # 备份配置文件``vim httpd.conf``# 放掉191行的注释,修改为:``ServerName [你的IP]:80``:wq

16、启动apache

 /usr/local/apache2/bin/apachectl start``# 或者``/usr/local/apache2``//bin/httpd -k start

关闭防火墙,在浏览器地址栏中输入服务器的ip就会出现网页:It works!

17、关闭apache

 ps -ef|grep apache``/usr/local/apache2/bin/apachectl stop``# 或者``/usr/local/apache2``//bin/httpd -k stop``# 没错,bin前面就是``//

这种原文件安装的方式太过复杂,其实安装apache服务还有另一种方式,不知道跟我前面这种安装有没有冲突,今天也一并试一试。

yum源安装方式

1、yum源安装(需要联网下载)

 首先关闭apache服务``yum install httpd # 中间过程中输入:y

Result:

作为依赖被安装:

 apr.x86_64 0:1.4.8-3.el7_4.1    
 
   apr-util.x86_64 0:1.5.2-6.el7      
 
   httpd-tools.x86_64 0:2.4.6-67.el7.centos.6    
 
   mailcap.noarch 0:2.1.41-2.el7

2、yum的安装位置在:/etc/httpd/conf,我进入后备份配置文件先,修改的地方跟之前不一样,在95行,仅供参考

 
 cd /etc/httpd/conf
 
 cp httpd.conf httpd.conf.bak
 
 # 放掉95行的注释,修改为:
 
 ServerName [你的IP]:80
 
 :wq

3、启动服务

 systemctl start httpd.service

在浏览器输入ip,出现apache预置的html,完美!!!

Linux系统如何安装Apache4、关闭服务

 systemctl stop httpd.service

5、我再次去启动第一种方式安装的httpd

 /usr/local/apache2/bin/apachectl start

刷新浏览器赫然出现:It works!,说明两种安装方式没有冲突哈。

感谢你能够认真阅读完这篇文章,希望小编分享的“Linux系统如何安装Apache”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. 如何安装Apache 2.4.18
  2. apache编译安装

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

linux apache

上一篇:Linux系统如何安装git

下一篇:Linux系统如何安装chef

相关阅读

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

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