源码包安装

安装gcc  [root@apenglinux-001 ~]# yum install gcc -y

下载[root@apenglinux-001 httpd-2.2.34]# wget https://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz

解压[root@apenglinux-001 httpd-2.2.34]# tar zxvf httpd-2.2.34.tar.gz

进入到解压目录[root@apenglinux-001 httpd-2.2.34]# cd httpd-2.2.34

配置[root@apenglinux-001 httpd-2.2.34]# ./configure --prefix=/usr/local/apache2

编译[root@apenglinux-001 httpd-2.2.34]# make

安装[root@apenglinux-001 httpd-2.2.34]# make install

查看

[root@apenglinux-001 httpd-2.2.34]# ls /usr/local/apache2/

bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules

源码包安装_linux

但有些时候源码包安装要依赖相关的包


[root@apenglinux-001 httpd-2.4.28]# yum install gcc -y

[root@apenglinux-001 src]# wget https://mirrors.cnnic.cn/apache/httpd/httpd-2.4.28.tar.gz

[root@apenglinux-001 httpd-2.4.28]# ./configure --prefix=/usr/local/apache2

configure: error: APR not found.  Please read the documentation.(报错)

[root@apenglinux-001 httpd-2.4.28]# ./configure --help|grep -i apr
  --enable-hook-probes    Enable APR hook probes
  --with-included-apr     Use bundled copies of APR/APR-Util
  --with-apr=PATH         prefix for installed APR or the full path to
                             apr-config
  --with-apr-util=PATH    prefix for installed APU or the full path to

源码包安装apr

[root@apenglinux-001 apr-1.4.6]# wget http://archive.apache.org/dist/apr/apr-1.4.6.tar.gz
[root@apenglinux-001 apr-1.4.6]# tar zxvf apr-1.4.6.tar.gz
[root@apenglinux-001 apr-1.4.6]# cd apr-1.4.6
[root@apenglinux-001 apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@apenglinux-001 apr-1.4.6]# make
[root@apenglinux-001 apr-1.4.6]# make install

继续源码包安装httpd-2.4.28

[root@apenglinux-001 httpd-2.4.28]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr/
[root@apenglinux-001 httpd-2.4.28]# ./configure --help|grep -i apr-util
  --with-included-apr     Use bundled copies of APR/APR-Util
  --with-apr-util=PATH    prefix for installed APU or the full path to

源码包安装apr-util

[root@apenglinux-001 apr-util-1.4.1]# wget http://archive.apache.org/dist/apr/apr-util-1.4.1.tar.gz 
[root@apenglinux-001 apr-util-1.4.1]# tar zxvf apr-util-1.4.1.tar.gz
[root@apenglinux-001 apr-util-1.4.1]# cd apr-util-1.4.1
[root@apenglinux-001 apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@apenglinux-001 apr-util-1.4.1]# make
[root@apenglinux-001 apr-util-1.4.1]# make install

继续源码包安装httpd-2.4.28

[root@apenglinux-001 httpd-2.4.28]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/

安装pcre-devel

[root@apenglinux-001 httpd-2.4.28]# yum install pcre-devel -y

继续源码包安装httpd-2.4.28

[root@apenglinux-001 httpd-2.4.28]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
[root@apenglinux-001 httpd-2.4.28]# make
[root@apenglinux-001 httpd-2.4.28]# make install

启动httpd-2.4.28

[root@apenglinux-001 ~]# /usr/local/apache2/bin/apachectl start
[root@apenglinux-001 ~]# ps aux|grep httpd
root      33480  0.0  0.1  96280  3048 ?        Ss   15:15   0:00 /usr/local/apache2/bin/httpd -k start
daemon    33481  0.0  0.2 448644  4560 ?        Sl   15:15   0:00 /usr/local/apache2/bin/httpd -k start
daemon    33482  0.0  0.2 383108  4564 ?        Sl   15:15   0:00 /usr/local/apache2/bin/httpd -k start
daemon    33483  0.0  0.2 383108  4564 ?        Sl   15:15   0:00 /usr/local/apache2/bin/httpd -k start
root      33573  0.0  0.0 112676   980 pts/1    S+   15:19   0:00 grep --color=auto httpd
[root@apenglinux-001 ~]# netstat -tnlp|grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      33480/httpd

httpd-2.4.28编译安装成功后安装路径为:/usr/local/apache2

配置文件为:/u/usr/local/apache2/conf/httpd.conf

为Apache添加服务脚本:cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

添加进环境变量

 echo 'export PATH=$PATH:/usr/local/apache2/bin' > /etc/profile.d/httpd.sh

chmod +x /etc/profile.d/httpd.sh

source /etc/profile.d/httpd.sh

如果想把apache服务加入到开机自启,可以修改服务启动脚本:


# vim /etc/init.d/httpd

在第二行下添加:# chkconfig:235 85 15

                           # description: This is apache server!

加入开机自启:

# chkconfig  --add  httpd

其中235代表在第2,3,5运行级别下会开机启动

85和15代表开机和关机的启动顺序,数值越大代表启动的优先级越低

后启动的一般要先关闭,参数可以随你的喜好调整

description后的内容可以随意写

/usr/local/apache2/conf/httpd.conf这个文件各选项意义 

ServerRoot  "/usr/local/apache"        // Apache的安装目录
ServerName  localhost                       // 服务名称,可以填主机名
Listen  80                                            // 服务监听端口,默认80
LoadModule                                       // 服务启动需要加载的模块
User  daemon                                     // apache进程执行者
Group deamon                                   // 执行者的属组
ServerAdmin  you@example.com      // 管理员的邮箱地址
DocumentRoot "/usr/local/apache/htdocs"         // 网站根目录
ErrorLog "logs/error_log"                   // Apache运行产生的错误日志
LogLevel warn                                     // 指定ErrorLog会记录的错误的级别
DirectoryIndex index.html                   // 网站目录索引文件

检查语法是否有错误

[root@apenglinux-001 ~]# /usr/local/apache2/bin/httpd -t
Syntax OK
[root@apenglinux-001 ~]# service httpd configtest
Syntax OK

重启服务

[root@apenglinux-001 ~]# httpd -k restart
[root@apenglinux-001 ~]# service httpd graceful

重新读取配置文件

[root@apenglinux-001 ~]# httpd -k graceful
[root@apenglinux-001 ~]# service httpd graceful

关闭服务

[root@apenglinux-001 ~]# httpd -k stop
[root@apenglinux-001 ~]# service -k stop