[root@jianxiangqiao ~]# rpm -qa|grep -e wget -e ^gcc -e make
gcc-4.8.3-9.el7.x86_64
make-3.82-21.el7.x86_64
wget-1.14-10.el7_0.1.x86_64
yum -y install wget gcc make
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package wget-1.14-10.el7_0.1.x86_64 already installed and latest version
Package gcc-4.8.3-9.el7.x86_64 already installed and latest version
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Nothing to do
安装Apache
编译安装Apache组件
Apache至少需要apr、apr-util、pcre组件的支持。
APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。在早期的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数。随着Apache的进一步开发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样,APR的开发就从Apache中独立出来,Apache仅仅是使用APR而已。目前APR主要还是由Apache使用,不过由于APR的较好的移植性,因此一些需要进行移植的C程序也开始使用APR。
APR-util是在APR的基础上提供了更多的数据结构和操作系统封装接口。APR-util依赖于APR,必须先安装APR再安装APR-util。
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括perl兼容的正则表达式库。
编译安装APR:
cd /usr/local/src
wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz
tar -zxf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure –prefix=/usr/local/apr
//–prefix=/usr/local/apr意思是指定apr的安装目录为/usr/local/apr
[root@jianxiangqiao apr-1.5.2]# make && make install
编译安装APR-util:
# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
# tar -zxf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
//–with-apr=/usr/local/apr选项的意思是指定apr的安装位置/usr/local/apr
# make && make install
编译安装PCRE:
# cd /usr/local/src
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
# tar -zxf pcre-8.37.tar.gz
# cd pcre-8.37
# ./configure –prefix=/usr/local/pcre
# make && make install
编译安装Apache
最新版本:Apache httpd 2.4.17 Released(2015-10-13)
下载地址:http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.17.tar.gz
# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.17.tar.gz
# tar -zxf httpd-2.4.17.tar.gz
# cd httpd-2.4.17
# ./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-rewrite –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –with-pcre=/usr/local/pcre
# make && make install
配置Apache
配置防火墙
# firewall-cmd –permanent –add-service=http
success
# firewall-cmd –reload
success
配置SELinux
# restorecon -RFvv /usr/local/apache/htdocs
restorecon reset /usr/local/apache/htdocs context system_u:object_r:usr_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /usr/local/apache/htdocs/index.html context system_u:object_r:usr_t:s0->system_u:object_r:httpd_sys_content_t:s0
启动Apache
启动和停止Apache
使用httpd命令控制Apache,执行以下命令:
# /usr/local/apache/bin/httpd -k start
# /usr/local/apache/bin/httpd -k stop
使用脚本控制Apache,执行以下命令:
# /usr/local/apache/bin/apachectl start
# /usr/local/apache/bin/apachectl stop
设置Apache开机启动
1、将apachectl命令拷贝到/etc/init.d目录下,改名为httpd
# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
2、编辑/etc/init.d/httpd文件,在第1行#!/bin/sh的后面添加如下两行
# vi /etc/init.d/httpd
# chkconfig: 2345 70 30
# description: Apache
其中,所增加的第二行中三个数字,第一个表示在运行级别2345下启动Apache,第二、三是关于启动和停止的优先级配置,无关紧要。
# chkconfig –add httpd
# chkconfig –list httpd
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use ‘systemctl list-unit-files’.
To see services enabled on particular target use
‘systemctl list-dependencies [target]’.
httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off