摘要:很多朋友在初步接触linux很头疼,对于源码包的的安装没有头绪,源码包都经过配置–编译–安装三部,最后还有安装完成后的配置,下面介绍下linux下安装apache的步骤
下面是linux下安装apache的完整代码,系统是redhat5.5
下载httpd-2.2.6.tar.bz2 把httpd-2.2.6.tar.bz2放到/soft 下
[root@localhost ~]#cd /soft
[root@localhost soft]#tar jxvf httpd-2.2.6.tar.bz2 //解压apache的压缩包
[root@localhost soft]#cd httpd-2.2.6 //定位到httpd-2.2.6 文件夹下
[root@localhost httpd-2.2.6]#ls //查看显示httpd-2.2.6 文件夹下内容
[root@localhost httpd-2.2.6]#./configure –help | more //查看安装apache配置参数
[root@localhost httpd-2.2.6]#./configure –prefix=/usr/local/apache –enable-so // 配置apache路径
[root@localhost httpd-2.2.6]#make //编译apache
[root@localhost httpd-2.2.6]#make install //安装apache
[root@localhost httpd-2.2.6]#cd /usr/local/apache //进入apache的目录
[root@localhost apache]# cd conf/
[root@localhost conf]#cp -a httpd.conf httpd.conf- //备份apache配置文件
[root@localhost conf]#chkconfig –list httpd //查看httpd服务是否已存在
[root@localhost conf]#chkconfig httpd off //关闭系统自带了httpd的服务,如果存在httpd服务
[root@localhost conf]#service httpd status //查看自带httpd服务状态
[root@localhost conf]#/usr/local/apache/bin/apachectl -k start //linux启动apache命令
[root@localhost conf]#netstat -an | grep :80 //查看linux80端口是否开启
[root@localhost conf]#ps -aux | grep httpd //linux下查看apache进程
[root@localhost conf]#cd ../..
[root@localhost local]#cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache //拷贝apache启动脚本
[root@localhost local]#vi /etc/rc.d/init.d/apache // 这里是编辑apache启动脚本
在开头的#!/bin/sh 下面加上
#chkconfig: 2345 85 15
[root@localhost local]#chkconfig –add apache //添加apache服务
[root@localhost local]#chkconfig –list apache //列出apache服务
[root@localhost local]#service apache stop //停止apache服务
[root@localhost local]#netstat -an | grep :80 //查看linux的80端口是否关闭
[root@localhost local]#ps -aux | grep httpd //查看是否存在httpd服务,若果之前自带httpd服务启动的话会导致新添加的apache服务启动失败
[root@localhost local]#service apache start //启动apache服务
打开你的服务器ip地址,看看是否出现了tomcat的默认首页,如果出现的话,那么恭喜你
linux下安装apache已经成功了
可能出现的错误情况:
1.打不到gcc组件
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/ken/httpd-2.2.22/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
configure failed for srclib/apr
可以考虑用yum来安装
yum install gcc
2.make命令没发现
make: command not found
是一些相关的软件没有安装,如:gcc automake autoconf libtool make
ubuntu debian 可以直接 apt-get install gcc automake autoconf libtool make
redhat centos: yum -y install gcc automake autoconf libtool make
3.
备注:Apache启动之后会提示错误:
正在启动httpd:httpd: Could not reliably determine the server's fully qualif domainname, using ::1 for ServerName
解决办法:
vi /usr/local/apache/conf/httpd.conf #编辑
找到 #ServerName www.example.com:80
修改为ServerName localhost:80 #这里设置为你自己的域名,如果没有域名,可以设置为localhost
:wq! #保存退出