httpd 源码安装 CentOS 64位

本文档详细记录了在CentOS 6.5环境下从源码安装Apache HTTP Server (HTTPD)的过程,包括安装前的环境配置、依赖软件安装、解决编译错误等步骤。

记录一下第一次源码安装httpd

操作系统:CentOS 6.5最小化安装(VMware)


准备工作:

1关闭iptables:

service iptables stop

chkconfig iptables off


验证是否关闭

iptables -vnL



2:关闭selinux

setenforce 0

vi /etc/selinux/config

修改红框部分

验证是否关闭

getenforce


3:yum安装一些准备软件,需要gcc编译器,rzsz传输工具(因为源码包我保存在Windows本地,这款软件能够实现Windows到Linux系统之间的文件传输),vim编辑器

yum -y install gcc* lrzsz vim


4:检查系统时间,因为要上传安装源码包,系统的时间要跟源码包的时间一致,不能使源码包的时间超前于系统时间

date

时间不太准确,
这里我将自己本地PC设置为NTP服务器(参考:http://www.jb51.net/os/windows/131624.html)

CentOS上NTP同步一下时间


5使用rz命令把保存在本地的源码包上传到Linux


源码包下载地址:

http://apr.apache.org/

http://mirrors.hust.edu.cn/apache/httpd/


==============================正式编译


(1) 编译安装apr

# tar xf apr-1.4.6.tar.bz2
# cd apr-1.4.6
# ./configure --prefix=/usr/local/apr
# make && make install

(2) 编译安装apr-util

# tar xf apr-util-1.5.2.tar.bz2
# cd apr-util-1.5.2
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install


(3)编译安装httpd,由于httpd编译过程需要依赖pcre-devel软件包否则会报错libpcre not found的错

,因此我们先yum安装

#yum -y install pcre-devel


# tar xf httpd-2.4.6.tar.bz2
# cd httpd-2.4.6
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=most --with-mpm=event
# make && make install

结果编译的时候报错:出现configure: WARNING: OpenSSL version is too old;checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures;


解决方法:

openssl源码下载地址http://www.openssl.org/source/  下载源码

#tar -xf openssl-1.0.2.tar.gz
#cd openssl-1.0.2
# ./config --prefix=/usr/local/openssl

# make & make install


再次编译

# cd httpd-2.4.6
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --enable-mods-shared=most --with-mpm=event --with-ssl=/usr/local/openssl
# make && make install


结果编译的时候报错如下

/usr/bin/ld: /usr/local/openssl/lib/libssl.a(s3_srvr.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/openssl/lib/libssl.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[4]: *** [mod_ssl.la] Error 1
make[4]: Leaving directory `/root/httpd-2.4.6/modules/ssl'
make[3]: *** [shared-build-recursive] Error 1
make[3]: Leaving directory `/root/httpd-2.4.6/modules/ssl'
make[2]: *** [shared-build-recursive] Error 1
make[2]: Leaving directory `/root/httpd-2.4.6/modules'
make[1]: *** [shared-build-recursive] Error 1
make[1]: Leaving directory `/root/httpd-2.4.6'
make: *** [all-recursive] Error 1

网上查找到(http://www.linuxidc.com/Linux/2014-10/107919p2.htm)

openssl重新编译

openssl编译:
./config --prefix=${destination_dir} -fPIC no-gost no-shared no-zlib
 make depend ; make install


再次编译httpd


==============================================稍做修改

一般pid文件放置在如下位置,但是可以看到httpd编译完之后并没有放置于此

ls /var/run/







### 在 CentOS 9 上配置和使用 httpd 安装源 在 CentOS 9 上安装和配置 Apache HTTP 服务器(httpd),需要确保系统环境已更新,并通过 YUM 源或其他方式完成安装。以下是详细的说明和步骤: #### 系统准备 在开始之前,必须确保服务器运行的是 CentOS 9,并且具有 root 权限或可以使用 `sudo` 命令的用户账户[^1]。 #### 更新系统 为了保证安装过程顺利进行,首先需要更新系统软件包: ```bash sudo dnf update -y ``` 此命令会确保所有系统组件处于最新状态,避免因版本冲突导致的问题[^1]。 #### 安装 httpd 服务 在 CentOS 9 中,可以通过 `dnf` 包管理器直接安装 httpd 服务: ```bash sudo dnf install httpd -y ``` 此命令会从默认的 CentOS 9 YUM 源中下载并安装 Apache HTTP 服务器[^3]。 #### 配置防火墙 如果防火墙处于启用状态,则需要开放 HTTP(80 端口)和 HTTPS(443 端口)以允许外部访问: ```bash sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --add-service=https --permanent sudo firewall-cmd --reload ``` 上述命令将永久性地开放 HTTP 和 HTTPS 服务,并重新加载防火墙规则以使更改生效[^3]。 #### 启动和验证 httpd 服务 启动 httpd 服务并设置为开机自启: ```bash sudo systemctl start httpd sudo systemctl enable httpd ``` 检查服务状态以确认其正常运行: ```bash sudo systemctl status httpd ``` 此外,可以通过以下命令验证端口监听情况: ```bash sudo netstat -lnpt | grep httpd ``` 如果一切正常,应能看到类似以下输出: ``` tcp6 0 0 :::80 :::* LISTEN 1234/httpd ``` 这表明 httpd 服务正在监听 TCP 80 端口[^5]。 #### 自定义 YUM 源 如果需要配置自定义 YUM 源(例如本地 ISO 或局域网源),可以参考以下步骤: 1. 将 ISO 文件挂载到 `/mnt/iso` 目录。 2. 复制 ISO 内容到 Web 根目录: ```bash sudo cp -r /mnt/iso/* /var/www/html/CentOS-9/ ``` 3. 启动 httpd 服务并确保其正常运行。 4. 其他服务器可以通过网络访问该 YUM 源,例如: ``` http://<服务器IP>/CentOS-9/ ``` #### 使用 ./configure 脚本(可选) 如果需要从源代码编译安装 httpd,可以参考以下步骤: 1. 下载并解压 Apache 源代码。 2. 执行配置脚本以指定安装路径和其他选项: ```bash ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so ``` 3. 编译并安装: ```bash make && make install ``` --- ### 注意事项 - 如果遇到 SELinux 相关问题,可以临时禁用 SELinux 或调整其策略以适应 httpd 的运行需求[^3]。 - 在生产环境中,建议配置 HTTPS 以提高安全性。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值