Ticket #502 (new defect)

Opened 11 months ago

Last modified 11 months ago

SCRIPT_NAME with CGI script in subdirectory causes failed install

Reported by: alexbcoles Assigned to: somebody
Priority: normal Milestone: WPMU 1.0
Component: component1 Version:
Severity: normal Keywords:
Cc:

Description

Background: I have had some difficulty trying to install WordPress? MU for a client (a major university). In this case, PHP is available as CGI, rather than as an Apache Module. The _SERVER["SCRIPT_FILENAME"] variable is reported as /cgi-php5/php. I managed to resolve the issues through use of a workaround - which I detail below. In this case

Affected functions: Initial installation and usage.

Steps to replicate:

  • Install Apache.
  • Install PHP as CGI, within a subdirectory of the cgi-bin.
  • Attempt to install WordPress? MU.

Analysis:

The "regular" installation instructions will not install WordPress MU.

The problematic _SERVER scoped variables are: _SERVER["SCRIPT_FILENAME"] which is reported as /usr/local/opt/php/php-5.2.1/bin/php . _SERVER["SCRIPT_NAME"] which is reported as /cgi-php5/php .

The misconfiguration in the generated configuration files includes:

  • $base in generated wp-config.php incorrectly defined as 'cgi-php5'.
  • RewriteBase? in generated .htaccess incorrectly defined as 'cgi-php5'.
  • the following database values are set incorrectly:

tables for multi-user support:

table name column name column value
wp_blogs path /cgi-php5/
wp_site path /cgi-php5/

the default blog:

table name column name column value
wp_1_comments comment_author_url http://ucl.ac.uk/cgi-php5/
wp_1_options siteurl http://ucl.ac.uk/cgi-php5/
wp_1_options home http://ucl.ac.uk/cgi-php5/
wp_1_options fileupload_url http://ucl.ac.uk/cgi-php5/files

Workaround 1 : Possible Manual Workaround

The first attempt was to see if a manual workaround is possible, after an incorrect installation:

  1. go through database and fix table values listed above manually.
  2. fix generated wp-config.php:
    cp wp-config.php wp-config.php2
    pico wp-config.php2
    
    changing:
        $base = '/cgi-php5/';
    
    to:
        $base = '/site/blogs/';
    

rm wp-config.php

(select override YES, must be in BASH shell to do this)

mv wp-config.php2 wp-config.php
chmod 644 wp-config.php

  1. fix .htaccess' by removing it:
    rm .htaccess
    

and replacing with this new .htaccess:

    RewriteEngine On
    RewriteBase /site/blogs/


    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
  1. Fix ownership of .htaccess
    chown www-process
    chmod 600 .htaccess
    

Step-By-Step Workaround

Unsuccessful Installation Removal

WARNING: Before following these instructions, ensure any remnants of previous unsuccessful installations are removed:

  • remove all database tables.
  • either remove the whole blog directory: rm -Rf blogs/ or, at the very least, remove the following generated files:
    rm .htaccess
    rm wp-config.php
    

Basic Installation

The first part of the instructions closely mirror the official installation instructions, albeit in more detail:

  • create a blank database for WordPress MU through either the command line or phpMyAdmin.
  • login to your account through SSH.
  • switch to the bash shell and cd in to your webdocs directory:
    bash 
    cd www
    
  • download WordPress MU:
    wget http://mu.wordpress.org/latest.zip
    unzip latest.zip
    
  • rename the directory to whatever you want your URL to appear as.
    mv wordpress-mu-1.3 blogs
    
    (In this case if we want http://ucl.ac.uk/dutch/blogs/ for our blogs subsite, rename to blogs)
  • clean-up, by removing the zip file:
    rm latest.zip 
    

Patching the Install Files

  • At this point, if you follow the regular installation routine for WordPress MU, you would proceed to visit http://yoursite.com/subsite/blogs/, which generates all of the required configuration files through a web interface. VERY IMPORTANT : don't follow this part of the instructions just yet. Instead, its necessary to patch some of the installer files to make the site work with the ucl.ac.uk hosting environment.
  • cd into your blog directory, and open the wp-settings.php file in your favourite text editor (pico in this example, but vi or emacs do the job equally well, if not better)
    cd blogs
    pico wp-settings.php
    
  • at line 68, add the following:
    // Fix for hosting that sets SCRIPT_FILENAME to something ending in /bin/php for all requests
    if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'bin/php') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
        $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
    
    
  • and at line 76:
    if (strpos($_SERVER['SCRIPT_NAME'], 'cgi-php5') !== false)
        unset($_SERVER['PATH_INFO']);
    
    
  • close and save the files (CTRL/o, followed by CTRL/x in pico)
  • open index_install.php and replace three instances of
    $base = stripslashes( dirname( $_SERVER["SCRIPT_NAME"] ) );
    
    with
    $base = stripslashes( dirname( $_SERVER["PHP_SELF"] ) );
    
    (CTRL/W allows you to find in pico)
  • then proceed with installation as normal, first by fixing the permissions:
    chmod 777 /home/user/www/public/subsite/blogs /home/user/www/public/subsite/blogs/wp-content/ 
    
  • then visit: http://yoursite.com/subsite/blogs/
  • follow the on-screen instructions:
    • select sub-directories for Blog Addresses type.
  • add your database parameters, and site name, etc.
  • your WordPress MU site should set-up correctly. You can then proceed to login as WP admin and set up multiple user blogs.
  • as WordPress reminds you for security reasons, after the installation reset the following directory permissions:
    chmod 755 /home/user/www/public/subsite/blogs /home/user/www/public/subsite/blogs/wp-content/
    

Attachments

wp-settings.php.diff (424 bytes) - added by alexbcoles on 11/19/07 19:41:20.
index-install.php.diff (0.6 kB) - added by alexbcoles on 11/19/07 19:41:36.

Change History

11/19/07 19:41:20 changed by alexbcoles

  • attachment wp-settings.php.diff added.

11/19/07 19:41:36 changed by alexbcoles

  • attachment index-install.php.diff added.

11/19/07 19:47:32 changed by alexbcoles

  • my apologies for the length of the workaround text - this was taken from step-by-step instructions for non-developers - these simple changes can effectively be condensed into the two diffs above by those who know how to apply patches.
  • index_install.php should read index-install.php.
  • "three instances of" should read "four instances of"