1、需要额外安装的软件
apr、apr-util、pcre
2、安装apr
yum install gcc libtools -y
# 下载apr压缩文件
wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.gz
tar -zxvf apr-1.6.3.tar.gz
cd apr-1.6.3
./configure --prefix=/usr/local/apr # prefix=/usr/local/apr是apr的安装目录
make && make install
3、安装apr-util
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
4、安装pcre库
yum install gcc-c++ -y
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure --prefix=/usr/local/pcre
make && make install
5、安装apache
wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
tar -zxvf httpd-2.4.33.tar.gz
cd httpd-2.4.33
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make && make install
6、配置apache
·修改端口
cd /usr/local/apache/conf/
vim httpd.conf
# 找到Listen 80,将80修改为你要的端口
# 找到ServerName www.example.com:80, 将其修改为ServerName localhost:80 80修改为你要的端口
·添加apache到Linux服务
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/
mv /etc/rc.d/init.d/apachectl /etc/rc.d/init.d/httpd
cd /etc/rc.d/init.d/
vi httpd
## 在第一行下添加如下三行文字
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 90 90
# description:http server
·注册服务
chkconfig --add httpd #所有开机模式下自启动
chkconfig httpd on #345开机模式下自启动
·配置环境变量
vi /etc/profile
# 在最后一行加入
PATH=$PATH:/usr/local/apache/bin
# 保存退出
source /etc/profile
·启停apache的命令
service httpd start # 启动
service httpd stop # 停止
service httpd restart # 重启
apachectl -k start # 启动
apachectl -k stop # 停止
网友评论