下載Apache:http://httpd.apache.org/download.cgi
安裝步驟略過。。。。
安裝完 Apache 程式後,Monitor apache servers 無法啟動,表徵圖顯示為紅色停止標誌。滑鼠移至工作列 Apache 服務表徵圖顯示 “No services installed”,原因如下:
Apache 服務沒有安裝成功
如果 Apache 服務程式成功安裝,那麼我們可以通過右鍵“我的電腦” -》“管理” -》“服務和應用程式” -》“服務” 可以看到右側列表中存在 apache 服務,如不存在,則表示伺服器沒有被安裝成功。具體解決辦法如下:
1)運行中鍵入: cmd 進入 dos 操作介面;
2)進入Apache安裝目錄:
cd C:/Program Files/Apache Software Foundation/Apache2.2/bin
3)鍵入命令:
httpd.exe -k install -n apache2
添加apache為服務,在 apache2 中有的版本中是
apache.exe -k install -n apache2。
4)啟動服務。鍵入命令:net start apache2。
如果apache不能啟動,將 httpd.conf 檔案中 ServerName 去掉#注釋,修改原來的主機名稱為 localhost ,80連接埠如被佔用,用 netstat -anb 查出佔用的進程,終止相關進程的程式,或者換一個連接埠號碼。
將php以module方式與Apache相結合,使php融入Apache
開啟httpd.conf,添加以下五行:
LoadModule php5_module C:/PHP/php5apache2_2.dll
LoadFile C:/PHP/libeay32.dll
LoadFile C:/PHP/ssleay32.dll
PHPIniDir "C:/PHP" #php.ini 檔案的所在目錄
AddType application/x-httpd-php .php
找到
DirectoryIndex index.html
改為:
DirectoryIndex index.php index.html
———————————————————
以下方式更工整,效果同上
找到:
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
在後面添加一行
LoadModule php5_module C:/PHP/php5apache2_2.dll
LoadFile C:/PHP/libeay32.dll
LoadFile C:/PHP/ssleay32.dll
PHPIniDir "C:/PHP"
找到:
AddType application/x-gzip .gz .tgz
在後面添加一行
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html #加入此行則.html檔案也可以執行php程式
libeay32.dll 和 ssleay32.dll 這兩個檔案是 php.ini 檔案中啟用了 extension=php_curl.dll 擴充的情況下才需要調用,如果沒有開啟此擴充,可以刪除調用兩個檔案的兩行代碼。
========================================================================
添加虛擬機器主機的步驟:
找到
ServerAdmin
前面打上”#”(不含雙引號),也就是把這段注釋掉.
找到
DocumentRoot "DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
這個是你安裝apache的位置,自己應該曉得把這段也打上”#”,注釋掉.
假如,虛擬空間的各個網站都在D盤的wwwroot目錄下,那麼請添加這段
<Directory "D:/wwwroot">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
這個很重要,接下來,就把各個網站都放在wwwroot目錄下,才能正常訪問.
找到
#Include conf/extra/httpd-vhosts.conf
取消前面的#注釋,使之生效
接著就可以到extra目錄中,對httpd-vhosts.conf進行設定,添加網站
例子如下:
<VirtualHost *:80>
ServerAdmin webmaster@網域名稱.com
DocumentRoot "D:/wwwroot/網域名稱.com/www"
ServerName 網域名稱.com
ServerAlias www.網域名稱.com
ErrorLog "D:/wwwroot/網域名稱.com/logs/網域名稱.com-error.log"
CustomLog "D:/wwwroot/網域名稱.com/logs/網域名稱.com-access.log" common
</VirtualHost>
</Directory>
如果要為該網站建立虛擬目錄(檔案對應),請在<VirtualHost *:80></VirtualHost>標籤內添加以下內容:
Alias /uploads "D:/wwwroot/網域名稱.com/www/wp-content/uploads"
<Directory "D:/wwwroot/網域名稱.com/www/wp-content/uploads">
Order allow,deny
Allow from all
</Directory>
通過虛擬目錄(檔案對應),Regex:
http://www.網域名稱.com/wp-content/uploads/
將可通過以下別名的方式進行訪問:
http://www.網域名稱.com/uploads/
如果,需要用到rewrite的html靜態功能,
請在httpd.conf檔案中,找到
#LoadModule rewrite_module modules/mod_rewrite.so
取消掉前面的#注釋,使mod_rewrite.so模組生效
並且把所有的
AllowOverride None
更改為
AllowOverride All
好了,一切都ok了,別忘記restat Apache