1. 程式人生 > >WampServer新增多站點

WampServer新增多站點

首頁安裝正常的WampServer,安裝成功後能夠正常執行。如下圖:


下面第一步就是安裝第二個apache服務

一、找到Apache2的htppd.conf檔案.例如:我的wamp是安裝在I盤的,我的就是I:\wamp\bin\apache\apache2.2.22\conf目錄下。 
二、複製httpd.conf,粘貼後在conf目錄下後更名httpd2.conf(這裡httpd2.conf是自定義的。)
三、用用編輯器開啟httpd2.conf 找到如下幾行程式碼 (不在一起的)

Listen 80 
ServerName localhost:80
DocumentRoot "i:/wamp/www/"
<Directory "i:/wamp/www/">
更改為  
Listen 8080 //apache服務新監聽的埠,可根據自己需要進行修改
ServerName localhost:8080 
DocumentRoot "i:/wamp/www2/" //www2是我們第二個網站的目錄 
<Directory "i:/wamp/www2/">
然後在i:/wamp下建一新資料夾為 www2 
四、接下來就是安裝服務了, 
在桌面或其他地方新建個文字,貼入下面內容(注意目錄)
cd /d i:\wamp\bin\apache\apache2.2.22\bin
httpd.exe -k install -n "www2" -f "i:\wamp\bin\apache\apache2.2.22\conf\httpd2.conf"
儲存,然後將擴充套件後改成.bat,雙擊即可。
然後我們在www2下放一個html檔案來做測試,在瀏覽器中輸入 http://localhost:8080 OK。服務正常。如果此時無法訪問,可能是因為服務還沒啟動,在windows服務中會有個我們剛剛新增的名為www2服務,如下圖,啟動他即可正常訪問8080地址了


第二步要做的就是用wamp控制檯來控制新安裝的服務 

一、開啟wamp目錄,找到wampmanager.ini用編輯器開啟

二、相關的修改

其實主要就是全部停止服務、全部啟動服務、地址、目錄幾個配置,只要看到  Service: wampapache 之類的配置然後在下面再加行  Service: www2配置就可以了

在這裡有個需要注意的就是在配置之前先前  wampmanager.tpl 改名,不然如果配置檔案裡的配置與  wampmanager.tpl 不相符的話會自動給覆蓋掉。

下面的修改供參考:

[Services]
Name: wampapache
Name: wampmysqld
Name: www2

[StartupAction]
;WAMPSTARTUPACTIONSTART
Action: run; FileName: "i:/wamp/bin/php/php5.3.13/php-win.exe";Parameters: "refresh.php";WorkingDir: "i:/wamp/scripts"; Flags: waituntilterminated
Action: resetservices
Action: readconfig;
Action: service; Service: wampapache; ServiceAction: startresume; Flags: ignoreerrors
Action: service; Service: wampmysqld; ServiceAction: startresume; Flags: ignoreerrors
Action: service; Service: www2; ServiceAction: startresume; Flags: ignoreerrors
;WAMPSTARTUPACTIONEND

[Menu.Left]
;WAMPMENULEFTSTART
Type: separator; Caption: "Powered by Alter Way"
Type: item; Caption: "Localhost"; Action: run; FileName: "C:\Program Files\Google\Chrome\Application\chrome.exe"; Parameters: "http://localhost/"; Glyph: 5
Type: item; Caption: "Localhost 8080"; Action: run; FileName: "C:\Program Files\Google\Chrome\Application\chrome.exe"; Parameters: "http://localhost:8080/"; Glyph: 5
Type: item; Caption: "phpMyAdmin"; Action: run; FileName: "C:\Program Files\Google\Chrome\Application\chrome.exe"; Parameters: "http://localhost/phpmyadmin/"; Glyph: 5
Type: item; Caption: "www directory"; Action: shellexecute; FileName: "i:/wamp/www"; Glyph: 2
Type: item; Caption: "www2 directory"; Action: shellexecute; FileName: "i:/wamp/www2"; Glyph: 2

[StartAll]
;WAMPSTARTALLSTART
Action: service; Service: wampapache; ServiceAction: startresume; Flags: ignoreerrors
Action: service; Service: wampmysqld; ServiceAction: startresume; Flags: ignoreerrors
Action: service; Service: www2; ServiceAction: startresume; Flags: ignoreerrors

[StopAll]
;WAMPSTOPALLSTART
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors
Action: service; Service: wampmysqld; ServiceAction: stop; Flags: ignoreerrors
Action: service; Service: www2; ServiceAction: stop; Flags: ignoreerrors

[RestartAll]
;WAMPRESTARTALLSTART
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: service; Service: wampmysqld; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: service; Service: www2; ServiceAction: stop; Flags: ignoreerrors waituntilterminated
Action: service; Service: wampapache; ServiceAction: startresume; Flags: ignoreerrors waituntilterminated
Action: service; Service: wampmysqld; ServiceAction: startresume; Flags: ignoreerrors waituntilterminated
Action: service; Service: www2; ServiceAction: startresume; Flags: ignoreerrors waituntilterminated

[myexit]
;WAMPMYEXITSTART
Action: service; Service: wampapache; ServiceAction: stop; Flags: ignoreerrors
Action: service; Service: wampmysqld; ServiceAction: stop; Flags: ignoreerrors
Action: service; Service: www2; ServiceAction: stop; Flags: ignoreerrors
Action:  exit

更改完成後儲存並重啟wamp就可以了。下面是我改後的效果:


可以按此方法繼續新增多個站點。