Linux学习之编译安装Apache


一、编译安装Apache 步骤:

1.建立源码包存放的路径:[root@wei ~]# mkdir -P /usr/local/src/apache/

2.进入该路径:[root@wei ~]# cd /usr/local/src/apache/

3.下载源码包 :[root@wei apache]# wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.2.25.tar.gz 如果没有wget命令就先下载 并安装wget 软件 在redhat 系列下用 yum -y install wget ,在ubuntu下用apt-get 命令

4.解压该源码包:[root@wei apache]# tar zxvf httpd-2.2.25.tar.gz 解压完成后会在当前路径下看到解压后的文件夹 httpd-2.2.25

5.进入httpd-2.2.25文件夹:[root@wei apache]#cd httpd-2.2.25

6.生成makefile文件: [root@wei httpd-2.2.25 ]# ./configure --prefix=/usr/local/apache-2.2.25 --enable-so --enable-mods-shared=most --with-mpm=worker 注意执行这一步之前要确保已安装GCC编译器

7.编译: [root@wei httpd-2.2.25 ]#make

8.安装: [root@wei httpd-2.2.25 ]#make install

9.启动Apache服务: [root@wei httpd-2.2.25 ]#/usr/local/apache-2.2.25/bin/apachectl start 注意该路径下的apachectl文件就是apache服务的控制脚本

10.将该服务加入系统自启动项: echo "/usr/local/apache-2.2.25/bin/apachectl start" >> /etc/rc.local 这一步是可选的

11.将apache加入到系统服务,以后就可以用service来控制apache的启动和停止,方便操作。

这一步是可选的 加入步骤:

1.复制一份apache控制脚本到系统服务的目录下:grep -v "#" /usr/local/apache-2.2.25/bin/apachectl > /etc/init.d/apache

2.修改该脚本,使其支持chkconfig命令 vi /etc/init.d/apache 在文件最前面插入下面的行
    #!/bin/sh
# chkconfig: 2345 85 15

3.退出vi 编辑器,增加该脚本的执行权限 chmod +x /etc/init.d/apache

4. 将Apache服务加入到系统服务: chkconfig --add apache

5.检测服务是否生效 chkconfig --list apache 如果输出类似下面的结果就表明生效: apache 0:off 1:off 2:on 3:on 4:on 5:on 6:off 至此就可以方便操作apache服务了, 启动Apache服务: service apache start

停止Apache服务: service apache stop

执行下面的命令关闭开机自启动: chkconfig apache off

执行下面的命令改变开机自启动的运行级别为3、5: chkconfig --level 35 apache on

二、测试结果:在其他计算机浏览器访问Apache所在的主机出现“It works” 前提:修改Apache所在主机的防火墙设置,让其允许80端口的访问配置:(1)修改防火墙设置:在Shell下输入命令 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

(2)保存上面的设置:/etc/rc.d/init.d/iptables save

(3)重启防火墙:/etc/init.d/iptables restart

相关内容