所需软件下载地址:
http://pan.baidu.com/s/1EUljg
1、查看系统是否安装Apache:
rpm -qa|grep httpd
有则卸载
yum remove httpd* -y
或
rpm -e --allmatches --nodeps httpd-2.2.3-83.el5.centos
2、源码安装apache
安装apr
tar zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
mkdir -p /usr/local/apr
./configure --prefix=/usr/local/apr
make
make install
安装apr-util
tar zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
mkdir -p /usr/local/apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make
make install
安装pcre
unzip -o pcre-8.34.zip
cd pcre-8.34
mkdir -p /usr/local/pcre
./configure --prefix=/usr/local/pcre
make
make install
安装openssl
tar zxvf openssl-1.0.1.tar.gz
cd openssl-1.0.1
mkdir -p /usr/local/openssl-1.0.1
./configure --prefix=/usr/local/openssl-1.0.1
make
make install
安装apache
tar zxvf httpd-2.4.7.tar.gz
cd httpd-2.4.7
mkdir -p /usr/local/apache
./configure --prefix=/usr/local/apache --enable-modules=all --enable-mods-shared=all --enable-dav --enable-dav-fs --enable-so --with-mpm=prefork --with-ssl=/usr/local/openssl --with-apxs=/usr/local/apache/bin/apxs
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make
make install
配置http服务器
首先测试一下服务器是否可以正常访问,命令如下:
cd /usr/local/apache/bin
./apachectl start
然后在浏览器里输入http://运行apache的ip地址
出现It Works,表示成功。
==============================apache的vhost配置=====================================
一、修改http.conf,使用httpd-vhosts.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
二、在httpd-vhosts.conf中配置站点
apache-2.2.x配置虚拟机的内容:
NameVirtualHost 192.168.10.81:80
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 192.168.10.81
DocumentRoot /var/www/vhosts/wwwroot
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all
==================================
apache-2.4.x配置虚拟机的内容:
ServerAdmin rocdk890@gmail.com
directoryIndex index.html index.php index.htm index.shtml login.php
ServerName 192.168.10.81
DocumentRoot /var/www/vhosts/wwwroot
Options -Indexes
AllowOverride All
Require all granted
可以看到apache-2.4.x把NameVirtualHost给取消,现在配置虚拟主机不需要再配置NameVirtualHost了.
删除了 Order deny,allow 和 Order allow,deny
把 Deny from all 替换成了 Require all denied
把Allow from all 替换成了 Require all granted
然后还把 Allow from 192.168.10.21 这样的语句给替换成了 Require host 192.168.10.21
三、浏览器绑定host即可