htaccess & php[45]-script

Discussion in 'PHP' started by priestjim, Mar 20, 2009.

  1. priestjim

    priestjim Well-Known Member


    I am trying to give my Plesk hosting clients a method of choosing between php4 and php5 without changing something in Plesk's configuration files. The quickest and most unobtrusive solution I've come so far is using .htaccess files inside the client's httpdocs directory with this line:

    AddHandler php5-script php php3 php4 php5
    to force PHP5 versioning and

    AddHandler php4-script php php3 php4 php5
    to force PHP4 versioning.

    Unfortunately, while changing from PHP4 to PHP5 works, the other way around does not (PHP5->PHP4). Am I doing something wrong? Is it a bug?

    Thanks in advance!
  2. mistwang

    mistwang LiteSpeed Staff

    use "AddType application/x-httpd-php[4|5] php php3 php4 php5" instead.
  3. priestjim

    priestjim Well-Known Member

    That did it. Thank you very much! :)
  4. kamran

    kamran New Member

    I want PHP to work in my HTML files with .htacess

    I added

    AddType application/x-httpd-php .html .htm

    I tested my html file with php code but it is showing blank page, what should I use, any idea would be great.

  5. mistwang

    mistwang LiteSpeed Staff

    that mean php code problem, so try a simple php command like <?php phpinfo(); ?>
  6. kamran

    kamran New Member

    I tried simple one. like phpinfo code but it is not working. My question am I using correct syntax in htaccess?

  7. mistwang

    mistwang LiteSpeed Staff

    It looks correct. how about .php file? works as expected?

    Check the server level script handler configuration from LSWS console. You should have a script handler for 'php', if not, only have script handler for 'php5', then you need to change the MIME type to "application/x-httpd-php5", it must match the script handler configuration.
  8. priestjim

    priestjim Well-Known Member

    A month after running correctly using the configuration described here, LS is giving me issues when selecting a PHP version on the fly. Let me explain:

    I added the following directive to an .htaccess file in httpdocs:
    AddType application/x-httpd-php4 php php3 php4 php5

    Then I tried to open a classic info.php (phpinfo()) page to verify that the mod worked but instead I got the default Redhat info page. The weird part is that info.php4 with the .htaccess removed displays the correct PHP4 info! The even weirder thing is that on another server I got with the EXACT same configuration and php versions/compiles everything is running correctly.

    Both PHP4 & PHP5 are recompiled with my options through LS's interface and everything else works correctly. The problem occurs with LS versions 4.0 through 4.0.3

    Error log gives me:
    2009-04-28 14:05:07.245 [ERROR] [] MIME type [application/x-httpd-php4] for suffix '.php' does not allow serving as static file, access denied!
    2009-04-28 14:05:07.245 [NOTICE] [] Content len: 29, Request line:

    Any suggestions?
  9. mistwang

    mistwang LiteSpeed Staff

    You have to have a "Script Handler" for "php4" defined at server level from LSWS web console.
  10. priestjim

    priestjim Well-Known Member

    I already have. .php4 scripts are working fine! In addition, converting to
    AddType application/x-httpd-php5 php php3 php4 php5
    AddType application/x-httpd-php4 php php3 php4 php5
    which makes no sense since php5 is the default handler for php files but just for the heck of it, gives me no error whatsoever.
  11. mistwang

    mistwang LiteSpeed Staff

    I am talking about the script handler configuration in LSWS console, not whether .php4 scripts are processed by PHP4 or PHP5. It is controlled by the "AddType" directives you mentioned.

    You have to have a script handler defined for "php4", so LSWS will know that MIME type "application/x-httpd-php4" will be handled by that handler. And later on, you can change the handler using those "AddType" directives.

    You should not remove the script handler configuration from the LSWS console.
  12. priestjim

    priestjim Well-Known Member

    I thought it was apparent that I already have a php4 script handler.

    Excerpt from httpd_config.xml:
    PHP4 settings:
  13. auser

    auser Super Moderator

    how about info.php4 with the .htaccess(not remove)? display correct or not?
  14. mistwang

    mistwang LiteSpeed Staff

    Make sure it does exist. You can try that command from command line.
  15. priestjim

    priestjim Well-Known Member

    With no apparent reason and no configuration change,no reboot, no other change, now the directive works...

Share This Page