Linux Apache服務搭建學習

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測試

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章