Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: chillax86 (---.dynamic.dsl.as9105.com)
Date: October 30, 2016 12:56AM

When adding a virtual host listening on a different port like :8080 and editing the httpd.config to listen on both port :80 & :8080, apache serves both my websites on both ports OK.

The problem is when I refresh Wamp 3's menu the menu item 'Your VirtualHosts' contains an item with a warning symbol saying 'VirtualHost_PortValue' and when you click this menu item a command line interface opens up and says...

Sorry,
There is an error.
In the httpd-vhosts.conf files:

Port number into <VirtualHost *:port>
has not correct value or is not the same for each <VirtualHost *:xx>

Value are:Array
(
[0] => <VirtualHost *:80>
[1] => <VirtualHost *:8080>
)

Switch cancelled
Press ENTER to continue...

Also when I click on the menu item for the website on port :8080 the URL in the browser does not have the port number appended to the end of the domain name e.g. [example.com].

It is important to me to be able to hosts sites on at least two different ports as I some time give clients access to websites i'm building and on our network, IIS is on port :80.

Just to be clear apache is working well it is the wamp menu that does seem to be able to handle this sort of functionality which is a shame as I like the the new virtual host menu feature.

Is there anything I can do or should I wait for a new release of WAMP for this to be fixed?



Edited 2 time(s). Last edit at 10/30/2016 01:05AM by chillax86.

Options: ReplyQuote
Re: Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: Otomatic (Moderator)
Date: October 30, 2016 09:53AM

Hi,

Right-Click Wampmanager tray icon -> Wamp Settings -> Don't check VirtualHost definitions

Perhaps also, depending on how you define VirtualHost:
-> Don't check duplicate Server Name
-> Allow VirtualHost local IP's other than 127.*

With the menu item:
Right-Click Wampmanager tray icon ->Tools -> Use a port other than 80
you can change the port to 8080, but it will be for ALL VirtualHost defined with Wampserver.
It is impossible to mix VirtualHost on port 80 with the other on port 8080. There is only one variable that defines the listener and it is impossible to create the different calls in the menus with numbers different port.

Note : For pro, there are thousands of possibilities for defining and VirtualHost settings for Apache. It is totally impossible to check all possibilities.
Wampserver is - above all - for beginners. The pros may well use Apache, PHP and MySQL without the need for Wampserver.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons



Edited 1 time(s). Last edit at 10/30/2016 11:16AM by Otomatic.

Options: ReplyQuote
Re: Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: chillax86 (---.dynamic.dsl.as9105.com)
Date: October 30, 2016 07:16PM

Hi, thank you for your quick reply.

After posting that issue last night I decided to explore the right-click menu as I have been using WAMP server probably more than 7 years for developing on Windows and I have never really explored all the menu options.
I found the 'Right-Click Wampmanager tray icon -> Wamp Settings -> Don't check VirtualHost definitions' and I can confirm it did remove the menu item warning.

Looking at WAMP scripts, the other two options do not seem to effect the functionality I am looking for.

I also tried to change the port number like you said and this does indeed change the default port that Apache listens on and also appends the specified port number to all the URL's listed in the virtual host menu but this function also changes all of Apache's listening ports in httpd.conf to the port specified, this is a new undesirable bug. Also WAMP fails to start Apache because of the duplicate ports.

Looking at WAMP's scripts the problem boils down to the fact that there is an assumption that all listening ports must be the same because of the way the default port is set.

If you look at -> C:\wamp\scripts\switchWampPort.php on line 21 you will see that preg_replace has no limit set. Just by simply changing this...

$httpdFileContents = preg_replace($findTxtRegex,'${1}'.$portToUse, $httpdFileContents);

to this..
.
$httpdFileContents = preg_replace($findTxtRegex,'${1}'.$portToUse, $httpdFileContents, 1);

would stop the script from replacing all of Apaches ports numbers and only changes the first occurrence of each pattern in the $findTxtRegex array therefore fixing the new found undesirable bug with changing the default port. All we need to do is put a comment inside httpd.conf stating the default port for WAMP is the first port specified.

When inspecting the rest of the code its should be easy to change only entries in the virtual host config files that match the previous default port set and change them to the new port specified therefore not effecting any other virtual host with different port numbers. I do not see why these scripts are so fiercely setting everything to one port. In fact the tools menu should say change Apache default port and maybe have an extra menu item to add extra ports easily. The only real difficult part would be grabbing the different port numbers and appending them to the relative URL's for their respective menu items.

I am quite happy to help implement the changes as I will probably make the changes if you don't.

I would like to explorer the possibilities of getting this functionality, if you could get round appending the different ports to the respective URL's would you consider adding this functionality?

Note: In my first question an existing WAMP script can already grab the different ports from the virtual hosts configuration file maybe we change the refresh script to grab the virtual host port numbers and store them in an array linking the ServerName string to the port number and then rebuild the URL's using that?.



Edited 6 time(s). Last edit at 10/30/2016 09:01PM by chillax86.

Options: ReplyQuote
Re: Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: Otomatic (Moderator)
Date: October 31, 2016 09:41AM

Hi,

> If you look at -> C:\wamp\scripts\switchWampPort.php on line 21...
Ok to change the preg_replace with limit 1 and replace

$findTxtRegex[] = '/^([ \t]*<VirtualHost[ \t]+.+: ).*$/m';

by

$findTxtRegex[] = '/^([ \t]*<VirtualHost[ \t]+.+: )[^\$].*$/m';

Without space between : and ) . I write space because without it is transformed into smiley smiling smiley

and apply this:

To use one or more ports other than the default port 80, I think it would be better to use the Apache Define variables.
For example, in httpd.conf:
...
Define APACHE_DIR ${INSTALL_DIR}/bin/apache/apache${VERSION_APACHE}
Define MYPORT 80
...
#Listen 12.34.56.78:80
Listen 0.0.0.0:8080
Listen 0.0.0.0:${MYPORT}
Listen [::0]:8080
Listen [::0]:${MYPORT}
...
and, for httpd-vhosts.conf:
<VirtualHost *:${MYPORT}>

This approach is much simpler for me; it will be necessary not to change the port number by tools if it is indicated by a variable and didnt check it by a variable number indicated. There will be no big changes in the code.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons



Edited 3 time(s). Last edit at 10/31/2016 11:12AM by Otomatic.

Options: ReplyQuote
Re: Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: chillax86 (---.dynamic.dsl.as9105.com)
Date: November 01, 2016 01:32AM

I would like to suggest a different approach...

Make these changes to C:\wamp\scripts\switchWampPort.php

Change line 21 to this...
$httpdFileContents = preg_replace($findTxtRegex,'${1}'.$portToUse, $httpdFileContents, 1);

Add this...
//Grab Currently Used Port
$portInUse = $wampConf['apachePortUsed'];

Above this ..
//Replace Used Port by New port ($_SERVER['argv'][1])
$portToUse = intval(trim($_SERVER['argv'][1]));

Change line 34 (now line 36) to this...
$findTxtRegex[] = '/^([ \t]*<VirtualHost[ \t]+.+: )'.$portInUse.'(?!.[0-9]).*$/m';
Without space between : and )

Then finally change line 38 (now line 40) to this...
$findTxtRegex[] = '/^([ \t]*NameVirtualHost)'.$portInUse.'(?!.[0-9]).*$/m';

By making these changes we can now change the default port for all my virtual hosts using the default port without effecting virtual hosts using custom ports. This would not be a massive change to the code and we would not need to use a separate variable in httpd.conf

If you do favour this approach are you able get these changes committed to the next release of WAMP?



Edited 2 time(s). Last edit at 11/01/2016 01:41AM by chillax86.

Options: ReplyQuote
Re: Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: Otomatic (Moderator)
Date: November 01, 2016 09:48AM

Hi,

> This would not be a massive change to the code

You laugh ! With only switchWampPort.php, you see only the tip of the iceberg.
You do not represent all the changes and developments implied to manage multiple ports listening.

There are not that switchWampPort.php script, there also refresh.php, wampserver.lib.php, index.php, add_vhost.php, etc.
And refresh.php is the heart of Wampmanager; the script that creates wampmanager.ini, so the menus and submenus of Wampmanager icon.

In order to have a good separation of the "basic and standard" portion from customizable parts, ports "personal" will necessarily be variables Define from Apache.

Support for multiple Apache listening ports will be effective with Wampserver 3.0.7.
I can not give a release date.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Virtual Hosts with Different Ports - WAMP 3 Menu Bug
Posted by: chillax86 (---.wessexcomputers.com)
Date: November 01, 2016 04:02PM

Will reply later



Edited 1 time(s). Last edit at 11/01/2016 04:06PM by chillax86.

Options: ReplyQuote


Sorry, only registered users may post in this forum.