一、准备工作
1、安装Apache httpd需要依赖APR、APR-Util以及Pcre,下面是官方文档给的解释。
APR and APR-Util
Make sure you have APR and APR-Util already installed on your system. If you don't, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into /httpd_source_tree_root/srclib/apr and /httpd_source_tree_root/srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under /httpd_source_tree_root/srclib/apr/) and use ./configure's --with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util.
Perl-Compatible Regular Expressions Library (PCRE)
This library is required but not longer bundled with httpd. Download the source code from http://www.pcre.org, or install a Port or Package. If your build system can't find the pcre-config script installed by the PCRE build, point to it using the --with-pcreparameter. On some platforms, you may have to install the corresponding -dev package to allow httpd to build against your installed copy of PCRE.
Disk Space
Make sure you have at least 50 MB of temporary free disk space available. After installation the server occupies approximately 10 MB of disk space. The actual disk space requirements will vary considerably based on your chosen configuration options, any third-party modules, and, of course, the size of the web site or sites that you have on the server.
ANSI-C Compiler and Build System
Make sure you have an ANSI-C compiler installed. The GNU C compiler (GCC) from the Free Software Foundation (FSF) is recommended. If you don't have GCC then at least make sure your vendor's compiler is ANSI compliant. In addition, your PATHmust contain basic build tools such as make.
Accurate time keeping
Elements of the HTTP protocol are expressed as the time of day. So, it's time to investigate setting some time synchronization facility on your system. Usually the ntpdate or xntpd programs are used for this purpose which are based on the Network Time Protocol (NTP). See the NTP homepage for more details about NTP software and public time servers.
Perl 5 [OPTIONAL]
For some of the support scripts like apxs or dbmmanage (which are written in Perl) the Perl 5 interpreter is required (versions 5.003 or newer are sufficient). If no Perl 5 interpreter is found by the configure script, you will not be able to use the affected support scripts. Of course, you will still be able to build and use Apache httpd.。
注意:之前在CentOs 7安装了apr1.6和apr-util1.6 导致安装apache失败,错误的原因为apr和apr-util版本的问题 修改为1.5就没有问题了,所有此次安装1.5版本。
2、下载地址
下载pcre 地址:https://ftp.pcre.org/pub/pcre/
下载apr_1.5:http://archive.apache.org/dist/apr/
下载apr-util_1.5:http://archive.apache.org/dist/apr/
二、 安装步骤
Linux下,源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。
1、安装APR
解压
[root@bogon app]# tar -zxvf apr-1.5.2.tar.gz
新建目录/usr/local/apr,配置apr安装目录
[root@bogon apr-1.5.2]# mkdir /usr/local/apr
[root@bogon apr-1.5.2]# ./configure --prefix=/usr/local/apr
注意:在./configure 的时候 可能会报错 rm: cannot remove `libtoolT': No such file or directory
解决方法:
cd /app/apr-1.5.2
vi configure
修改RM='$RM' 为 RM='$RM -f'
修改完之后重新./configure 一下 然后继续
编译
[root@bogon apr-1.5.2]# make
安装
[root@bogon apr-1.5.2]# make install
安装完成,可以验证
[root@bogon apr-1.5.2]# cd /usr/local/apr/
[root@bogon apr]# ls -lrt
总用量 0
drwxr-xr-x. 3 root root 19 3月 26 17:13 include
drwxr-xr-x. 3 root root 140 3月 26 17:13 lib
drwxr-xr-x. 2 root root 148 3月 26 17:13 build-1
drwxr-xr-x. 2 root root 26 3月 26 17:13 bin
[root@bogon apr]#
2、安装APR-Util
解压
[root@bogon app]# tar -zxvf apr-util-1.6.1.tar.gz
新建目录/usr/local/apr,用作apr-util安装目录
[root@bogon app]# cd apr-util-1.5.2
[root@bogon apr-util-1.5.2]#
[root@bogon apr-util-1.5.2]# mkdir /usr/local/apr-util
[root@bogon apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
编译
[root@bogon apr-util-1.5.2]# make
注意:make编译时可能会发生错误,如下:xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
问题:缺少 expat库
解决方法 :yum install -y expat-devel
再次编译即可
编译
[root@bogon apr-util-1.5.2]# make
...
安装
[root@bogon apr-util-1.5.2]# make install
3、安装pcre
解压并创建安装文件夹,执行配置
[root@bogon pcre-8.33]#
[root@bogon pcre-8.33]# mkdir /usr/local/pcre
[root@bogon pcre-8.33]# ./configure --prefix=/usr/local/pcre/
编译
[root@bogon pcre-8.33]# make
安装
[root@bogon pcre-8.33]# make insatll
4、安装Apache
安装apache时记得依赖apr、apr-util以及pcre
[root@bogon app]# tar -zxvf httpd-2.4.33.tar.gz
...
[root@bogon app]# cd httpd-2.4.33
[root@bogon app]# mkdir /usr/local/apache
[root@bogon httpd-2.4.33]# ./configure --prefix=/usr/local/apache/ --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
编译
[root@bogon httpd-2.4.33]# make
安装
[root@bogon httpd-2.4.33]# make install
5、启动
[root@bogon etc]# /usr/local/apache/bin/apachectl start
注意:初次启动时,会报错,错误的大概意思应该是无法使用ServerName 对应的域名来启动
解决方案:进入Apache的配置文件http.conf中 在 #ServerName www.example.com:80 下一行添加自己的地址及端口号
ps:ServerName localhost:80
修改完,重新启动apache服务 在浏览器地址栏中输入自己的ip地址,即可看到下图页面
如果不能查看的话,记得开启80端口,具体视实际情况而定,临时开放端口命令:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
至此,在linux中安装apache的过程就全部完成了。
基本的操作方法:
本文假设你的apahce安装目录为/usr/local/apache,这些方法适合任何情况
apahce启动命令:推荐/usr/local/apache/bin/apachectl start
apache停止命令:/usr/local/apache/bin/apachectl stop
apache重新启动命令:/usr/local/apache/bin/apachectl restart
要在重启 Apache 服务器时不中断当前的连接,则应运行:/usr/local/sbin/apachectl graceful
如果apache安装成为linux的服务的话,可以用以下命令操作:
service httpd start 启动
service httpd restart 重新启动
service httpd stop 停止服务