如何在Centos7下升级Apache至最新版本

Apache是使用最广泛的应用部署软件。并且它也是所有服务器的必要组成部分。安装最新版本的apache意味着拥有更多最新的功能和修复了已知的BUG。

介绍

在这篇教程里面,我将会介绍在Centos7下安装最新版Apache的几个简单步骤。

默认情况下, Centos7为软件设置了一些预定义的软件库。不幸的是,这些预定义软件库上的很多软件已近过时了。

第一步:找出默认软件库上的Apache版本

为了查找Centos上软件库里的Apache版本,在命令行下输入以下指令:

 
  1. yum info httpd  

如果你的centos保持着默认的配置的话,你很可能会按到类似的结果:

 
  1. [root@crosp ~]# yum info httpd  
  2. Loaded plugins: fastestmirror  
  3. epel/x86_64/metalink                                     |  19 kB     00:00  
  4. epel                                                     | 4.3 kB     00:00  
  5. (1/3): epel/x86_64/group_gz                                | 170 kB   00:00  
  6. (2/3): epel/x86_64/primary_db                              | 4.6 MB   00:00  
  7. (3/3): epel/x86_64/updateinfo                              | 780 kB   00:00  
  8. Loading mirror speeds from cached hostfile  
  9.  * base: mirrors.ircam.fr  
  10.  * epel: mirrors.ircam.fr  
  11.  * extras: centos.mirror.fr.planethoster.net  
  12.  * updates: centos.mirror.fr.planethoster.net  
  13. Available Packages  
  14. Name        : httpd  
  15. Arch        : x86_64  
  16. Version     : 2.4.6  
  17. Release     : 45.el7.centos.4  
  18. Size        : 2.7 M  
  19. Repo        : updates/7/x86_64  
  20. Summary     : Apache HTTP Server  
  21. URL         : http://httpd.apache.org/  
  22. License     : ASL 2.0  
  23. Description : The Apache HTTP Server is a powerful, efficient, and extensible  
  24.             : web server.  

正如你从上面的输出结果中看到,默认软件库中只有2.4.6版本的apache。

注意:

Centos使用 向后修复安全实践 来将新的软件修复应用到更早期的版本。所以,默认库中的早期版本软件不意味着就更脆弱。不过对于我来说,并不算是个满足需求的更新。

你可以使用changelog来查看版本更新:

 
  1. sudo yum install yum-changelog  
  2. yum changelog httpd  

第二步:安装CodeIT库

CodeIT的人提供了一个很好的自定义库。这个库提供了最新版本的服务器软件(Apache & Nginx)。

在安装CodeIT库之前,你需要开启 EPEL 。EPEL提供了CodeIT库需要的依赖。

 
  1. sudo yum install -y epel-release  

最后,我们来安装CodeIT库

 
  1. cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo  

接下来,我们再次确认Apache的包版本,你应该会看到类似下面的输出

 
  1. [root@crosp ~]# yum info httpd  
  2. Loaded plugins: changelog, fastestmirror  
  3. Loading mirror speeds from cached hostfile  
  4.  * base: centos.crazyfrogs.org  
  5.  * epel: mirror.23media.de  
  6.  * extras: mirrors.ircam.fr  
  7.  * updates: centos.mirror.fr.planethoster.net  
  8. Available Packages  
  9. Name        : httpd  
  10. Arch        : x86_64  
  11. Version     : 2.4.25  
  12. Release     : 3.el7.codeit  
  13. Size        : 1.4 M  
  14. Repo        : CodeIT/x86_64  
  15. Summary     : Apache HTTP Server  
  16. URL         : http://httpd.apache.org/  
  17. License     : ASL 2.0  
  18. Description : The Apache HTTP Server is a powerful, efficient, and extensible  
  19.             : web server.  

第三步:安装Apache

现在你应该有了安装最新版apache所需要的所有东西:

 
  1. yum install httpd  

一旦Apache安装好,我们就可以测试apache是否正常工作:

 
  1. [root@crosp ~]# systemctl start httpd  

输出应该是类似下图:

 
  1. [root@crosp ~]# curl localhost  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  
  3.   
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">  
  5.     <head>  
  6.         <title>Test Page for the Apache HTTP Server on CentOS</title>  
  7.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  8.                 ...  

最后,让systemctl将Apache设置为开机自启动:

 
  1. [root@crosp ~]# systemctl enable httpd  
大功告成!

 

 
posted @ 2018-05-14 16:14  柠檬没我萌  阅读(1235)  评论(0编辑  收藏  举报