Linux 源码安装httpd

本文详细介绍如何从源码安装Apache及相关依赖组件,包括apr、apr-util和pcre,并配置Apache的基本设置,如设置ServerName、修改站点目录等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装apr

下载解压apr-1.4.5 

./configure --prefix=/usr/local/apr
make
sudo make install

安装apr-util

下载解压apr-util-1.5.2

./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr
make
sudo make install

安装pcre

下载解压pcre-7.8.tar.gz

./configure --prefix=/usr/local/pcre
make
sudo make install

安装httpd

下载解压httpd-2.4.12

./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite
make
sudo make install

--enable-so 支持DSO模式(动态模块加载方式)
--enable-rewrite 支持rewrite(地址重定向)

建立软链接

sudo ln -s /usr/local/httpd/bin/apachectl /usr/local/bin/apachectl

启动

sudo apachectl start

启动异常

$sudo ./apachectl start

AH00557: httpd: apr_sockaddr_info_get() failed for test10.125.8.116
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

原因:这个问题应该是没有在 /etc/httpd/conf/httpd.conf 中设定 ServerName。所以apache会用主机上的名称来取代,首先会去找 /etc/hosts 中有没有主机的定义。

解决:在/etc/httpd/conf/httpd.conf中添加上ServerName=****

验证

打开浏览器输入ip,显示It works! 表示成功了。

添加网页

文件:/usr/local/httpd/htdocs/test.html

内容

<html>
<body>
<h1>
Test works OK!
</h1>
</body>
</html>

重启服务

sudo apachectl restart

验证

配置

1. 修改Web站点目录

默认的Web站点目录:/usr/local/apache2/htdocs,如果修改,例如"/home/gyw/WebSite"的目录作为apache的站点目录

  找到DocumentRoot这一行修改为:DocumentRoot "/home/gyw/WebSite"

  找到 <Directory> 这一行修改为:<Directory "/home/gyw/WebSite"> 

 

  

 

转载于:https://www.cnblogs.com/kaituorensheng/p/5162560.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值