How to show “Your Virtual Hosts” list in wamp 2.5 homepage

℡╲_俬逩灬. 提交于 2019-12-13 09:03:30

问题


There are plenty of instruction on what settings to change to show the Virtual Hosts list in the wamp homepage, however upon inspecting index.php in C://wamp/www there appeared to be no code in here to show the Virtual Hosts no matter what the settings were elsewhere. So, I have added some code in myself to show this list and thought it might help others who want to do the same.

This requires your httpd-vhosts.conf file to have entries such as the following

<VirtualHost *:80>
     DocumentRoot "C:/wamp/www/website_folder_name"
     ServerName Website_Name         #<----------This is the what index.php uses
     <Directory  "C:/wamp/www/website_folder_name">
          AllowOverride All
          Require local
     </Directory>
</VirtualHost>

Now, in C://wamp/www/index.php make the following changes:

After this line (line 65) $wampserverVersion = str_replace('"','',$result[1]);

Add:

$wampVHostsFile = $server_dir.'bin/apache/apache2.4.9/conf/extra/httpd-vhosts.conf';
if (!is_file($wampVHostsFile))
     die ('Unable to open Virtual Hosts file, please change path in index.php file');
$fp = fopen($wampVHostsFile,'r');
$wampVHostsFileContents = fread ($fp, filesize ($wampVHostsFile));
fclose ($fp);

$vHosts = "";
$result = array(1=>array(1=>786));
while(! empty($result)) {
     preg_match('|ServerName (.*)|',$wampVHostsFileContents,$result, PREG_OFFSET_CAPTURE, $result[1][1]);
     array_key_exists(1, $result) ? $vHosts .= '<li><a href="'.($suppress_localhost ? 'http://' : '').$result[1][0].'">'.$result[1][0].'</a></li>' : null;
}

if (empty($vHosts))
     $vHosts = "<li>No Virtual Hosts</li>\n";;

Then scroll to the bottom of the file and edit $pageContents containing the html. I decided I didn't want the list of aliases so comment out this code:

<div class="third right">
     <h2>{$langues[$langue]['txtAlias']}</h2>
     <ul class="aliases">
          ${aliasContents}          
     </ul>
</div>

And replace with this code:

<div class="third right">
     <h2>Your Virtual Hosts</h2>
     <ul class="aliases">
          ${vHosts}
     </ul>
</div>

回答1:


How do I turn the WAMPServer2.5 My Virtual Hosts menu on?

  • Make a backup of the \wamp\wampmanager.tpl file, just in case you make a mistake, its a very important file.

  • Edit the \wamp\wampmanager.tpl

  • Find this parameter ;WAMPPROJECTSUBMENU, its in the '[Menu.Left]' section.

  • Add this new parameter ;WAMPVHOSTSUBMENU either before or after the ;WAMPPROJECTSUBMENU parameter.

  • Save the file.

  • Now left click the wampmanager icon, and select Refresh. If this does not add the menu, 'exit' and restart wampmanager.

Note The new menu will only appear if you already have some Virtual Hosts defined! Otherwise you will see no difference until you define a Virtual Host or two.

Oh and if its @Bollis reading this, undo all the unnecessary changes you made to index.php



来源:https://stackoverflow.com/questions/24399200/how-to-show-your-virtual-hosts-list-in-wamp-2-5-homepage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!