The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ForceType producing 500 Error on Apache 1.3

Discussion in 'EasyApache' started by awells, Sep 11, 2006.

  1. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I am trying to setup a clean URL navigation, but I am having some trouble with internal server errors. I am basically trying to force the php type on a file called 'content', so I can have files such as www.mysite.com/content/blah/344. Anyways, this is what I was told to add to the .htaccess file:

    Code:
    <FilesMatch "^content$">
        ForceType application/x-httpd-php
    </FilesMatch>
    and this is the content file in the same directory:

    Code:
    <?php
    	header('Content-type: text/html');
    	echo 'It works!!';
    ?>
    I want it to work on my main server, but it doesn't. My main server is running cPanel with php4 and Apache 1.3. This technique does work on my home webserver running php5 and Apache2, and it does work on my shared hosting account running php4 and Apache 1.3. When I get the internal server error, I look in the error log and see that the error says "Premature end of script headers." If I look at my suExec log, it says the script doesn't have executable permissions.

    Any ideas? Thanks.
     
  2. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    I think you just not enable all options in AllowOverride apache directives. (httpd.conf)
     
  3. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Ok, I just tried that. I changed 'AllowOverride All' in the <Directory /> directive, but still have the same error.
     
  4. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    Possible mistakes
    1) May be you enable AllowOverride in incorrect place
    2) Your php run as cgi

    You may check your /usr/local/apache/logs/error_log

    you should find here more detailed information about problem.
     
  5. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Basically what I did was find every occurrence of AllowOverride in the file and change the options to All.

    About the logs, the Apache error log says "Premature end of script headers", and the suExec log says "File has no execute permissions", but the file does have execute permissions. PHP files don't have to have executing permissions anyway - or so I thought.
     
  6. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    If i am not wrong ForceType do not work under php as cgi (i.e. phpsuexec enabled). But i am not sure, we have similar problem very long time ago. Also try may be not a application/x-httpd-php but just for example text/html. There is may be some problem exist with apache handlers.
     
  7. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Well that's interesting. It works when I change the ForceType to text/html. So does that mean that it will not be able to force the php type?

    Well, if I can't do it in the .htaccess file, I do have root access son this server, so could I just add the type in the conf file?
     
  8. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    no, most likely just your "application/x-httpd-php" is not correct. Usually that means php runned as module not as binary. for binary you should use something like

    AddType application/x-httpd-php .php .php3 .php4 .phtml
    AddHandler x-httpd-php .php .php3 .php4 .phtml
     
  9. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Well, here is what I found in my httpd.conf file:
    Code:
        #
        # AddHandler allows you to map certain file extensions to "handlers",
        # actions unrelated to filetype. These can be either built into the server
        # or added with the Action command (see below)
        #
        # If you want to use server side includes, or CGI outside
        # ScriptAliased directories, uncomment the following lines.
        #
        # To use CGI scripts:
        #
    AddHandler application/x-httpd-php .php .php4 .php3
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php4
    AddType application/x-httpd-php .php3
    AddType application/x-httpd-php-source .phps
    AddType application/x-httpd-php .phtml
    AddHandler cgi-script .cgi .pl
    AddType text/html .shtml
    AddType application/x-tar .tgz
    AddType text/vnd.wap.wml .wml
    AddType image/vnd.wap.wbmp .wbmp
    AddType text/vnd.wap.wmlscript .wmls
    AddType application/vnd.wap.wmlc .wmlc
    AddType application/vnd.wap.wmlscriptc .wmlsc
     
  10. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    Yes, it's definately reason why your ForceType construction do not work with php.

    May be something like:

    AddHandler php-cgi .php
    Action php-cgi /cgi-bin/php.cgi
    ForceType php-cgi

    in your .htaccess will help you... In aove example you use own apache handlers. Of course php patch should be corrected to your server files location

    may be this directives can help you instead:

    AddType application/x-httpd-php .php .phtml
     
  11. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    I just tried that real quick with no luck.

    I did recently learn something though. I rebuilt Apache w/o PHP suEXEC Support, and it does work, but I can't have that disabled because I can't have my mail scripts running as nobody. At least I know the culprit though.
     
  12. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    If that's the case, then could I just add the type to the httpd.conf file?
     
  13. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    i am not sure, but may be under suphp ForceType will work.
     
  14. rustelekom

    rustelekom Well-Known Member
    PartnerNOC

    Joined:
    Nov 13, 2003
    Messages:
    290
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    moscow
    I think no. It shouldn't help.
     
  15. awells

    awells Member

    Joined:
    Mar 18, 2006
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    1
    Hello, I know it's been over a month since this thread was posted to, but I did find a solution to the problem. I found a quick any easy way to use Apache's mod_rewrite method and it works great. It's probably the more proper way to form clean URLs than the ForceType method I was talking about anyway.

    Thanks for all your tips and advise!
     
  16. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    Care to share?

    I am having the exact same issue, using php5 so far with no luck.

    Whats your mod_rewrite method? How exactly do you implement it? In an .htaccess file?

    Thanks very much.
     
  17. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Has nothing to do with being PHP5 ....

    The issue at hand really is whether PHP is being run as a module or CGI.

    When PHP is run as a CGI as is the case with phpSuExec or SuPHP then trying
    to parse additional extensions as PHP by a simple "AddType" or similiar is
    not going to be sufficient because PHP is not being handled by Apache.

    In a similiar fashion, php_flag and php_admin commands won't work either
    when PHP is setup as a CGI vs a loadable Apache module.

    When PHP is run as a module then you do have the ability to use standard
    "AddType" commands to add extensions, HTACCESS overrides, etc but at
    a tremendous cost to security that comes with it.

    There are ways to accomplish the same goel with PHP running as a CGI but
    the configuration is going to be quite different and you need to learn the
    differences between configuring CGI and module based PHP.
     
  18. pr0gr4mm3r

    pr0gr4mm3r Member

    Joined:
    Aug 25, 2006
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
  19. lijeeshsd

    lijeeshsd Active Member

    Joined:
    Apr 22, 2005
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    6
    ForceType will not work with phpsuexec. So use SetHandler, it will work for sure.

    SetHandler application/x-httpd-php
     

Share This Page