官方下载目前稳定版本,http://mirror.esocc.com/apache/httpd/httpd-2.2.27.tar.gz ,解压安装如下,安装apache之前,需要先安装apr apr-util。

[root@localhost src]# tar zxvf httpd-2.2.27.tar.gz

[root@localhost src]# yum install -y apr apr-util apr-util-devel

[root@localhost src]# cd httpd-2.2.27

编译之前确定你的电脑已安装gcc    

[root@localhost httpd-2.2.27]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so

[root@localhost httpd-2.2.27]# make

[root@localhost httpd-2.2.27]# make install

然后启动apache服务:  /usr/local/apache2/bin/apachectl start

提示:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName  解决方案:将/usr/local/apache2/conf/httpd.conf面的#ServerName localhost:80注释去掉即可。

查看apache进程及端口:

[root@localhost httpd-2.2.27]# netstat -tnl |grep 80

tcp        0      0 :::80                       :::* 


[root@localhost httpd-2.2.27]# ps -ef |grep httpd

root     17295     1  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17296 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17297 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17298 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17299 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17300 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17301 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17302 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

daemon   17303 17295  0 13:14 ?        00:00:00 /usr/local/apache2/bin/httpd -k start

root     17316  6781  0 13:21 pts/0    00:00:00 grep httpd


源码包安装Apache默认发布目录为:/usr/local/apache2/htdocs/下。

启动apache服务:[root@localhost httpd-2.2.27]# /usr/local/apache2/bin/apachectl start


二、Apache基于域名虚拟主机配置,这个就叫做虚拟主机,在一台机器可以搭建多个网站。

修改vi /usr/local/apache2/conf/extra/httpd-vhosts.conf虚拟主机配置文件内容如下:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin webmaster@antpedia.com    管理员邮箱
    DocumentRoot /www/wwwroot/supesite   DocumentRoot 指的是网站文件存放的目录               ServerName www.ruizengguiji.com             是网站的域名   
    DirectoryIndex index.htm index.html home.php index.php index.cgi
    DefaultLanguage zh-CN
    AddDefaultCharset UTF-8
    ErrorDocument 404 /error/err.html
   <Directory "/www/wwwroot/supesite">
       Options FollowSymLinks
       AllowOverride All
       Order deny,allow
   </Directory>
</VirtualHost>


第二个虚拟主机:

<VirtualHost *:80>
    ServerAdmin webmaster@antpedia.com
    DocumentRoot /www/wwwroot/supesite2
        ServerName david.ruizengguoji.com
    DirectoryIndex index.htm index.html home.php index.php index.cgi
    DefaultLanguage zh-CN
    AddDefaultCharset UTF-8
    ErrorDocument 404 /error/err.html
   <Directory "/www/wwwroot/supesite2">
       Options FollowSymLinks
       AllowOverride All
       Order deny,allow
   </Directory>
</VirtualHost>


把httpd.conf中  Include conf/extra/httpd-vhosts.conf  取消注释

保存退出!重启apache服务

新建文件 mkdir /data/webapps/www1 www2

进入到相应的目录下创建index.html   

echo wgk1 www.wugk.com >>index.html

echo wgk2 www.wugk.com >>index.html

测试检查文件有没有错误:/usr/local/apache2/bin/apachectl -t

重新加载apache不中断apache:/usr/local/apache2/bin/apachectl graceful

在测试机上配置 运行:c:\WINDOWS\system32\drivers\etc

打开hosts  增加内容:192.168.1.7(提供apache服务地址)  www.wugk1.com(指定域名1) www.wugk2.com(指定域名2) www.wugk3.com  www.wugk4.com www.wugk5.com