环境:web02机器,centos6.8
需要在web02机器上面编译安装apache,php,然后apache和php整合。web02不需要安装mysql
mysql数据库已独立安装在独立的一台机器db01上了。
1 apache下载:
登录官网:http://www.apache.org/ 根据下图提示下载
下载版本为: httpd-2.2.34.tar.gz (二进制源码)
2 在web02机器配置、编译、安装apache
2.1 apache 安装
####apache httpd安装步骤(源码编译安装)####
mkdir -p /home/oldboy/tools/ cd /home/oldboy/tools/ wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.2.34.tar.gz tar xf httpd-2.2.34.tar.gz cd httpd-2.2.34 #进入源码包里面才可以配置、编译、安装。 #less INSTALL #查看安装指导 #less README #查看说明 yum install zlib zlib-devel -y #C语言源码编译前配置 ./configure --prefix=/application/apache2.2.34 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite #源码编译成二进制,是写的过程,速度慢。 make #编译的过程,(编译完成后最后一行是:make[1]: Leaving directory `/home/oldboy/tools/httpd-2.2.34'说明已经编译完成) #二进制安装过程,属于拷贝过程,速度快。 make install #拷贝的过程(安装后最后一行是make[1]: Leaving directory `/home/oldboy/tools/httpd-2.2.34'说明已经安装完成)
2.2 apache编译安装后配置(配置三个虚拟主机站点)
ln -s /application/apache2.2.34/ /application/apache ll /application/apache/ [root@web02 httpd-2.2.34]# cd /application/apache/htdocs [root@web02 htdocs]# mkdir bbs www blog [root@web02 htdocs]# cd /application/apache/conf/ [root@web02 conf]# ll 总用量 92 drwxr-xr-x 2 root root 4096 8月 27 21:57 extra -rw-r--r-- 1 root root 13956 8月 27 21:57 httpd.conf -rw-r--r-- 1 root root 12958 8月 27 21:57 magic -rw-r--r-- 1 root root 53015 8月 27 21:57 mime.types drwxr-xr-x 3 root root 4096 8月 27 21:57 original [root@web02 conf]# vim httpd.conf 把#Include conf/extra/httpd-vhosts.conf这行的#注释去掉。 把98行的#ServerName www.example.com:80修改为ServerName 127.0.0.1:80 把Options Indexes FollowSymLinks修改为Options -Indexes FollowSymLinks或者 注释掉,或者删除,因为此行是apache默认显示目录的,和nginx的autoindex on;一样。 [root@web02 conf]# vim /application/apache/conf/extra/httpd-vhosts.conf 把<VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "/application/apache2.2.34/docs/dummy-host2.example.com" ServerName dummy-host2.example.com ErrorLog "logs/dummy-host2.example.com-error_log" CustomLog "logs/dummy-host2.example.com-access_log" common </VirtualHost> 修改为: <VirtualHost *:80> ServerAdmin webadmin@qq.com DocumentRoot "/application/apache2.2.34/htdocs/www" ServerName www.etiantian.org ServerAlias etiantian.org ErrorLog "logs/www-error_log" CustomLog "logs/www-access_log" common </VirtualHost> #VirtualHost全部配置如下所示: [root@web02 conf]# tail -36 /application/apache/conf/extra/httpd-vhosts.conf # # Use name-based virtual hosting. # NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <VirtualHost *:80> ServerAdmin webadmin@qq.com DocumentRoot "/application/apache2.2.34/htdocs/www" ServerName www.etiantian.org ServerAlias etiantian.org ErrorLog "logs/www-error_log" CustomLog "logs/www-access_log" common </VirtualHost> # <VirtualHost *:80> ServerAdmin webadmin@qq.com DocumentRoot "/application/apache2.2.34/htdocs/bbs" ServerName bbs.etiantian.org ErrorLog "logs/bbs-error_log" CustomLog "logs/bbs-access_log" common </VirtualHost> # <VirtualHost *:80> ServerAdmin webadmin@qq.com DocumentRoot "/application/apache2.2.34/htdocs/blog" ServerName blog.etiantian.org ErrorLog "logs/blog-error_log" CustomLog "logs/blog-access_log" common </VirtualHost> 检查语法: [root@web02 conf]# ../bin/apachectl -t Syntax OK #这个OK的标志是检查apache的语法没有错误 启动apache [root@web02 htdocs]# /application/apache/bin/apachectl start 如果apache已经启动了,优雅重新apache [root@web02 htdocs]# /application/apache/bin/apachectl graceful
3 验证配置的三个虚拟主机站点是否可以正常登陆(在web01机器上面测试)
在web01上面测试apache先添加hosts文件解析 [root@web01 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.1.5 lb01 172.16.1.6 lb01 172.16.1.7 web02 www.etiantian.org etiantian.org blog.etiantian.org bbs.etiantian.org 172.16.1.8 web01 172.16.1.51 db01 db01.etiantian.org 172.16.1.31 nfs01 172.16.1.41 backup 172.16.1.61 m01 [root@web01 ~]# curl -I www.etiantian.org ##403错误代表没有首页 HTTP/1.1 403 Forbidden Date: Sun, 27 Aug 2017 14:56:47 GMT Server: Apache/2.2.34 (Unix) DAV/2 Content-Type: text/html; charset=iso-8859-1 在web02虚拟主机站点服务器给各个站点添加首页: [root@web02 htdocs]# vi /application/apache/conf/httpd.conf 把Options Indexes FollowSymLinks修改为Options -Indexes FollowSymLinks [root@web02 htdocs]# echo 'apache www' >www/index.html [root@web02 htdocs]# echo 'apache bbs' >bbs/index.html [root@web02 htdocs]# echo 'apache blog' >blog/index.html 在web01上面继续测试:继续curl虚拟主机站点 [root@web01 ~]# curl www.etiantian.org apache www #测试OK [root@web01 ~]# curl bbs.etiantian.org apache bbs #测试OK [root@web01 ~]# curl blog.etiantian.org apache blog #测试OK [root@web01 ~]# curl -I www.etiantian.org HTTP/1.1 200 OK #测试OK Date: Sun, 27 Aug 2017 16:20:55 GMT Server: Apache/2.2.34 (Unix) DAV/2 Last-Modified: Sun, 27 Aug 2017 14:59:40 GMT ETag: "204c4-b-557bd6d7606d8" Accept-Ranges: bytes Content-Length: 11 Content-Type: text/html
如上测试结果说明三个虚拟主机站点www.etiantian.org、blog.etiantian.org、bbs.etiantian.org都已配置OK了。
######
./configure
--prefix=/application/apache2.2.34
--enable-deflate
--enable-expires
--enable-headers
--enable-modules=most
--enable-so
--with-mpm=worker
--enable-rewrite
虚拟主机配置: | |
域名 | 站点目录 |
www.etiantian.org | /application/apache/htdocs/www |
blog.etiantian.org | /application/apache/htdocs/blog |
bbs.etiantian.org | /application/apache/htdocs/bbs |
转载于:https://blog.51cto.com/sandshell/1959798