- CentOS4.4系统安装
- CentOS 4.4 的安装后初始环境设定
- 用 Apache 构建 HTTP 服务器
CentOS系统安装步骤
( http://bbs.88443.net/ ShowPost.asp?ThreadID=2184 )
作者:88443
发表时间:2006-11-30 23:54:00
CentOS是当前最流行的商业版Linux -- Red Hat Enterprise Linux(RHEL)的克隆版。它和RHEL的区别除了没有RHEL一样的技术支持以外,就是修正了RHEL已知的一些Bug,所以,其稳定性值得我们 信赖。至于RHEL所谓的技术支持,在一般公司采购的情况下,公司无非是为了安心或者在问题出现的时候能够找到负责方才购买Red Hat的技术支持。事实上,为了能够享受技术支持而付费的公司,真正确实的享受了技术支持服务的情况并没有想象的那么多。因为只要有LPIC Level 1级别的用户就基本能够驾驭它。所以,对于我们个人,根据用途的不同,不需要技术支持,也完全有能力活用这个系统。
对于安装,我们的原则就是在初期按装时采用最小安装,这样使得初期状态显得干净而简洁。在以后的配置中,需要哪些组件的时候,再通过CentOS的“yum”命令(前提需要首先接入互联网)来在线安装。
CentOS 4.4 的下载及安装光盘的制作
[第一步] 从镜像站点上下载ISO的镜像文件
CD 1 : http://mirror.tini4u.net/centos/4.4/isos/i386/CentOS-4.4-i386-bin1of4.iso
CD 2 : http://mirror.tini4u.net/centos/4.4/isos/i386/CentOS-4.4-i386-bin2of4.iso
CD 3 : http://mirror.tini4u.net/centos/4.4/isos/i386/CentOS-4.4-i386-bin3of4.iso
CD 4 : http://mirror.tini4u.net/centos/4.4/isos/i386/CentOS-4.4-i386-bin4of4.iso
md5校验码:http://mirror.tini4u.net/centos/4.4/isos/i386/md5sum
将上面所有文件(包括md5校验码)下载到同一个目录(文件夹)下。(这里,选择了从CentOS的韩国镜像站上下载。根据具体位置可以选择距离近、速度快的景象站点。查找CentOS的镜像请见官方镜像站点列表。)
[第二步] 验证下载的ISO镜像文件的完整性
下载 md5校验工具 ,并将其放在和刚刚下载的CentOS的ISO镜像文件所在的目录里。
C:Documents and SettingsXXXX> e: ← 进入镜像文件所在分区
E:> cd CentOS ← 进入镜像文件所在目录
E:CentOS> md5sum -c md5sum ← 回车,执行md5sum进行完整性校验
CentOS-4.4-i386-bin1of4.iso: OK -
CentOS-4.4-i386-bin2of4.iso: OK - 四个镜像文件全部显示OK,
CentOS-4.4-i386-bin3of4.iso: OK - 说明下载的ISO镜像文件没有问题!
CentOS-4.4-i386-bin4of4.iso: OK -/
md5sum: CentOS-4.4-i386-binDVD.iso: No such file or directory -
CentOS-4.4-i386-binDVD.iso: FAILED open or read - 无视这些信息
md5sum: WARNING: 1 of 5 listed files could not be read -/
[第三步] 将ISO镜像文件制作成CentOS安装CD
在Microsoft Windows下,用Nero等等的光盘刻录软件将ISO镜像文件转换、刻录成安装CD。
CentOS 4.4 的安装过程
将BIOS设置中的启动项设置为从光盘启动,然后放入CentOS安装CD的第一张后,重新启动计算机。
安装程序启动后的安装与设置步骤如下:
[1] 光盘启动,出现“boot:”提示符,直接按回车进入图形安装界面。
[2] 出现是否对CD媒体进行测试的提问,这里选择“Skip”跳过测试。
[3] 图形安装模式启动,点击“Next”。
[4] 语言选择,这里不用中文,而用默认的英文。
[5] 选择键盘布局模式,这里根据自己具体的情况来选择。中国大陆一般为“U.S.English”。
[6] 安装类型选择,这里选择“Server”(服务器)进行服务器安装。
[7] 硬盘分区设置,这里选择“Automatically Partition”进行自动分区。
[8] 选择自动分区模式,这里选择“Remove all partitions on this system”来删除硬盘上所有的分区。请确认硬盘上的确没有重要的数据在上面,否则请事前做好数据备份。
[9] 硬盘分区设置的确认,这里点击“Yes”。
[10] 硬盘分区后的分割状态,在此可以了解安装后硬盘的分割状态。点击“Next”进入下一步。
[11] 引导程序的配置,这里全部保持默认设置,点击“Next进入下一步”。
[12] 网络配置,这里需要根据自己的实际情况来配置。特别,eth0的IP地址不能够与局域网中其他计算机的IP地址重复。
[13] 防火墙与SELinux的配置,这里防火墙要选择启动的状态,然后给窗口中各个服务的复选项打勾,接受这些服务的连接。
SELinux选择“Warn”(警告)。
[14] 语言设置,在默认“English(USA)”被安装的基础上,找到简体中文、繁体中文等等的复选项,将它们打勾安装到系统中。但在这里为了省去解决CUI下文字显示方面的繁琐,默认语言选择“English(USA)”。
[15] 时区设定,这里根据自己所在的时区选择相应的城市。
[16] root密码设置。root作为系统的全权拥有者,对系统有百分之一百的修改与访问权,所以这个密码建议设置的比较复杂一些,最好包括数字、大写英文字母、小写英文字母,以及符号的混合。
[17] 软件包选择,这里为了精简系统的目的,把所有默认的复选项的勾全部去掉,然后只选择“Development Tools”(开发工具)一项。
CentOS 4.4 的安装后初始环境设定
安装完毕重新启动系统后,出现如下的状态:
CentOS release 4.4 (Final) Kernel
2.6.9-42.EL on an i686
localhost login: ← 根据安装时网络设置的情况的不同,“localhost”显示的是你设置好的主机名。
|
[1] 系统的登录与退出
localhost login: root ← 用root用户来登录系统,输入用户名root Password: ← 在这里输入安装时设置的root密码,输入时密码不会被显示
[root@localhost ~]# ← root用户登录成功,提示符为“#”。若一般用户登录成功后,提示符为“$”
[root@localhost ~]# exit ← 退出系统
localhost login: ← 退出系统成功
|
[2] 一般用户的建立与删除
[root@localhost ~]# useradd digeast ← 建立用户名为 digeast 的一般用户 [root@localhost ~]# passwd digeast ← 为用户 digeast 设置密码 Changing password for user digeast. New UNIX password: ← 输入密码(密码不会被显示) Retype new UNIX password: ← 再次输入密码确认两次密码一致 passwd: all authentication tokens updated successfully. ← 密码设置成功
[root@localhost ~]# userdel -r digeast ← 删除用户名为 digeast 的一般用户
|
[3] 通过一般用户登录为root用户
因为root用户对系统具有全权的操作权限,为了避免一些失误的操作,建议在一般情况下,以一般用户登录系统,必要的时候需要root操作权限时,再通过“su -”命令来登录为root用户进行操作。
[digeast@localhost ~]$ ← 提示符为“$”,说明当前状态为一般用户digeast登录在系统中
[digeast@localhost ~]$ su - ← 输入登录为root用户的命令 Password: ← 输入root密码(密码不会被显示),回车
[root@localhost ~]# ← 成功登录为root用户,提示符变为“#”
[root@localhost ~]# exit ← 回到一般用户的登录状态
[digeast@localhost ~]$ ← 提示符变为“$”,回到了一般用户digeast登录系统的状态
|
[4] 建立管理员组内一般用户
在 一般情况下,一般用户通过执行“su -”命令、输入正确的root密码,可以登录为root用户来对系统进行管理员级别的配置。但是,为了更进一步加强系统的安全性,有必要建立一个管理员的组,只允许这个组的用户来执行“su -”命令登录为root用户,而让其他组的用户即使执行“su -”、输入了正确的root密码,也无法登录为root用户。在UNIX下,这个组的名称通常为“wheel”。
[root@localhost ~]# usermod -G wheel digeast ← 将一般用户 digeast 加在管理员组wheel组中
[root@localhost ~]# vi /etc/pam.d/su ← 打开这个配置文件
#auth required /lib/security/$ISA/pam_wheel.so use_uid ← 找到此行,去掉行首的“#” ↓ auth required /lib/security/$ISA/pam_wheel.so use_uid ← 变为此状态(大约在第6行的位置)
[root@localhost ~]# echo "SU_WHEEL_ONLY yes" >> /etc/login.defs ← 添加语句到行末
|
以上操作完成后,可以再建立一个新用户,然后用这个新建的用户测试会发现,没有加入到wheel组的用户,执行“su -”命令,即使输入了正确的root密码,也无法登录为root用户。
[5] 建立PPPoE连接(非xDSL接入方式的用户可跳过此步骤)
[root@localhost ~]# adsl-setup ← 建立ADSL连接
Welcome to the ADSL client setup. First, I will run some checks on your system to make sure the PPPoE client is installed properly...
LOGIN NAME
Enter your Login Name (default root): ← 填入ADSL连接的用户名(这里以digeast为例)
INTERFACE
Enter the Ethernet interface connected to the ADSL modem For Solaris, this is likely to be something like /dev/hme0. For Linux, it will be ethX, where 'X' is a number. (default eth0): ← 指定网络接入设备,一块网卡的情况下,一般为默认eth0
Do you want the link to come up on demand, or stay up continuously? If you want it to come up on demand, enter the idle time in seconds after which the link should be dropped. If you want the link to stay up permanently, enter 'no' (two letters, lower-case.) NOTE: Demand-activated links do not interact well with dynamic IP addresses. You may have some problems with demand-activated links. Enter the demand value (default no): ← 直接按回车,接受默认设置
DNS
Please enter the IP address of your ISP's primary DNS server. If your ISP claims that 'the server will provide dynamic DNS addresses', enter 'server' (all lower-case) here. If you just press enter, I will assume you know what you are doing and not modify your DNS setup. Enter the DNS information here: ← 如果知道DNS服务器的信息在此填入。不知道的情况按回车跳过
PASSWORD
Please enter your Password: ← 输入ADSL的连接密码 Please re-enter your Password: ← 再次确认输入ADSL的连接密码
USERCTRL
Please enter 'yes' (two letters, lower-case.) if you want to allow normal user to start or stop DSL connection (default yes): no ← 填入no,不允许一般用户控制PPPoE的连接
FIREWALLING
Please choose the firewall rules to use. Note that these rules are very basic. You are strongly encouraged to use a more sophisticated firewall setup; however, these will provide basic security. If you are running any servers on your machine, you must choose 'NONE' and set up firewalling yourself. Otherwise, the firewall rules will deny access to all standard servers like Web, e-mail, ftp, etc. If you are using SSH, the rules will block outgoing SSH connections which allocate a privileged source port.
The firewall choices are: 0 - NONE: This script will not set any firewall rules. You are responsible for ensuring the security of your machine. You are STRONGLY recommended to use some kind of firewall rules. 1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation 2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway for a LAN Choose a type of firewall (0-2): 0 ← 输入0,不在这里使用防火墙
Start this connection at boot time
Do you want to start this connection at boot time? Please enter no or yes (default no): yes ← 填入yes,在系统启动时自动连接ADSL
** Summary of what you entered **
Ethernet Interface: eth0 User name: caun870293@ca.dti.ne.jp Activate-on-demand: No DNS: Do not adjust Firewalling: NONE User Control: no Accept these settings and adjust configuration files (y/n)? y ← 配置信息确认无误后,键入y同意设置 Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0 Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets (But first backing it up to /etc/ppp/chap-secrets.bak) (But first backing it up to /etc/ppp/pap-secrets.bak)
?
Congratulations, it should be all set up!
Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0' to bring it down. Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0' to see the link status.
|
然后,启动ADSL连接。
[root@localhost ~]# adsl-start ← 启动ADSL连接
[root@localhost ~]# ← 稍等片刻后若启动成功后出现提示符(无任何提示即意味着连接成功)
|
这时,通过“ifconfig”命令可以看到各网络接口的信息(IP地址等等)。
[6] root邮件的转送
在系统出现错误或有重要通知发送邮件给root的时候,让系统自动转送到我们通常使用的邮箱中,这样方便查阅相关报告和日志。
[root@localhost ~]# sed -i '/^root:/d' /etc/aliases ← 删除旧的root邮件转送设定
[root@localhost ~]# echo "root: yourname@yourserver.com" >> /etc/aliases ← 加入自己的邮箱地址
[root@localhost ~]# newaliases ← 重建aliasesdb /etc/aliases: 79 aliases, longest 19 bytes, 825 bytes total
[root@localhost ~]# echo test|mail root ← 发送测试邮件给root
|
如果成功的话,会在刚刚填入的 yourname@yourserver.com 的邮箱中收到测试的邮件。
[7] locate命令用数据库更新及自动更新设定
locate命令是Linux下告诉搜索文件用的工具,它的原理和Windows下的“Google桌面搜索”有点类似,是通过事先建立数据库的方式,来达到高速查找目标文件的目的。
[root@localhost ~]# updatedb ← 运行locate数据库更新命令,稍等片刻…更新成功后出现提示符
[root@localhost ~]# vi /etc/updatedb.conf ← 编辑locate数据库更新配置文件
DAILY_UPDATE=no ← 找到这一行,将“no”改为“yes” ↓ DAILY_UPDATE=yes ← 变为此状态后,保存、退出
|
[8] 停止打印服务
如果不准备提供打印服务,停止默认被设置为自动启动的打印服务。
[root@localhost ~]# /etc/rc.d/init.d/cups stop ← 停止打印服务 Stopping cups: [ OK ] ← 停止服务成功,出现“OK”
[root@localhost ~]# chkconfig cups off ← 禁止打印服务自动启动
[root@localhost ~]# chkconfig --list cups ← 确认打印服务自启动设置状态 cups 0:off 1:off 2:off 3:off 4:off 5:off 6:off ← 0-6都为off的状态就OK(当前打印服务自启动被禁止中)
|
[9] 系统的重新启动与关闭
3:用 Apache 构建 HTTP 服务器
对于大多数的网络服务器,最广泛的功能就是开通HTTP服务,达到开放和发布网站的目的。目前绝大多数的网络交互程序,例如论坛、社区等等也是基于HTTP而建立的。
在这里,我们通过Web服务器软件中,使用量超过半数的自由软件Apache,来构建一台和我们看到的一般的网站具有相同功能的服务器,使它能够在我 们发布网页的基础上,实现可以运行Perl、PHP的等等语言编写的交互程序,以及在虚拟主机、保密方面的功能的实现。
首先来安装Apache服务器及相关组件。这里使用yum命令来在线安装。
[root@localhost ~]# yum -y install httpd ← 在线安装httpd
Setting up Install Process Setting up repositories dag 100% |=========================| 1.1 kB 00:00 update 100% |=========================| 951 B 00:00 base 100% |=========================| 1.1 kB 00:00 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Reading repository metadata in from local files Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only Finished Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for httpd to pack into transaction set. httpd-
2.0.52-28.ent.cento 100% |=========================| 62 kB 00:00
---> Package httpd.i386 0:2.0.52-28.ent.centos4 set to be updated --> Running transaction check --> Processing Dependency: libaprutil-0.so.0 for package: httpd --> Processing Dependency: apr >= 0.9.4-24.2 for package: httpd --> Processing Dependency: libapr-0.so.0 for package: httpd --> Processing Dependency: httpd-suexec for package: httpd --> Restarting Dependency Resolution with new changes. --> Populating transaction set with selected packages. Please wait. ---> Downloading header for apr to pack into transaction set. apr-0.9.4-24.5.c4.1.i386. 100% |=========================| 7.5 kB 00:00 ---> Package apr.i386 0:0.9.4-24.5.c4.1 set to be updated ---> Downloading header for httpd-suexec to pack into transaction set. httpd-suexec-2.0.52-28.en 100% |=========================| 22 kB 00:00 ---> Package httpd-suexec.i386 0:2.0.52-28.ent.centos4 set to be updated ---> Downloading header for apr-util to pack into transaction set. apr-util-0.9.4-21.i386.rp 100% |=========================| 5.2 kB 00:00 ---> Package apr-util.i386 0:0.9.4-21 set to be updated --> Running transaction check
Dependencies Resolved
============================================================================= Package Arch Version Repository Size ============================================================================= Installing: httpd i386
2.0.52-28.ent.centos4 update 888 k
Installing for dependencies:
apr i386 0.9.4-24.5.c4.1 base 88 k
apr-util i386 0.9.4-21 base 51 k
httpd-suexec i386 2.0.52-28.ent.centos4 update 28 k
Transaction Summary ============================================================================= Install 4 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size:
1.0 M
Downloading Packages:
(1/4): apr-
0.9.4-24.5.c4. 100% |=========================| 88 kB 00:00
(2/4): httpd-suexec-2.0.5 100% |=========================| 28 kB 00:00
(3/4): httpd-2.0.52-28.en 100% |=========================| 888 kB 00:02
(4/4): apr-util-0.9.4-21. 100% |=========================| 51 kB 00:00
warning: rpmts_HdrFromFdno: V3 DSA signature: NOKEY, key ID 443e1821
Public key for apr-0.9.4-24.5.c4.1.i386.rpm is not installed
Retrieving GPG key from http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
Imp
orting GPG key 0x443E1821 "CentOS-4 key <centos-4key@centos.org>"
Key imp
orted successfully
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: apr ######################### [1/4]
Installing: apr-util ######################### [2/4]
Installing: httpd ######################### [3/4]
Installing: httpd-suexec ######################### [4/4]
Installed: httpd.i386 0:
2.0.52-28.ent.centos4
Dependency Installed: apr.i386 0:0.9.4-24.5.c4.1 apr-util.i386 0:0.9.4-21 httpd-suexec.i386 0:2.0.52-28.ent.centos4 Complete!
|
为了使服务器开通HTTP服务后能够运行PHP编写的交互程序,接下来安装PHP。
[root@localhost ~]# yum -y install php ← 在线安装PHP
Setting up Install Process Setting up repositories Reading repository metadata in from local files Reducing Dag RPM Repository for Red Hat Enterprise Linux to included packages only Finished Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for php to pack into transaction set. php-
4.3.9-3.15.i386.rpm 100% |=========================| 23 kB 00:00
---> Package php.i386 0:4.3.9-3.15 set to be updated --> Running transaction check --> Processing Dependency: php-pear for package: php --> Restarting Dependency Resolution with new changes. --> Populating transaction set with selected packages. Please wait. ---> Downloading header for php-pear to pack into transaction set. php-pear-4.3.9-3.15.i386. 100% |=========================| 33 kB 00:00 ---> Package php-pear.i386 0:4.3.9-3.15 set to be updated --> Running transaction check
Dependencies Resolved
============================================================================= Package Arch Version Repository Size ============================================================================= Installing: php i386
4.3.9-3.15 update
1.3 M
Installing for dependencies:
php-pear i386 4.3.9-3.15 update 266 k
Transaction Summary ============================================================================= Install 2 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size:
1.6 M
Downloading Packages:
(1/2): php-pear-
4.3.9-3.1 100% |=========================| 266 kB 00:00
(2/2): php-4.3.9-3.15.i38 100% |=========================| 1.3 MB 00:01
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php ######################### [1/2]
Installing: php-pear ######################### [2/2]
Installed: php.i386 0:
4.3.9-3.15
Dependency Installed: php-pear.i386 0:4.3.9-3.15 Complete!
|
为了使PHP应用程序的执行效率大幅度提高,我们安装Zend。
[root@localhost ~]# wget http://downloads.zend.com/optimizer/
3.0.1/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz
← 下载Zend的源代码
--13:19:06-- http://downloads.zend.com/optimizer/
3.0.1/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz
=> `ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz'
Resolving downloads.zend.com... 66.98.224.81
Connecting to downloads.zend.com|66.98.224.81|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6,358,090 (
6.1M) [application/gzip]
100%[====================================>] 6,358,090 240.53K/s ETA 00:00
13:19:33 (238.15 KB/s) - `ZendOptimizer-
3.0.1-linux-glibc21-i386.tar.gz' saved [6358090/6358090]
[root@localhost ~]# tar zxvf ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz ← 展开被压缩的源代码
[root@localhost ~]# cd ZendOptimizer* ← 进入Zend的源代码目录
[root@localhost ZendOptimizer-3.0.1-linux-glibc21-i386]# ./install.sh ← 运行安装脚本
|
然后会出现对话方式的安装向导,图样如下:
[1] 选择OK,进入安装向导。
[2] 阅读协议后,选择EXIT。
[3] 选择Yes同意使用协议。
[4] 设置安装目录,这里以默认的/usr/local/Zend为例,然后选择OK进入下一步。
[5] 设置PHP配置文件所在的位置,一般为/etc(默认),如果PHP的配置文件在别处的话,请根据实际情况设置。
[6] 被询问是否使用Apache服务器,这里选择Yes。
[7] 设置Apache的路径,这里保持默认,选择OK进入下一步。
[8] 选择OK进入下一步。
[9] 然后开始安装…稍等片刻,安装完成后,提示安装成功,选择OK进入下一步。
[10] 选择No,不重新启动HTTP服务(由于Apache也刚刚安装完毕,还没有被启动过。为了安全,等我们将Apache配置完毕后,再启动HTTP服务。)。然后会出现命令行 -- Zend Optimizer安装完毕。
接下来,为了使服务器更安全以及更加符合我们的实际要求,对默认的设置进行一些必要的更改。尤其在一些细节方面,越少向外界透露服务器的信息,就越能保证服务器的安全。
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf ← 编辑Apache的配置文件
# # Don't give away too much information about all the subcomponents # we are running. Comment out this line if you don't mind remote sites # finding out what major optional modules you are running ServerTokens OS ← 找到这一行,将“OS”改为“Prod”(在出现错误页的时候不显示服务器操作系统的名称) ↓ ServerTokens Prod ← 变为此状态
# # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin@your-domain.com # ServerAdmin root@localhost ← 将管理员邮箱设置为自己常用的邮箱 ↓ ServerAdmin yourname@yourserver.com ← 根据实际情况修改默认设置
# # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If this is not set to valid DNS name for your host, server-generated # redirections will not work. See also the UseCanonicalName directive. # # If your host doesn't have a registered DNS name, enter its IP address here. # You will have to access it by its address anyway, and this will make # redirections work in a sensible way. # #ServerName new.host.name:80 ← 修改主机名 ↓ ServerName www.centospub.com:80 ← 根据实际情况修改,端口号保持默认的80
# # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs-2.0/mod/core.html#options # for more information. # Options Indexes FollowSymLinks ← 找到这一行,删除“Indexes”,并添加“Includes”、“ExecCGI” ↓ Options Includes ExecCGI FollowSymLinks ← 允许服务器执行CGI及SSI
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None ← 找到这一行,将“None”改为“All” ↓ AllowOverride All ← 变为此状态,允许.htaccess
# # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined ← 找到这一行 ↓ LogFormat "%h %l %u %t "%!414r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined ← 改为此状态(添加“!
414”
到规则中,对于过长的日志不记录)
# # Optionally add a line containing the server version and virtual host # name to server-generated pages (internal error documents, FTP directory # listings, mod_status and mod_info output etc., but not CGI generated # documents or custom error documents). # Set to "EMail" to also include a mailto: link to the ServerAdmin. # Set to one of: On | Off | EMail # ServerSignature On ← 找到这一行,将“On”改为“Off” ↓ ServerSignature Off ← 在错误页中不显示Apache的版本
# # Specify a default charset for all pages sent out. This is # always a good idea and opens the door for future internationalisation # of your web site, should you ever want it. Specifying it as # a default does little harm; as the standard dictates that a page # is in iso-8859-1 (latin1) unless specified otherwise i.e. you # are merely stating the obvious. There are also some security # reasons in browsers, related to javascript and URL parsing # which encourage you to always set a default char set. # AddDefaultCharset UTF-8 ← 找到这一行,在行首添加“#” ↓ #AddDefaultCharset UTF-8 ← 不使用UTF-8作为网页的默认编码 AddDefaultCharset GB2312 ← 并接着添加这一行(添加GB2312为默认编码)
# # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi ← 找到这一行,去掉行首的“#”,并在行尾添加“.pl” ↓ AddHandler cgi-script .cgi .pl ← 允许扩展名为.pl的CGI脚本运行
<Directory "/var/www/icons"> ← 找到这一个标签,并在标签中更改相应选项 Options Indexes MultiViews ← 找到这一行,将“Indexes”删除 ↓ Options MultiViews ← 变为此状态(不在浏览器上显示树状目录结构) AllowOverride None Order allow,deny Allow from all </Directory>
[root@localhost ~]# rm -f /etc/httpd/conf.d/welcome.conf ← 删除测试页
[root@localhost ~]# rm -f /var/www/error/noindex.html ← 删除测试页
|
然后,启动HTTP服务。
[root@localhost ~]# /etc/rc.d/init.d/httpd start ← 启动HTTP服务 Starting httpd: [ OK ] ← 启动成功会出现OK 如果启动失败的话,会出现错误信息。原因可能是因为httpd.conf文件编辑过程中的失误,请检查httpd.conf。
[root@localhost ~]# chkconfig httpd on ← 设置HTTP服务自启动
[root@localhost ~]# chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2--5为on的状态就OK
|
然后,初步对HTTP服务进行简单测试。如下:
[root@localhost ~]# echo hello >> /var/www/html/index.html ← 建立测试页
|
然后,在下面输入服务器的IP地址,或域名(通过ifconfig命令可以看到IP地址;或者通过前面介绍过的“动态域名的申请”中的方法设置成功的域名来测试。)
如果成功的话会出现类似如下的页面:
然后,删除刚刚建立的测试页。
[root@localhost ~]# rm -f /var/www/html/index.html ← 删除测试页
|
[1] 对HTML格式网页正确显示的测试
[root@localhost ~]# vi /var/www/html/index.html ← 建立测试页,内容如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Hello,World!</title> <body> Hello,World! </body> </html>
|
然后在浏览器中输入“http://服务器IP地址”或者“http://你的域名”,如果出现“Hello,World!”,并且浏览器读取编码为简体中文,就OK。
为了在这之后测试.htaccess,将默认为主页的index.html测试页删除。
[root@localhost ~]# rm -f /var/www/html/index.html ← 删除刚刚测试用的网页
|
[2] 对CGI的支持进行测试
[root@localhost ~]# vi /var/www/html/test.cgi ← 建立CGI测试页,内容如下:
#!/usr/bin/perl print "Content-Type: text/htmlnn"; print "<html>n"; print "<head>n"; print "<meta http-equiv="Content-Type" content="text/html; charset=GB2312">n"; print "<title>Hello,World!</title>n"; print "</head>n"; print "<body>n"; print "Hello,World!CGI is working!n"; print "</body>n"; print "</html>n";
[root@localhost ~]# chmod 755 /var/www/html/test.cgi ← 然后将CGI测试文件属性设置为755
|
然后在浏览器中输入“http://服务器IP地址/test.cgi”或者“http://你的域名/test.cgi”,如果正确显示“Hello,World!CGI is working!”,说明对于CGI的支持没有问题。
[3] 对SSI进行测试
[root@localhost ~]# vi /var/www/html/test.shtml ← 建立SSI测试页,内容如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Hello,World!</title> <body> TEST SSI <!--#config timefmt="%Y/%m/%d %H:%M:%S" --> <!--#echo var="DATE_LOCAL" --> </body> </html>
|
然后在浏览器中输入“http://服务器IP地址/test.shtml”或者“http://你的域名/test.shtml”,如果正确显示当时的日期和时间,说明对于SSI的支持没有问题。
[4] 对.htaccess的支持进行测试
[root@localhost ~]# vi /var/www/html/index.shtml ← 建立.htaccess测试用的页,内容如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Hello,World!</title> <body> The name of the file is <!--#echo var="DOCUMENT_NAME" --> </body> </html>
|
然后在浏览器中输入“http://服务器IP地址”或者“http://你的域名”,如果显示“Forbidden”,说明.htaccess正常。
然后建立一个.htaccess文件,并定义相应规则,如下:
[root@localhost html]# vi /var/www/html/.htaccess ← 建立.htaccess文件,内容如下:
DirectoryIndex index.shtml
|
这时,再次在浏览器中输入“http://服务器IP地址”或者“http://你的域名”,如果正确显示“ The name of the file is index.shtml”,说明.htaccess中的规则生效状态,OK。
[5] 对PHP的支持进行测试
[root@localhost html]# vi /var/www/html/test.php ← 建立PHP测试文件,内容如下:
<?php phpinfo(); ?>
|
然后在浏览器中输入“http://服务器IP地址/test.php”或者“http://你的域名/test.php”后,正确的显示出了服务器上PHP的详细信息,说明对PHP可以正确的支持。
[6] 删除测试用的遗留文件