Custom PHP Script Handler

Discussion in 'PHP' started by J.T., May 19, 2010.

  1. J.T.

    J.T. New Member

    Hi,

    Following this thread: http://www.litespeedtech.com/support/forum/showthread.php?t=3995

    I've now compiled:

    1 x PHP 5.3.2 called "lsphpcerb"
    1 x PHP 5.2.13 called "lsphpmage"

    In /opt/lsws/ I can see those two folders, lsphpcerb and lsphpmage

    In fcgi-bin I have this:

    Now I set up a new VH. It is my intention to use the PHP 5.3.2 compilation called lsphpcerb for this.

    Following the thread mentioned above, I was hoping this was a matter of setting the External App or Script Handler in the Virtual Host. But my custom named PHP compilations aren't showing.

    When I click View/Edit on the VH and then External App I thought maybe I can edit the LSAPI App from something lsphp to lsphpcerb. Or under Script Handler edit php. Handler Type is LiteSpeed API and I had hoped and expected that now under Handler Name I would find my lsphpcerb. But I only get three options:

    [Server Level]: lsphp5
    [Server Level]: lsphp4
    [VHost Level]: $VH_NAME_lsphp

    So, what do I need to do to say "This VH needs its php files handled by lsphpcerb instead of lsphp5."

    Any directions you can offer?
  2. mistwang

    mistwang LiteSpeed Staff

    create a external app called lsphpcerb, using lsphp-5.3.2 binary,
    at vhost level add or change script handler for ".php" using the lsphpcerb application.
  3. J.T.

    J.T. New Member

    Thanks mistwang, appreciate your prompt responses.

    Under Server > External App or
    Virtual Hosts > Xyz VH > External App?

    I guess the latter as this is the only VH which will use this specific PHP setup.

    How exactly do I accomplish that? In Command? Or the socket Address?

    That, I follow! Thanks.

    I'd be ever so grateful if you could please elaborate on the above two points.
  4. mistwang

    mistwang LiteSpeed Staff

    If only used for that VHOST, just add it at vhost level.

    In command, use path to lsphp-5.3.2 binary. Socket address should be unique, could be anything you want.
  5. J.T.

    J.T. New Member

    OK thanks.

    Think I finally get it now. Please correct me if I'm wrong on the following findings.

    Key fact: You can compile PHP only once per version.

    Example, possible:

    - PHP 5.2.13 with Mailparse, plus;
    - PHP 5.3.2 with Curl, plus;
    - PHP 5.3.1 with SOAP

    Example, not possible:

    - PHP 5.3.2 with Curl and Mailparse, plus;
    - PHP 5.3.2 with SOAP and GD

    LSWS references each instance of a PHP compilation by its version number, not by an arbitrarily set name. (Would be nice if this changed...)

    Building on the example, possible, you can have one VH with external app pointing to $SERVER_ROOT/fcgi-bin/lsphp-5.3.2 and one to $SERVER_ROOT/fcgi-bin/lsphp-5.2.13 - simply edit the standard LSAPI App External App and update the Name, Socket Address and Command.

    My use case works now. Thanks for your help.

    If the above finding is correct, I'd make it a feature request to be able to "label" a certain PHP compile set with a unique arbitrarily chosen reference so withing fast-cgi folder, the PHP binary is referenced with this label. That way, we can have multiple binary compilations of the same PHP version with different PHP extensions. On a busy web server with many sites/scripts, this make environment isolation much easier and greatly helps with upgrade paths etc.
  6. NiteWave

    NiteWave Administrator

    it's possible, too.

    steps:
    1. assume you have defined external applications:
    lsphp532_1 --> PHP 5.3.2 with Curl and Mailparse
    lsphp532_2 --> PHP 5.3.2 with SOAP and GD

    2. under admin console --> server or vhost --> Script Handler -->Add,
    (for example,)
    php52 -->lsphp532_1
    php53 -->lsphp532_2
    php52,php53 are suffixes.

    thus, you've defined new php handlers:
    application/x-httpd-php52
    application/x-httpd-php53

    3.you can choose different php handler in different folders.
    in .htaccess,
    to select "PHP 5.3.2 with Curl and Mailparse" to run .php, using
    AddType application/x-httpd-php52 php
    to select "PHP 5.3.2 with SOAP and GD" to run .php, using
    AddType application/x-httpd-php53 php

    and so on. you can verify this by access phpinfo() in that folder.

Share This Page