CentOS安装Apache详解
有时候安装Apache会碰到apr not found的解决方法,请看下面链接文章http://blog.sina.com.cn/s/blog_61c07ac501017pb9.html
言归正传,开始
安装HTTP(Apache)服务器及相关组件
安装Apache服务器及相关组件
# yum -y install httpd\* ← 在线安装httpd
为了使服务器开通HTTP服务后能够运行PHP编写的交互程序
# yum -y install php\* ← 在线安装PHP
为了使PHP应用程序的执行效率大幅度提高需要安装Zend
#wget http://downloads.zend.com/optimizer/3.0.1/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz ← 下载Zend的源代码
# tar zxvf ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz ← 展开被压缩的源代码
# cd ZendOptimizer* ← 进入Zend的源代码目录
# ./install.sh ← 运行安装脚本
配置HTTP(Apache)服务器
接下来,为了使服务器更安全以及更加符合实际要求,对默认的设置进行一些必要的更改。尤其在一些细节方面,越少向外界透露服务器的信息,就越能保证服务器的安全。
# vi etc/httpd/conf/httpd.conf ← 编辑Apache的配置文件
ServerTokens OS ← 找到这一行,将“OS”改为“Prod”(在出现错误页的时候不显示服务器操作系统的名称)
↓
ServerTokens Prod ← 变为此状态
ServerSignature On ← 找到这一行,将“On”改为“Off”
↓
ServerSignature Off ← 在错误页中不显示Apache的版本
ServerAdmin root@localhost ← 将管理员邮箱设置为自己常用的邮箱
↓
ServerAdmin yourname@yourserver.com ← 根据实际情况修改默认设置
#ServerName new.host.name:80 ← 修改主机名
↓
ServerName www.centospub.com:80 ← 根据实际情况修改,端口号保持默认的80
Options Indexes FollowSymLinks ← 找到这一行,删除“Indexes”,并添加“Includes”、“ExecCGI”
↓
Options Includes ExecCGI FollowSymLinks ← 允许服务器执行CGI及SSI
#AddHandler cgi-script .cgi ← 找到这一行,去掉行首的“#”,并在行尾添加“.pl”
↓
AddHandler cgi-script .cgi .pl ← 允许扩展名为.pl的CGI脚本运行
AllowOverride None ← 找到这一行,将“None”改为“All”
↓
AllowOverride All ← 变为此状态,允许.htaccess
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”到规则中,对于过长的日志不记录)
AddDefaultCharset UTF-8 ← 找到这一行,在行首添加“#”
↓
#AddDefaultCharset UTF-8 ← 不使用UTF-8作为网页的默认编码
AddDefaultCharset GB2312 ← 并接着添加这一行(添加GB2312为默认编码)
← 找到这一个标签,并在标签中更改相应选项
Options Indexes MultiViews ← 找到这一行,将“Indexes”删除
↓
Options MultiViews ← 变为此状态(不在浏览器上显示树状目录结构)
# rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html ← 删除测试页
启动HTTP服务
# chkconfig httpd on ← 设置HTTP服务自启动
# chkconfig –list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← 确认2–5为on的状态就OK
# /etc/rc.d/init.d/httpd start ← 启动HTTP服务
Starting httpd: [ OK ] ← 启动成功会出现OK
如果启动失败的话,会出现错误信息。原因可能是因为httpd.conf文件编辑过程中的失误,请检查httpd.conf。
对HTTP服务进行简单测试
# echo hello >> /var/www/html/index.html ← 建立测试页
删除刚刚建立的测试页
# rm -f /var/www/html/index.html ← 删除测试页
对HTTP服务进行全面测试
对HTML格式网页正确显示的测试
# vi /var/www/html/index.html ← 建立测试页,内容如下:
< head>
< meta http-equiv=”Content-Type” content=”text/html; ″>
< body>
Hello,World!
< /body>
< /html>
在浏览器中输入“http://服务器IP地址”或者“http://你的域名”,如果出现“Hello,World!”,并且浏览器读取编码为简体中文,就OK。
对CGI的支持进行测试
# vi /var/www/html/test.cgi ← 建立CGI测试页,内容如下:
#!/usr/bin/perl
print “Content-Type: text/html\n\n”;
print “”;
print “Hello,World!CGI is working!”;
print “”;
# chmod 755 /var/www/html/test.cgi ← 然后将CGI测试文件属性设置为755
在浏览器中输入“http://服务器IP地址/test.cgi”或者“http://你的域名/test.cgi”,如果正确显示“Hello,World!CGI is working!”,说明对于CGI的支持没有问题。
对PHP的支持进行测试
# vi /var/www/html/test.php ← 建立PHP测试文件,内容如下:
在浏览器中输入“http://服务器IP地址/test.php”或者“http://你的域名/test.php”后,正确的显示出了服务器上PHP的详细信息,说明对PHP可以正确的支持。
对SSI进行测试
# vi /var/www/html/test.shtml ← 建立SSI测试页,内容如下:
< head>
< meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″>
< 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的支持没有问题。
对.htaccess的支持进行测试
# vi /var/www/html/index.shtml ← 建立.htaccess测试用的页,内容如下:
< head>
< meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″>
< body>
The name of the file is
< /body>
< /html>
在浏览器中输入“http://服务器IP地址”或者“http://你的域名”,如果显示“Forbidden”,说明.htaccess正常。
建立一个.htaccess文件,并定义相应规则,如下:
# vi /var/www/html/.htaccess ← 建立.htaccess文件,内容如下:
DirectoryIndex index.shtml
在浏览器中输入“http://服务器IP地址”或者“http://你的域名”,如果正确显示“ The name of the file is index.shtml”,说明.htaccess中的规则生效状态,OK。
Apache 日志文件
#vi /var/log/httpd/error_log ← Apache 日志文件
原文地址:http://www.cnyunwei.com/forum.php?mod=viewthread&tid=9053
页:
[1]