编译安装httpd 2.4

简介:

编译安装LAMP之:编译安装httpd 2.4

环境介绍:

    系统环境:CentOS6.5

所需软件包:apr-1.5.2.tar.gz、apr-util-1.5.2.tar.gz、httpd-2.4.6.tar.gz


  注意:httpd2.4需要依赖apr和arp-util 1.4以上版本


  CentOS编译安装Apache准备:确保开发包组已安装(Development tools、Server Platform Development) 

yum groupinstall "Development Tools" "Server Platform Development" -y


安装依赖:

1、下载官方源码包并解压:


httpd-2.4需要较新版本的apr(1.4以上)和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行。


wget http://archive.apache.org/dist/httpd/httpd-2.4.6.tar.bz2

wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz  

wget http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz


1.1 安装apr:


    [root@Server src]# tar xf apr-1.5.2.tar.gz 

    [root@Server src]# cd apr-1.5.2.tar.gz

    [root@Server apr-1.5.2]# ./configure --prefix=/usr/local/apr

    [root@Server apr-1.5.2]# make

    [root@Server apr-1.5.2]# make install

说明:编译时报错提示 rm: cannot remove `libtoolT': No such file or directory

      解决:直接打开 configure,把 $RM “$cfgfile” 那行删除掉,重新再运行 ./configure 就可以了。


1.2 安装apr-util


    [root@Server src]# tar xf apr-util-1.5.2.tar.gz

[root@Server src]# cd apr-util-1.5.2

    [root@Server apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

    [root@Server apr-util-1.5.2]# make

    [root@Server apr-util-1.5.2]# make install



编译说明:


    --prefix指定安装路径;


    --with-apr指定apr的安装路径,apr-util依赖于apr


2、编译安装httpd

2.1 安装依赖:


    [root@Server src]# yum -y install pcre-devel openssl-devel


2.2 编译安装


    [root@Server src]# tar xf httpd-2.4.6.tar.bz2

    [root@Server src]# cd httpd-2.4.6

    [root@Server httpd-2.4.6]# ./configure \

    --prefix=/usr/local/apache \

    --sysconfdir=/etc/httpd \

    --enable-so \

    --enable-rewrite \

    --enable-ssl \

    --enable-cgi \

    --enable-cgid \

    --with-zlib \

    --with-pcre \

    --enable-modules=most \

    --enable-modules-shared=most \

    --enable-mpms-shared=all \

    --with-mpm=event \

    --with-apr=/usr/local/apr \

    --with-apr-util=/usr/local/apr-util


    [root@Server httpd-2.4.6]# make

    [root@Server httpd-2.4.6]# make install


编译说明:


    --prefix=/usr/local/apache :指定安装目标路径

    --sysconfdir=/etc/httpd :指定配置文件安装位置

    --enable-so :支持动态共享模块,如果没有这个模块PHP将无法与apache结合工作;DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效

    --enable-rewirte :支持URL重写

    --enable-ssl :启用支持ssl 支持SSL/TLS,可实现https访问 需已安装openssl-devel

    --enable-cgi :启用支持cgi (默认情况下启用非线程MPM)

    --enable-cgid : 启用支持cgid (默认情况下启用线程MPM )

--with-zlib : 支持zlib压缩,传输层的压缩(不指定具体的路径,默认在系统中搜索)

    --with-pcre : 支持正则化(不指定具体的路径,默认在系统中搜索)

    --enable-modules=most :支持动态启用的模块,可选参数:all,most,few,reallyall

    --enable-mods-shared=most :安装大多数共享模块,可选参数:all,most,few,reallyall (可选)

    --enable-mpms-shared=all :支持全部多道处理方式

--with-mpm :#设置默认启用的MPM模式,{prefork|worker|event}

    --with-apr=/usr/local/apr :指定apr路径

    --with-apr-util=/usr/local/apr-util :指定apr-util路径


3、配置httpd 2.4(基于域名的虚拟主机)

[root@Server ~]# vim /etc/httpd/httpd.conf

# DocumentRoot "/usr/local/apache/htdocs"    # 注释掉DocumentRoot关闭主服务配置段

Include /etc/httpd/extra/httpd-vhosts.conf    # 启用虚拟主机功能



4、配置虚拟主机配置文件

[root@Server ~]# vim /etc/httpd/extra/httpd-vhosts.conf

<VirtualHost 192.168.100.11:80>

    ServerAdmin webadmin@parparxy.com

    DocumentRoot "/usr/local/apache/htdocs/test1/"

    ServerName test1.parparxy.com

    ErrorLog "logs/test1-error_log"

    CustomLog "logs/test1-access_log" common

</VirtualHost>

<VirtualHost 192.168.100.11:80>

    ServerAdmin webadmin@parparxy.com

    DocumentRoot "/usr/local/apache/htdocs/test2/"

    ServerName test2.parparxy.com

    ErrorLog "logs/test2-error_log"

    CustomLog "logs/test2-access_log" common

</VirtualHost>



5、生成测试网页

[root@Server ~]# cd /usr/local/apache/htdocs/

[root@Server htdocs]# mkdir test1 && echo "<h1> test1 </h1>" > test1/index.html

[root@Server htdocs]# mkdir test2 && echo "<h1> test2 </h1>" > test2/index.html



6、测试脚本文件语法是否正确

[root@Server ~]# ln -sv /usr/local/apache/bin/httpd /usr/bin/

`/usr/bin/httpd' -> `/usr/local/apache/bin/httpd'

[root@Server ~]# httpd -t

Syntax OK


7、为httpd执行文件创建PATH:


    # vi /etc/profile.d/httpd.sh #添加如下一行


    export PATH=$PATH:/usr/local/apache/bin

8、启动apache服务

[root@Server httpd-2.4.6]# apachectl start

[root@Server httpd-2.4.6]# netstat -tunlp | grep 80

tcp        0      0 :::80                       :::*                        LISTEN      23850/httpd         

[root@Server httpd-2.4.6]# 



9、头文件输出给系统:

# ln -sv /usr/local/apache/include /usr/local/include/httpd


10、为httpd执行文件创建PATH:


    # vi /etc/profile.d/httpd.sh #添加如下一行


    export PATH=$PATH:/usr/local/apache/bin让系统重新生成库文件路径缓存:

    # ldconfig -v |grep "^[^[:space:]]"


11、为httpd执行文件创建PATH:


    # vi /etc/profile.d/httpd.sh #添加如下一行


    export PATH=$PATH:/usr/local/apache/bin为日志文件创建软连接:


    # ln -fs /usr/local/apache/logs /var/log/httpd ##设置软链接以适应init脚本

# apachectl start 默认的启动apache方式


至此,就可以使用service httpd start 命令启动httpd了。



12、配置启动脚本:


[root@Server httpd-2.4.6]# cp build/rpm/httpd.init /etc/init.d/httpd //使用init脚本管理httpd

[root@Server httpd-2.4.6]# chmod 755 /etc/init.d/httpd //增加执行权限

[root@Server httpd-2.4.6]# chkconfig --add httpd //添加httpd到服务开机启动

[root@Server httpd-2.4.6]# ln -sf /usr/local/apache/bin/httpd /usr/sbin/httpd




问题:

Apache启动出现:

[root@Server httpd-2.4.6] service httpd restart

AH00557: httpd: apr_sockaddr_info_get() failed for linux.64.114

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


解决:

[root@Server httpd-2.4.6] vi /server/apache/conf/httpd.conf


修改ServerName www.example.com:80 为 ServerName localhost:80



首次启动服务,80端口未被监听:

# cat /usr/local/apache/logs/error_log

  报错提示:Resource Temporarily unavailable

  解决:

# ulimit -u unlimited   #修改 用户最大进程数  

# echo ulimit -u unlimited >>/etc/profile   #保存修改到自启动文件  



本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/1852827,如需转载请自行联系原作者

相关文章
|
5天前
|
弹性计算 运维 Shell
一键编译安装Httpd-2.4.53
【4月更文挑战第30天】
9 1
|
5月前
|
Ubuntu 应用服务中间件 PHP
Ubuntu 非手动编译安装 PHP8 和 Nginx
Ubuntu 非手动编译安装 PHP8 和 Nginx
50 0
|
关系型数据库 PHP MySQL
httpd编译安装php
wget http://hk1.php.net/distributions/php-5.6.31.tar.gz yum groupinstall "Development Tools" yum install zlib openssl perl yum install httpd httpd-devel tar -xf php.
1045 0
|
应用服务中间件 nginx C语言
编译安装 nginx
编译安装 ngixn
1167 0
|
Java 应用服务中间件 nginx
hi-nginx-1.3.4编译安装
hi-nginx既是 web 服务器,也是 application 服务器。它开源在https://github.com/webcpp/hi-nginx 它是NGINX的超集,因此与编译NGINX稍有不同。
885 0
|
应用服务中间件 nginx
|
Web App开发 网络安全 Apache
|
开发工具 缓存 Apache
|
应用服务中间件 nginx Ruby
|
监控 关系型数据库 应用服务中间件