1.安装:
rpm -q httpd
rpm -ivh httpd-...rpm
2.开放防火墙
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
3.配置文件
httpd.conf是Appache的文本配置文件,位于/etc/httpd/conf目录下
httpd.conf主要由全局配置,主服务器配置,虚拟主机配置组成
例如:
### Section 1: Global Environment
#配置文件和日志文件所在目录
ServerRoot "/etc/httpd"
#监听什么端口
#Listen 12.34.56.78:80
Listen 80
Include conf.d/*.conf
### Section 2: 'Main' server configuration
#Apache服务主目录路径,即静态网页所在目录
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
#设置默认主页
DirectoryIndex index.html index.html.var
DefaultType text/plain
CustomLog logs/access_log combined
#错误日志
ErrorLog logs/error_log
Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
#支持中文
AddDefaultCharset GB2312
4.启停服务
/etc/init.d/httpd start
/etc/init.d/httpd stop
/etc/init.d/httpd restart
ntsysv设置自动启动服务
5.CGI
5.1安装
rpm -q perl安装perl
5.2配置文件
修改httpd.conf,增加如下语句
#CGI可以执行
Options Indexes FollowSymLinks ExecCGI
#CGI支持的文件名
AddHandler cgi-script .cgi .pl
5.3测试
在/var/www/html中建立一个test.cgi的文件
#!/usr/bin/perl
print "Content-type:text/html\n\n"
print "Hello world!\n"
然后chmod +x /var/www/html/tect.cgi
浏览器中输入:http://服务器IP地址/test.cgi
6.PHP
6.1安装
rpm -q php
rpm -ivh ...
6.2 配置文件/etc/httpd/conf.d/php.conf,被httpd.conf包含(在httpd.conf中由一句话 Include conf.d/*.conf
6.2 测试
在/var/www/html中增加test.php
<?phpinfo();?>
6.3在浏览器中输入http://服务器IP/test.php测试