mkdir /apache #创建一个Apache目录,位置随你们习惯
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.25.tar.bz2 #下载apache源码
tar -jxvf httpd-2.4.25.tar.bz2 #解压缩
编译时可能会有各种问题,比如
checking for APR... no
configure: error: APR not found . Please read the documentation
下载所需软件包:
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
解决过程中出现的问题:
1.apr not found问题
tar -zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=/usr/local/apr
make && make install
2.APR-util not found问题
tar -zxvf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install
3.pcre问题
unzip -o pcre-8.10.zip
cd pcre-8.10
./configure --prefix=/usr/local/pcre
make && make install
解决上述问题时可能出现gcc/g++:command not found,解决方法:
yum -y install gcc
rpm -qa | grep "g++" #检查是否缺失相应的包
yum whatprovides "*/g++" #确认未安装之后,查询可安装的包
yum install gcc-c++-XXXXXXXXX.x86_64 #利用yum安装查询到的包
安装apache:
cd httpd-2.4.25 #切换到httpd目录
./configure --prefix=/opt/httpd-2.4.25 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \
--enable-so \ #支持DSO模式(动态共享目标)
--enable-mods-shared=most \ #动态编译大部分常用的模块
--enable-proxy-balancer=shared \ #支持负载均衡
--enable-proxy-http=shared \ #http代理模块
--enable-proxy-ajp \ #proxy-ajp模块
--enable-rewrite #支持地址重写功能
make
make install
/opt/http-2.4.25//bin/apachectl start
#如果出现httpd: Could not reliably determine the server‘s fully qualified domain name
vi /opt/httpd-2.4.25/conf/httpd.conf
:?#ServerName
#新起一行添加ServerName localhost:80
:wq
/opt/httpd-2.4.25/bin/apachectl stop
cp /opt/httpd-2.4.25/bin/apachectl /etc/init.d/httpd #将apache的启动脚本复制到/etc/rc.d/init.d这个目录下
vi /etc/rc.d/init.d/apache
// 这里是编辑apache启动脚本,在开头的#!/bin/sh 下面加上 #chkconfig: 2345 85 15
chkconfig --add apache //添加apache服务
chkconfig --list apache //列出apache服务
/etc/init.d/httpd start #启动apache
netstat -lntp| grep 80 (netstat -an | grep:80) #检验apache已开启
lsof -i :80 #查看当前系统文件打开情况
wget http://192.168.10.254 #检验是否能访问
浏览器打开 192.168.10.254(It works!)
#浏览器访问不了可能是服务器防火墙开着
service apache status
service apache stop