• Resolved WillemGrooters

    (@willemgrooters)


    I have one WP instance that I want to access using different webserver/virtual hosts, listening of different ports: one listens on port 80, second on 81, third on 82 and so on. So to access the blog, the URL would be http://host:port/blogname.
    Problem though is that WP stores WP- and blog URLs in the database (table <prefix>_options, and in order to have the instance work with one particular server, it needs to hold the port-number as well – as I found out.
    Can it be done?
    It would be nice it that could be retrieved by the WP code from the URL, but if I would need to set a variable per server, that would be a possibility as well, and add that in the URL when needed

Viewing 4 replies - 1 through 4 (of 4 total)
  • Seems like a strange configuration you’re going for…which begs the question: Is there a more orthodox way of achieving the desired effect?

    For example, would port forwarding or a multisite installation do the trick?

    Thread Starter WillemGrooters

    (@willemgrooters)

    I have reasons for this: this configuration is used to compare different server configurations, or even completely different web servers (a facility I have on my OS of choice), and therefore the only difference should be the server by which the application (in this case WordPress) is accessed. And each of these will access the application over it’s own port. B ecause that port is kept in the URL stored in the database, it is limiting access over that port only. I have observed that when port 81 is defined, access over port 82 will start the access, but the server on port 81 will take over at some point, and some functionality does not work…Different blogs (no problem for me – because the OS) using one database is no option either – for the same reason: the URL stored in the database will limit access over that single port….
    So port forwarding nor mutisite installtion will do the trick…

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Both the home and site url values are also definable via PHP constants. So if you have a means in PHP available to detect which server is being accessed, then you can change those values dynamically by setting varying constants for them. Setting constants will cause WordPress to ignore the database’s settings for those values.

    So something like this at the top of the wp-config.php file, for example:

    if ( $_SERVER['SERVER_PORT'] == 81 ) {
      define('WP_HOME','http://example.com:81/whatever');
      define('WP_SITEURL','http://example.com:81/whatever');
    }
    else if ( $_SERVER['SERVER_PORT'] == 82 ) {
      define('WP_HOME','http://example.com:82/whatever');
      define('WP_SITEURL','http://example.com:82/whatever');
    }

    … and so on.

    Thread Starter WillemGrooters

    (@willemgrooters)

    Thanks, that’s just what I was looking for 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘One blog, multiple (virtual) servers’ is closed to new replies.