Linux源码安装

源码安装

通过源码包进行源码安装,源码包能直接看到源码,安装时需要人为手工设置安装位置,一般是/usr/local/软件名/。

  • 优点:
    1、开源的,可以自行修改代码
    2、安装的时候可以自定义功能,按需选择功能
    3、编译安装,更加适合系统,
    4、卸载方便,直接删除安装目录
  • 缺点:
    1、步骤多,难度大
    2、编译时间长
    3、错误新手比较难解决

我们已经了解到的什么是源码安装,以及它的优缺点,那么接下来我们开始尝试以源码安装的方式安装httpd。

一.首先我们需要了解并作出以下准备:
1.安装相应编译工具:通过yum安装工具  wget gcc  gcc-c++  gcc-g77  expat-devel
2.分析安装平台
3.下载源码包:
     官方站点:http://mirror.bit.edu.cn/apache/apr/
4.保存位置:usr/local/src
二.编译安装程序源码包步骤
      1、./configure  软件配置和系统检查
	  	 a.指定安装路径 --prefix=/usr/local/apache
	  	 b.启用禁用功能  --enable-ssl
	  	 c.与其他软件关联 --with-apr
	  	 4.检查
	  	 定义好的功能和检测的安装环境信息写入到 makefile文件中,
	  2、 make
	  3、 make install
	  注意:如果make出错 需要执行 make clean    并且最好重新 ./configure
	  4、PREFIX/bin/*ctl   start  
	  5、cp  PREFIX/bin/*ctl  /etc/rc.d/init.d/httpd 
	  		service  httpd  start
三.做好以上的了解和准备我们便可以开始进行源码安装了。

使用官方站点的链接安装如下

  [root@centos6 ~]# cd /usr/local/src
  [root@centos6 src]# weg http://mirror.bit.edu.cn/apache/httpd/httpd- 2.4.41.tar.gz

但由于我无法打开外网网址,所以我选择将所需的源码包下载到电脑后拖入ssh工具中。在这里插入图片描述
但通常情况下我们还是在Linux系统中通过wget命令将源码包下载到Linux系统。

接下来就是将下载好的源码包进行解压。

 根据源码包的后缀,来选择合适的解压方法。我们将会用到以下两种。
 *.tar.gz tar -xzvf 解压
*.tar.bz2 tar -xjvf 解压

由于我提前准备 好了所有的源码包就将他们全都一次解压了。结果如下:在这里插入图片描述
下面我们开始软件配置系统检查,并指定安装路径

  [root@centos6 src]# cd httpd-2.4.41
  [root@centos6 httpd-2.4.41]# ./configure --prefix=/usr/local/apache
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found.  Please read the documentation.
APR安装:

我们可以看到error报错提示我们缺少关联软件APR
于是我们需要安装APR软件,原本也应到官方站点进行下载,但我已经下载好了,切都解压好并存在了/usr/local/scr目录下,所以我们只需进行以下操作:

[root@centos6 httpd-2.4.41]# cd ..
[root@centos6 src]# cd apr-1.6.5
[root@centos6 apr-1.6.5]# ./configure -- prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
......
config.status: executing libtool commands
rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands
config.status: include/apr.h is unchanged
config.status: include/arch/unix/apr_private.h is unchanged
[root@centos6 apr-1.6.5]# make && make install
......
[root@centos6 apr-1.6.5]# cd ..
[root@centos6 src]# cd httpd-2.4.41
[root@centos6 httpd-2.4.41]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
......
library...
configure:
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.
APR-util的安装:

现在有给我们报错没有找到APR-util,所以我们需要进行APR-util的安装,和APR的安装如出一辙。

[root@centos6 httpd-2.4.41]# cd ..
[root@centos6 src]# cd apr-util-1.6.1
[root@centos6 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
......
configure: error: APR could not be located. Please use the --with-apr option.

诶,看来也不是完全如出一辙,给我们报错提示需要with关联到APR。那我们就关联一下吧。

[root@centos6 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
......
config.status: include/private/apu_config.h is unchanged
config.status: executing default commands
[root@centos6 apr-util-1.6.1]# make && make install
......
[root@centos6 apr-util-1.6.1]# cd ..
[root@centos6 src]# cd httpd-2.4.41
[root@centos6 httpd-2.4.41]# ./configure --prefix=/usr/local/apache --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/
pcre的安装:

由于我们提前做好了准备,过程还是很顺利的,现在又出现了报错提示需要我们安装pcre,通过前两次的安装,对于流程应该没什么问题了。

[root@centos6 httpd-2.4.41]# cd ..
[root@centos6 src]# cd pcre-8.42
[root@centos6 pcre-8.42]# ./configure --prefix=/usr/local/pcre
......
[root@centos6 pcre-8.42]# make && make install
......
[root@centos6 pcre-8.42]# cd ..
[root@centos6 src]# cd httpd-2.4.41
[root@centos6 httpd-2.4.41]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
......
[root@centos6 httpd-2.4.41]# make && make install
......

当执行完后,会自动给我们创建一些目录文件在这里插入图片描述
于是我们切换到/usr/local/apache进行查看
在bin目录中存放着开启命令apachectl
于是我们执行 ./apachectl start启动服务。

[root@centos6 httpd-2.4.41]# cd /usr/local/apache
[root@centos6 apache]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@centos6 apache]# cd bin
[root@centos6 bin]# ls
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root@centos6 bin]# ./apachectl start

可惜临门一脚出现报错
在这里插入图片描述
apache的端口被占用了,这是怎么回事呢?
原来在之前的尝试中我们启动过apache,并且没有关闭,所以现在才无法再次启动apache。
由于我们之前是系统启动的apache,所以需要通过service命令来关闭之前的启动。

  [root@centos6 bin]# cd /etc/httpd/conf
  [root@centos6 conf]# service httpd stop
  Stopping httpd:                                            [  OK  ]

OK,这样我们在回到/usr/local/apache目录中完成后续操作。
在这里插入图片描述
很好,这样我们就可以在网页中打开ip地址进行查看了。
如果还是无法查看只需要iptables -F一下修改防火墙的状态就可以了。
在这里插入图片描述

总结:

以上就是我第一次进行源码安装的全过程。虽然在过程中总会遇到各种各样的错误,但办法总比困难多,不断的尝试,不断的错误,越挫越勇,必定能取得最后的成功。虽然说不上有多困难,但确实是只有不断的试错才能更好了理解学习。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值