apache2.4.27编译安装

简介:

#apache 2.4编译安装#

第1步:安装gcc编译器。

yum  install  -y   gcc   gcc-c++   openssl-devel   pcre  pcre-devel

说明:openssl-devel是让apache支持ssl安全套接字功能。

因为rewirte重写功能需要pcre-devel支持。所以要安装pcre和pcre-devel软件。

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。pcre来解决C语言中使用正则表达式的问题。


或者下载pcre,编译安装

tar  zxvf pcre-8.31.tar.gz

cd  pcre-8.31

./configure && make && make install

说明:默认安装在/usr/local/目录中。


第2步:准备软件包。

从http://httpd.apache.org下载最新的httpd、apr、apr-util,然后解压缩。

tar zxvf apr-1.5.1.tar.gz 

tar zxvf apr-util-1.5.4.tar.gz 

tar zxvf httpd-2.4.27.tar.gz


由于现在最新的httpd-2.4都需要apr、apr-util。

APR功能:(Apache portableRun-timelibraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。

方法一:插入方法安装

说明:插入方法安装(即内嵌apr软件包),在编译httpd-2.4.7的同时编译安装apr软件。

mv  apr-1.5.1   httpd-2.4.27/srclib/apr 

mv  apr-util-1.5.4  httpd-2.4.27/srclib/apr-util 

cd  httpd-2.4.27 

./configure  --prefix=/usr/local/apache2 --sysconfdir=/etc/apache2/conf/ --with-inculded-apr --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mpms-shared=all



方法二:一步一步安装

共有a、b、c三个步骤。

a.编译安装apr

cd  apr-1.5.1 

./configure --prefix=/usr/local/apr 

make && make install


b.编译安装apr-util

apr-util-1.5.4 

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 

make && make install


c.编译安装httpd

[root@apserver ~]# cd  httpd-2.4.27 

[root@apserver httpd-2.4.7]# ./configure \ 

prefix=/usr/local/apache2 \ 

sysconfdir=/etc/apache2/conf \ 

enable-so \ 

enable-rewirte \ 

enable-ssl \ 

enable-cgi \ 

enable-cgid \ 

enable-modules=most \ 

enable-modules-shared=most \ 

enable-mpms-shared=all \ 

with-apr=/usr/local/apr \ 

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


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

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

--enable-so :支持动态共享模块,如果没有这个模块PHP将无法与apache结合工作

--enable-rewirte :支持URL重写

--enable-ssl :启用支持ssl

--enable-cgi :启用支持cgi

--enable-cgid :启用支持带线状图形的CGI脚本 MPMs

--enable-modules=most :安装大多数模块

--enable-modules-shared=most :安装大多数共享模块

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

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

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


配置完成后,编译并安装:

[root@apserver httpd-2.4.7]# make && make install


编译安装后的文件结构:

1、主配置文件:/etc/apache2/conf/httpd.conf

2、命令和脚本目录:/usr/local/apache2/bin

3、默认网站的主页:/usr/local/apache2/htdocs/index.html

4、网页版帮助手册:/usr/local/apache2/manual/index.html

5、man手册:/usr/local/apache2/man

6、扩展功能配置文件目录:/etc/apache2/conf/extra/      目录中的配置文件如下

   httpd-vhosts.conf   虚拟主机配置文件

   httpd-default.conf   默认设置配置文件

   httpd-userdir.conf   用户家目录主页功能配置文件(类似于QQ空间)

   httpd-mpm.conf   工作模式配置文件(进程模式、线程模式的参数)

   httpd-manual.conf   帮助手册配置文件

   httpd-ssl.conf   ssl安全套接字配置文件

   httpd-languages.conf   语言配置文件

   httpd-autoindex.conf   自动索引配置文件


第3步:修改httpd.conf配置文件。

说明:需要修改2处。

1.修改/etc/hosts,增加一行

127.0.0.1  apserver   www.example.com


2.修改 /etc/apache2/conf/httpd.conf     修改如下代码

User   apache    //进程的属主(170行)。找到此行,将daemon改成apache。

Group  apache    //进程的属组(171行)。找到此行,将daemon改成apache

ServerName  www.example.com:80    //网站的域名(201行)。找到此行,并启用此行


注意:1、apserver、www.example.com都是主机名称。

2、如果不启用ServerName这行,启动服务时将会有警告,可能导致apache服务无法正常启动。


第4步:手动启动服务:

cd   /usr/local/apache2/bin

ls

./apachectl   start    //启动apache服务,apachectl是个脚本文件

./apachectl   stop    //停止apache服务

./apachectl   status   //查看apache服务状态


查进程状态:ps  aux|grep  httpd

查端口状态:ss  -atunlp|grep  :80  或  netstat  -atunlp|grep  :80  或  lsof  -i:80


第5步:配置apache的环境变量:

1、编辑环境变量文件。

vi  /etc/profile  添加如下内容

PATH="$PATH:/usr/local/apache2/bin"


2、加载环境变量文件。

source   /etc/profile


3、手动启动服务测试:

说明:添加了新的PATH环境变量后,可以在任何目录中运行脚本。

cd    

apachectl   stop  

apachectl  start



第6步:配置启动脚本:(首选)

方法一:用编译安装后的脚本文件设置开机启动(首选)

1、准备启动脚本文件:

cd  /usr/local/apache2/bin

cp  -pv  apachectl   /etc/init.d/apache

vi  /etc/init.d/apache   修改如下内容

#!/bin/sh    //找到此行,并添加下一行内容

# chkconfig:  -  85  15      //允许用chkconfig管理

#上行的-减号是控制默认的运行级别(默认为2 ~5),85为开机启动文件名S85apache的序号,15是开机不启动的文件名K15apache中的序号。启动文件路径:ls  /etc/rc.d/rc3.d/S85apache。


2、设置为开机启动,并验证

chmod  +x  /etc/init.d/apache    //添加x可执行权限

chkconfig  apache  on     //设为开机启动

chkconfig  apache  --list    //查看开机启动设置状态

service  apache  stop     // 停止apache服务

service  apache  start     // 启动apache服务


查端口状态:netstat  -atunlp|grep  :80

本地测试网站的访问:curl  127.0.0.1


3、(选做,可不做)给apache相关的文件和目录创建软链接。

root@apserver httpd-2.4.7]# cd /usr/sbin/ 

[root@apserver sbin]# ln  -s  /usr/local/apache2/bin/*  ./ 

为日志文件创建软链接 

[root@apserver sbin]# ln -s /usr/local/apache2/logs  /var/log/apache

到此,apache-2.4.27编译安装和配置实验完毕。


------------------------------------------------

方法二:配置启动脚本:

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

[root@apserver httpd-2.4.7]# vim /etc/init.d/apache 

          httpd=${HTTPD-/usr/sbin/httpd}          修改成 httpd=${HTTPD-/usr/local/apache2/bin/httpd} 

          pidfile=${PIDFILE-/var/run/${prog}.pid}  修改成pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid} 

          lockfile=${LOCKFILE-/var/lock/subsys/${prog}} 

          RETVAL=0 

          # check for 1.3 configuration 

        check13 () { 

              CONFFILE=/etc/apache2/conf/httpd.conf  修改成CONFFILE=/etc/apache2/conf/httpd.conf 

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

[root@apserver httpd-2.4.7]# chkconfig  apache  on   //设置apache到服务开机启动 

[root@apserver httpd-2.4.7]# chkconfig  apache --list  //查看apache开机设置状态

root@apserver httpd-2.4.7]# cd /usr/sbin/ 

[root@apserver sbin]# ln  -s  /usr/local/apache2/bin/*  ./ 

为日志文件创建软链接 

[root@apserver sbin]# ln -s /usr/local/apache2/logs  /var/log/apache


如果启动httpd的时候出现


Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for apserver 

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 

                                                          [  OK  ]


则需要修改2处:


1.修改/etc/hosts,增加一行

127.0.0.1  apserver


2.修改 /etc/apache2/conf/httpd.conf,在最后增加一行

ServerName  apserver


注意:apserver为机器名称

""




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



相关文章
|
6月前
|
Apache
apache2.4.39编译安装
apache2.4.39编译安装
|
10月前
|
Apache 开发工具
编译安装apache
编译安装apache
|
关系型数据库 MySQL Linux
Apache 源码包2.4.41版本 | 学习笔记
快速学习 Apache 源码包2.4.41版本
330 0
Apache 源码包2.4.41版本 | 学习笔记
|
前端开发 JavaScript API
源码编译 apache2.4
Apache HTTP Server是Apache软件基金会的一个开放源码的网页服务器软件,可以在大多数电脑操作系统中运行。由于其跨平台和安全性,被广泛使用,是最流行的Web服务器软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。
源码编译 apache2.4
|
Web App开发 Apache 数据安全/隐私保护
|
Apache Shell 开发工具