Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 4 of 4

This is a discussion on Tutorial: PHP5-CGI alongside PHP4-CGI on Interworx Servers in the VPS & Dedicated forum
I recently purchased a VPS with Interworx and began to migrate my sites from my trusty GigaDeal account. For the most part, I really like ...

  1. #1
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003

    Tutorial: PHP5-CGI alongside PHP4-CGI on Interworx Servers

    I recently purchased a VPS with Interworx and began to migrate my sites from my trusty GigaDeal account. For the most part, I really like Interworx, but one thing that frustrated me with it was that it doesn't support PHP4 alongside PHP5 out of the box. I've come to like that feature of my GigaDeal plan-I can develop new scripts using the latest PHP features while not having to worry about breaking my existing scripts before I have time to migrate them.

    I found a couple of posts on the Interworx forums about setting up such an environment using RPMs, but unfortunately the RPMs were user contributed and the links on the site no longer worked. So I decided to bite the bullet and figure out how to do it myself.

    Background: My VPS came set up with PHP 4.3.11 and Apache 2. For the record, I'm running CentOS 4, but that shouldn't matter too much for the tutorial. Even though it isn't the most current version, I decided to leave PHP 4 alone (for now). That binary is powering the Interworx CP and I don't want to break it by introducing any unsupported changes.

    1. Download and compile PHP 5. I opted to go with the most recent version, 5.2.4. For the sake of brevity, I'll leave it up to you to decide what options to pass to configure, but the ones listed are essential:
    Code:
    wget http://www.php.net/get/php-5.2.4.tar.gz/from/this/mirror
    tar xvfz php-5.2.4.tar.gz
    cd php-5.2.4
    ./configure --program-suffix=5 --prefix=/usr/local --enable-force-cgi-redirect
    program-suffix tells the compiler to stick a "5" on the end of all of the PHP 5 binaries so that they won't overwrite the existing PHP 4 binaries. (I'm also installing to a different path --/usr/local instead of /usr--so this won't be an issue, but it still makes it easier to keep track of what's what.)

    Once the configure script runs successfully you are ready to make PHP 5:
    Code:
    make
    make test
    make install
    If all goes well you should now have several php*5 binaries in /usr/local/bin.



    2. Now, in order to run PHP scripts under their owner's UID, we need to have suPHP. Again, I'm using the most recent release(0.6.2).
    Code:
    wget http://www.suphp.org/download/suphp-0.6.2.tar.gz
    tar xvfz suphp-0.6.2.tar.gz
    cd suphp-0.6.2.tar.gz
    Before you configure you'll need to edit the mod_suphp.c file in the src/apache2 directory of your unpacked suphp directory. Search for any occurrences of the string "ACCESS_CONF" (without quotes) and replace with "RSRC_CONF | ACCESS_CONF" (again, without quotes). If you do not do this you will get errors when you try to use suPHP_AddHandler in the server configuration process.

    suPHP's configure script will work fine without any arguments, but I've opted to use paranoid mode which runs scripts as the user I designate (more on that later), but only if the file is owned by that user.
    Code:
    ./configure --prefix=/usr --with-setid-mode=paranoid
    make
    make install
    When done compiling, suPHP should add a file in /etc/httpd/conf.d called mod_suphp.conf. When Apache is restarted, it will parse this file and load the suPHP module.



    3. Now open /etc/suphp.conf and set the following:
    Code:
    allow_file_others_writable = false
    allow_directory_others_writable = false
    Then find the [handlers] section make sure it contains the following (you'll need to add the second line):
    Code:
    x-httpd-php=php:/usr/bin/php
    x-httpd-php5=php:/usr/local/bin/php-cgi5


    4. Now it is time to configure Apache to use suPHP. Open /etc/httpd/conf.d/mod_suphp.conf and replace the existing <IfModule mod_suphp.c>…</IfModule> block with the following:
    Code:
      <IfModule mod_suphp.c>
      suPHP_Engine on
      suPHP_ConfigPath /etc
      suPHP_AddHandler x-httpd-php
      AddHandler application/x-httpd-php .php .php4 .php
      suPHP_AddHandler x-httpd-php5
      AddHandler application/x-httpd-php5 .php5
    </IfModule>
    DirectoryIndex index.php index.php5
    You should also remove the /etc/httpd/conf.d/php.conf file (I renamed mine to php.conf.disabled so that I'll still have it if I need it later).



    5. /etc/httpd/conf.d also contains a file for each virtual host on the server. You will need to make two edits to each of these files:
    a. Add the following line anywhere inside the <VirtualHost>…</VirtualHost> block:
    Code:
    suPHP_UserGroup username groupname
    Replace "username" and "groupname" with the appropriate values for the site's owner. Both should actually be the same value unless you've manually changed it. This tells suPHP which user should be used to run PHP scripts on this virtual host.
    b. Comment out (or remove) the line that starts "php_admin_flag." Since we've removed support for mod_php keeping this around will cause sites to fail with "500" errors.



    6. Interworx uses a template when it creates new virtual host conf files that can be found at /home/interworx/etc/vhost-base.conf. You should edit this file as in step 5 so that future sites you add will automatically configured to use suPHP. Instead of providing actual user and group names in the suPHP_UserGroup directive, use the following, which Interworx will substitute with the names it assigns to new accounts:
    Code:
    suPHP_UserGroup <<UNIQNAME>> <<UNIQNAME>>


    7. Restart Apache to make all of your changes take place.
    Code:
    service httpd restart

    User configuration

    Since mod_php has been disabled users will no longer be able to set php_value and php_flag directives in .htaccess. In fact, if they have any of these directives defined their sites will break after this change is made.

    Unlike cPanel's implementation, users cannot simply drop a php.ini file into the current directory to override default settings. The can, however, redefine suPHP_ConfigPath to point to any directory containing a php.ini file in .htaccess:
    Code:
    suPHP_ConfigPath /home/myaccount
    Note that the path should be to a directory containing a php.ini file, not to the php.ini file itself.

    Users who want to make their .php scripts run under PHP5 can do so by adding the following to .htaccess:
    Code:
    AddHandler application/x-httpd-php5 .php
    I hope you find this helpful.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  2. #2
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    I should note that this is something I discovered by my own trial and error and it has been tested on exactly one VPS. It is NOT supported by JPC or Interworx. You're on your own if you choose to implement it--don't blame me if it happens to hose your machine.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  3. #3
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Sweet!

    Thanks, jason!
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Quote Originally Posted by Vin DSL View Post
    Sweet!

    Thanks, jason!
    Are you using a VPS now, Vin? I though you were anti-PHP-CGI and anti-PHP5.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •