Linux编译安装Apache的详细过程
LAMP 是 Linux Apache MySQL PHP 的简写,其实就是把 Apache,MySQL 以及 PHP安装在 Linux 系统上,组成一个环境来运行 PHP 的脚本语言。Apache 是最常用的 WEB 服务软件,所以安装Apache必不可少,其中编译安装Apache又尤为重要,接下来我一步步来编译安装Apache。具体步骤:
1,准备工作:首先保证有Linux系统的PC或者服务器,我这里是CentOS6.8的64位的系统(最小化安装);然后得保证你系统能正常使用wget,因为需要它来下载我们说需要的东西;如果没有可以采用yum安装;
1
yum install -y wget
2,在apache的官网(或者其他途径)下载安装包;
1
wget http://apache.fayea.com//httpd/httpd-2.2.31.tar.gz
3、解压安装包;
1
tar zxvf httpd-2.2.31.tar.gz
4、创建一个安装目录;
1
mkdir /usr/local/apache2
5,进入解压后的目录;
1
cd httpd-2.2.31
6,编译安装;
./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared \--with-pcre
注意:--prefix 表示指定安装到哪里, --enable-so 表示启用DSO --enable-deflate=shared 表示共享的方式编译deflate,后面的参数同理。
出现的问题:
6.1,缺少zlib-devel包;
1
2
checking whether to enable mod_deflate... configure: error: mod_deflate has been
requested but can not be built due to prerequisite failures
解决办法:
1
yum install -y zlib-devel
6.2,缺少gcc的情况;
1
configure: error: no acceptable C compiler found in $PATH
解决办法:
1
yum install -y gcc
6.3、如果出现一些其他的问题,可以根据错误的意思进行yum安装相应的包;因为编译安装包与包之间会有对应的依赖关系;所以需要的包都不能缺少。
7,编译;这里会出现很多的动态代码,不用去管它,等待就好;
1
make
8,安装;
1
make install
注意:小技巧:我们每走一步可以通过“echo $?”来判断是否成功?输出为0,则成功没错误;输出为1就是失败,根据错误或者日志来查找错误即可。
1
2
# echo $?
0
9,进入安装目录,启动服务;
1
2
# cd /usr/local/apache2/bin/
# ./apachectl start
出现错误:
1
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
解决办法:修改Apache的配置文件;
1
# vim /usr/local/apache2/conf/httpd.conf
在100行的位置,vim命令模式下,光标放在100行,按下 yy,然后按下p;
1
100 #ServerName www.example.com:80
然后把#去掉,把“www.example.com”换成自己的IP地址,我这里换成之后变为
1
101 ServerName 10.0.151.189:80
最后:wp保存退出,再次启动服务;启动成功;
1
2
# ./apachectl start
httpd (pid 29725) already running
确保万无一失,我们可以查看是否启动:
1
2
# netstat -lnp |grep httpd
tcp 0 0 :::80 :::* LISTEN 29827/httpd
由于可能会受防火墙的影响,没办法检测成功,所以我先把防火墙关闭;
1
2
3
4
# service iptables stop
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
最后在浏览器输入ip地址;成功!
页:
[1]