Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

php - How to show "Your Virtual Hosts" list in wamp 2.5 homepage

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>
";;

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

  • Edit the wampwampmanager.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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...