当前位置: > CentOS > CentOS服务器 > webserver >

CentOS 5.4下配置Apache服务器

时间:2015-01-16 01:09来源:51cto.com 作者:51cto

WEB服务器的架设,在linux有一个很著名的架构叫lamp:linux+apache+mysql+php 
 
Apache一直是Internet上最流行的Web服务器
后台进程:httpd
脚本:/etc/rc.d/init.d/httpd
使用端口:80(http),443(https)
所需RPM包:httpd
配置路径:/etc/httpd/*
默认网站存放路径:/var/www/*

apache主要目录和文件说明
主配置文件位置/etc/httpd/conf/*或者/usr/local/apache2/conf/httpd.conf
启动脚本/etc/rc.d/init.d/httpd 
格式的帮助文档/usr/local/apache2/manual/*html
用在html网页中的图标文件/usr/local/apache2/icons/*
建立和更新apache用户的程序/usr/local/apache2/htpasswd
http
服务器程序/usr/sbin/httpd
日志文件/usr/local/apache2/
优点:免费,稳定,速度快

我们先安装apache

  rpm -ivh httpd-2.2.3-31.el5.centos.i386.rpm
  mv httpd-2.0.54 apache
  cd apache
  ./configure --prefix=/usr/local/apache2 --enable-module=so
  make
  make install 
  安装apache至/usr/local/apache 并配置apache支持dso方式

 

查看一下安装Apache的情况

[root@host CentOS]# rpm -qa | grep httpd
httpd-2.2.3-31.el5.centos
httpd-manual-2.2.3-31.el5.centos
system-config-httpd-1.3.3.3-1.el5

安装好了,启动Apache,
 [root@host CentOS]# service httpd start

 

现在就可以先看看这个服务带给我们的是什么,因为做这个实验应该可以DNS服务实验一起,但是时间的问题没有在一起做,访问WEB服务的时候,我们没有用域名服务器,只是对应WEB服务器的IP地址

要想网页上渡口自己想配置的内容就要来配置Apache,我们继续一步一步的来配置他!!!

这是apache的所有配置文件存放的目录

 [root@host ~]# ll /etc/httpd/
总计 28
drwxr-xr-x 2 root root 4096 11-04 17:08 conf
drwxr-xr-x 2 root root 4096 11-04 17:09 conf.d
lrwxrwxrwx 1 root root   19 11-04 17:08 logs -> ../../var/log/httpd
lrwxrwxrwx 1 root root   27 11-04 17:08 modules -> ../../usr/lib/httpd/modules
lrwxrwxrwx 1 root root   13 11-04 17:08 run -> ../../var/run

 

这是网页文件存放目录,一般在html内

[root@host ~]# ll /var/www/
总计 48
drwxr-xr-x  2 root      root 4096 2009-09-04 cgi-bin
drwxr-xr-x  3 root      root 4096 11-04 17:08 error
drwxr-xr-x  2 root      root 4096 2009-09-04 html
drwxr-xr-x  3 root      root 4096 11-04 17:08 icons
drwxr-xr-x 14 root      root 4096 11-04 17:09 manual
drwxr-xr-x  2 webalizer root 4096 11-04 17:08 usage
[root@host ~]# ll /var/www/html/
总计 0

 

apache的主配置文件

 [root@host ~]# vim /etc/httpd/conf/httpd.conf

 

httpd.conf中每行包含一条语句,行末使用反斜杠“\”可以换行,但是反斜杠与下一行中间不能有任何其他字符(包括空白)
httpd.conf的配置语句除了选项的参数值以外,所有选项指令均不区分大小写,可以在每一行前用“#”号表示注释。  
全局配置的相关参数,全局的参数一般不用改哦
ServerType
选择系统激活服务器的方式。可以是inetd或standalone
默认应该是独立的stationalone  
ServerRoot
设定Apache 安装的绝对路径

 #
ServerRoot "/etc/httpd"

 

TimeOut
设定 服务器接收至完成的最长等待时间
 

 

 #
Timeout 120

 

KeepAlive
设定服务器是否开启连续请求功能,真实服务器一般都要开启
 

 

 #
KeepAlive Off

 

MaxKeepAliveRequests
设定服务器所能接受的最大连续请求量

 #
MaxKeepAliveRequests 100

 

 #
KeepAliveTimeout 15        \\使用者‘连续’请求的等待时间上限数

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers       8                     \\设定激活时所需建立的子进程数
MinSpareServers    5                \\设定最小闲置子进程数 
MaxSpareServers   20              \\设定最大闲置子进程数
ServerLimit      256
MaxClients       256                   \\设定同时能够提供使用者的最大服务请求数
MaxRequestsPerChild  4000
</IfModule>

 

 

Port
设定http服务的默认端口。
User/Group
设定 服务器程序的执行者与属组

 #
User apache
Group apache

我们说过,网页文件默认是放在/var/www/html中的,我们现在就自己去写个网页,简单的,来测试下
 

[root@host ~]# ll /var/www/html/
总计 0
[root@host ~]# echo hello,this is my home,welcome! > /var/www/html/index.html
[root@host ~]# ll /var/www/html/
总计 8
-rw-r--r-- 1 root root 48 02-19 10:50 index.html
[root@host ~]# cat /var/www/html/index.html
hello,this is my home,welcomell!

 

然后重新访问你的服务器,看看有什么变化
 

 在主配置文件(/etc/httpd/conf/httpd.conf)中,看见DirectoryIndex了么,这个位置就是定义主页文件的名字的,自己可以随意修改,但是一般网页开发都写成了index.html,index.htm default.html 等等

 

 #
DirectoryIndex index.html index.html.var

 

我们按照自己的想法构架一个PHP WEB网站。。。GO。。。

添加了一个index.php ,方便一会我们测试apache支持php,如果找不到,系统会出现redhat的测试页面

 

 #
DirectoryIndex index.html
index.php

 

我们测试把默认网站目录改到root家目录下
第一步,修改DocumentRoot这个位置  1
第二步,修改目录的权限设置  2

 重启一下httpd服务

 

 [root@host webphp]# service httpd restart

 

客户端浏览

现在我们自己建一个PHP页面吧。。。

 

 [root@host webphp]# ll /root/webphp
总计 0
[root@host webphp]# echo hello.This is a php webservers! > /root/webphp/index.php
[root@host webphp]# ll /root/webphp
总计 8
-rw-r--r-- 1 root root 32 02-19 13:58 index.php

 

我们来看看我们自己建的PHP页面吧。。。

基于LINUX下的基本服务构架都实验过了!但是对于构架好后的正常维护,还需要有更好的环境去努力学习啊。。。

(责任编辑:IT)
------分隔线----------------------------