Problem: Multiple S9Y installs virtual hosts WORKAROUND

Found a bug? Tell us!!
Post Reply
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Problem: Multiple S9Y installs virtual hosts WORKAROUND

Post by johncanary »

Observed with S9Y Version 1.2. on a shared Linux hosting account
using name based virtual hosting on Apache Web Server.

** Setup
** Symptom
** Workaround / Fix
** Additional potential problems


Physical Directory Structure in hosting account
-----------------------------------------------

Code: Select all

1st S9Y installation:

 /home/user2/hmtl                (root directory for domain1.com)
 /home/user2/hmtl/blog/          (S9Y 1.1.2 blog for domain1.com
                                 blog1)

2nd S9Y installation:

 /home/user2/html/domain2/       (directory for domain2.net)
 /home/user2/html/domain2/blog/  (S9Y 1.2 blog for domain2.net
                                 blog2)

Symptom after installing S9Y for www .domain2.net/blog/
------------------------------------------------------

URL: http://www .domain2.net/blog/

Output: "Serendipity has detected that your currently installed Serendipity version is 1.1.2. It seems you are attempting to upgrade to version 1.2, so you need to click here to continue the upgrade process."

The local config file of Blog1 is loaded. That's the problem.
/home/user2/hmtl/blog/serendipity_config_local.inc.php

Having either blogs on differently named path like /blog/ and /blog2/
or calling the blog with a subdomain (needs to be configured a bit differently
with the blog in the root of the subdomain instead of a path) solved the
problem. But hey, who want a blog at /blog2?
Nobody.


WORKAROUND / FIX
-----------------

File: serendipity_config.inc.php
Version: # $Id: serendipity_config.inc.php 1871 2007-08-25 12:07:56Z garvinhicking $

Line: 222 (or close, I already added comments into my personal version, sorry)

Code: Select all

if (file_exists($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/serendipity_config_local.inc.php')) {
    $local_config = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/serendipity_config_local.inc.php';
} elseif (defined('S9Y_DATA_PATH')) {
...
That's where the problem is.
$_SERVER['DOCUMENT_ROOT'] is the physical root of all hosts, and name based virtual hosts
at least in my hosting account. E.g. in my example.

$_SERVER['DOCUMENT_ROOT'] is "/home/user2/hmtl" for domain1.com and domain2.net, and any others

Every use of $_SERVER['DOCUMENT_ROOT'] in the whole S9Y Software could
be wrong in those kind of setups. I did not observe any other problems so far.

So I fixed it by commenting the first test out like this.

Code: Select all

if ( false ) { /*file_exists($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/serendipity_config_local.inc.php')) {
    $local_config = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . '/serendipity_config_local.inc.php'; */
} elseif (defined('S9Y_DATA_PATH')) {
...
Additional Potential Problems:
------------------------------

I did a grep in the 1.2 tree to see, where else 'DOCUMENT_ROOT' is used.

Code: Select all

  grep "_SERVER\['DOCUMENT_ROOT'\]" -Rc * | grep -v :0

    bundled-libs/Text/Wiki/Render/Xhtml/Image.php:1
    include/functions_installer.inc.php:3
    serendipity_config.inc.php:2
I hope this is helpful Garvin.
Maybe it's not too much of an effort to fix this
in the V1.3 Beta

Yours
John
Last edited by johncanary on Wed Feb 27, 2008 3:41 pm, edited 3 times in total.
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

That's a server misconfiguration.

DOCUMENT_ROOT should point to the root for the virtual host. Subdomains should be configured with a new virtual host pointing at their own subdirectory. Here's a quick reference: http://httpd.apache.org/docs/1.3/vhosts/examples.html

That's the way it works in all the shared environments I've been on. The nice thing is that the subdomain has no idea where the top-level domain is, so they can't contaminate each other (just like your case).
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Also check this thread:

http://board.s9y.org/viewtopic.php?p=69302

This only seems to happen if you use AliasDomain, which is not really supported by Serendipity; that DOCUMENT_ROOT check is definitely needed for shared installatiosn, we cannot remove it.

And I agree with Judebert; different domains having the same Documentroot is very evil.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
johncanary
Regular
Posts: 116
Joined: Mon Aug 20, 2007 4:00 am
Location: Spain
Contact:

Post by johncanary »

Hello guys,
I appreciate your feedback.

Yeah, kind of weird not setting the DOCUMENT_ROOT
properly in the VirtualHosts Section. What they (GoDaddy in this case) do instead
is they introduce a new environmental variable. That one is set correctly.

$_SERVER['SUBDOMAIN_DOCUMENT_ROOT']

With that said, I changed my workaround as follows:

Code: Select all

# $Id: serendipity_config.inc.php 1871 2007-08-25 12:07:56Z garvinhicking $
# Modification, Line 217ff
/*
 *   Load DB configuration information
 *   Load Functions
 *   Make sure that the file included is in the current directory and not any possible
 *   include path
 */
$Local_Document_Root = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'] || $_SERVER['DOCUMENT_ROOT'];
if (file_exists($Local_Document_Root . dirname($_SERVER['PHP_SELF']) . '/serendipity_config_local.inc.php')) {
    $local_config = $Local_Document_Root . dirname($_SERVER['PHP_SELF']) . '/serendipity_config_local.inc.php';
} elseif (defined('S9Y_DATA_PATH')) {
    // Shared installation! ...
I never got into shared installations, because it's not offered as one-click install. I
might check it out, though. It seems to make sense.
Yours John
: John's Google+ Profile
: John's E-Biz Booster Blog powered by Serendipity 1.7/PHP 5.3.14
Post Reply