apache编译安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache编译安装相关的知识,希望对你有一定的参考价值。

cetos7.4下编译安装:
Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。同时Apache音译为阿帕奇!(引用网络中的词)
需要源码编译安装的软件包
httpd-2.4.28.tar.gz #Apache主程序包
apr-1.5.2.tar.gz #Apache依赖包
apr-util-1.5.4.tar.gz #Apache依赖包
pcre-8.41.tar.gz #Apache依赖包

下载源码安装包
http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.28.tar.gz http://archive.apache.org/dist/apr/apr-1.6.2.tar.gz
http://archive.apache.org/dist/apr/apr-util-1.6.0.tar.gz
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
首先下载最新的源码包
安装之前请先安装make、gcc、openssl等编译工具和开发包
[[email protected] ~]# yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel

安装依赖包:apr-1.5.2.tar.gz
[[email protected] ~]# tar xf apr-1.5.2.tar.gz
[[email protected] ~]# cd apr-1.5.2
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr && make && make install
编译安装依赖包apr-util-1.5.4.tar.gz
[[email protected] ~]# tar xf apr-util-1.5.4.tar.gz
[[email protected] ~]# cd apr-util-1.5.4
[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/bin/apr-1-config && make && make install
编译安装依赖包pcre-8.41.tar.gz
[[email protected] pcre-8.41]# tar xf pcre-8.41.tar.gz
[[email protected] ~]# cd pcre-8.41
[[email protected] pcre-8.41]# ./configure --prefix=/usr/local/pcre && make && make install

编译安装apache
[[email protected] ~]# tar xf httpd-2.4.28.tar.gz -C /usr/local/src/
[[email protected] ~]# cd /usr/local/src/httpd-2.4.28/
[[email protected] httpd-2.4.28]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/ && make && make install
注:
--enable-so #支持动态加载模块
--enable-rewrite #支持网站地址重写
--enable-ssl #支持ssl加密
--with-apr=/usr/local/apr #关联apr
--with-apr-util=/usr/local/apr-util #关联apr-util
--with-pcre=/usr/local/pcre #关联pcre
--libdir=/usr/lib64 #关联库文件
配置文件
[[email protected] httpd-2.4.28]# ls /usr/local/apache/conf/httpd.conf
/usr/local/apache/conf/httpd.conf
网站根目录
[[email protected] httpd-2.4.28]# ls /usr/local/apache/htdocs/
index.html
生成启动脚本
[[email protected] httpd-2.4.28]# cp /usr/local/apache/bin/apachectl /etc/init.d
[[email protected] httpd-2.4.28]# chmod +x /etc/init.d/apachectl

写个apache系统服务脚本, 以754的权限保存此文件
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

启动apache报错:
[[email protected] httpd-2.4.28]# /etc/init.d/apachectl restart
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName‘ directive globally to suppress this message

解决:
[[email protected] httpd-2.4.28]# vim /usr/local/apache/conf/httpd.conf
改成:
ServerName 192.168.140.138(服务器IP):80

启动apache
/etc/init.d/apachectl start

测试:
技术分享图片

以上是关于apache编译安装的主要内容,如果未能解决你的问题,请参考以下文章

apache动静态编译

源码编译安装apache

Linux编译安装Apache+PHP

手工编译安装Apache网站(源码包编译安装)

Apache编译安装

编译安装Apache