Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just recently encountered the same problem because some code I had that was masking the same problem had gotten in the way.</p> <p>My diagnosis of the problem is as follows: This is a quirk of a change made in Apache 2.0. The Port directive is no longer part of the httpd.conf directives, essentially split up between the ServerName and Listen directives.</p> <p>So my apache httpd.conf (Apache 2.2.23) had these entries</p> <pre><code>ServerName myservername.com Listen: 5150 </code></pre> <p>Yet PHP $_SERVER['SERVER_PORT'] was returning 80 to all requests being made on port 5150.</p> <p>So poring over the Apache docs, I found a tidbit about Port being a deprecated directive and ServerName subsuming it.</p> <p>I set my servername directive as follows</p> <pre><code>ServerName myservername.com:5150 UseCanonicalName On Listen 5150 </code></pre> <p>and suddenly the php script was doing the right thing, reporting _SERVER['SERVER_PORT'] as 5150.</p> <p>Alternatively your httpd.conf could read</p> <pre><code>ServerName myservername.com UseCanonicalName Off Listen 5150 </code></pre> <p>So then I dug into the php (5.3.20) source code and the apache source code until I found the source of the behavior.</p> <p>The behavior is rooted in (at least for apached 2.2.23 source code) in <code>dirOfApacheSource/server/core.c</code> Look at the function <code>AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r)</code></p> <p>Here you will see that if your httpd UseCanonicalName directive is set to "On" then port gets parsed out of the ServerName directive. When the ServerName directive is not of the form ServerName myserver.com:myport number, the case code will fetch an ap_default_port of the request object (which is kindly set to default to 80 by the apache folks).</p> <p>If it bothers you that you need to add the port explicitly to the ServerName directive in httpd.conf, your other choice is to set the UseCanonicalName to "Off", this forces the code in server/core.c to parse the URI request to extract the servername and port.</p> <p>Six of one, half a dozen of the other, tweak your apache httpd.conf file and you will soon see the expected results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload