Centos7.9源码编译安装Apache

下载Apache源码包

下载源码包:https://downloads.apache.org//httpd/httpd-2.4.46.tar.gz
使用FileZilla将httpd-2.4.46.tar.gz上传到CentOS服务器

下载并安装依赖包

依赖包:install gcc gcc-c++ zlib-devel openssl apr apr-util prce
服务器能连通外网的话可以直接 yum install 以上的依赖
我这里有3个包(apr apr-util )没有yum源,所以我手动下载编译安装这三个依赖包。
下载地址: wget http://archive.apache.org/dist/apr/apr-1.7.0.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
wget https://sourceforge.net/projects/pcre/files/pcre/8.43/pcre-8.43.tar.gz
注意:apr-util不要使用1.6版本,因为编译Apache编译没报错,但make时报了一堆undefined reference to `XML_xxxxxxxxxx’错误,网上说是不能使用最新的1.6版本,所以我就使用了1.5版本)
使用FileZilla将上述三个tar包上传到CentOS服务器

安装依赖包和Apache服务器

tar -xvfz apr-1.7.0.tar.gz
tar -xvfz apr-util-1.5.4.tar.gz #先全部解压缩
tar -xvfz pcre-8.43.tar.gz
tar -xvfz httpd-2.4.46.tar.gz

cd apr-1.7.0 #先编译安装apr依赖包
./configure --prefix=/usr/local/apr #指定安装路径为 /usr/local/apr
make
make install #安装没报错即可,有报错具体看下是什么错误再解决

cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #指定安装路径为 /usr/local/apr-util 并指定apr的路径
make
make install #安装没报错即可,有报错具体看下是什么错误再解决

cd pcre-8.43
./configure --prefix=/usr/local/prce #指定安装路径为 /usr/local/prce
make && make install #安装没报错即可,有报错具体看下是什么错误再解决

开始编译安装Apache
cd httpd-2.4.46
./configure --prefix=/usr/local/apache \ #指定Apache安装路径为/usr/local/apache,其他的自己写需要启用的功能
–with-apr=/usr/local/apr
–with-apr-util=/usr/local/apr-util
–with-prce=/usr/local/prce

make
make install #安装没有报错,安装完成

启动Apache服务

在这里插入图片描述
启动之前先修改一下配置文件
cd /usr/local/apache
vim conf/httpd.conf
找到#ServerName www.example.com:80 将#号去掉。
开始启动Apache服务
cd bin/
./apachectl -k start
lsof -i:80 #查看httpd服务是否启动
http://192.168.43.120:80/ #网页测试查看服务是否正常,出现It works! 这样表示Apache安装成功。

猜你喜欢

转载自blog.csdn.net/MssGuo/article/details/115312244