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.

php5 and internal server error

Discussion in 'General Discussion' started by cyon, Jan 10, 2005.

  1. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    hi,

    I installed php4 & php5 parallel on my server.
    Php4 is built as an apache module and php5 as a cgi.
    My httpd.conf says:
    Code:
    ScriptAlias /php5/ "/usr/local/php5/bin/"
    Action application/x-httpd-php5 "/php5/php"
    AddType application/x-httpd-php5 .php5
    
    When I access test.php5 via serverx.hostname.tld/~username/test.php5 it works perfect, but when I access the same file via domain.tld/test.php5 I get an Internal Server Error.
    Does anybody have an idea, what the problem could be?
    Thank you in advance.
     
    #1 cyon, Jan 10, 2005
    Last edited: Jan 10, 2005
  2. fusioncroc

    fusioncroc Well-Known Member

    Joined:
    Sep 28, 2004
    Messages:
    261
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    U.K.
    cyon thats the same problem i have ( as you showed me how to do the php5 + php4 thing )
     
  3. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,381
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    What does the error log say when you get the 500 error?
     
  4. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    [Wed Jan 12 11:22:19 2005] [error] [client x.x.x.x] Premature end of script headers: /usr/local/php5/bin/php
     
    #4 cyon, Jan 12, 2005
    Last edited: Jan 15, 2005
  5. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    I got the problem.
    The error occurs when the user and the group aren't nobody.
    So when I edit the VirtualHost in the httpd.conf and set User and Group to nobody, .php5 works.

    Does anyone have an idea how to run php5 under different uid:guid's?
     
  6. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,381
    Likes Received:
    23
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Try changing the ownership of the file /usr/local/php5/bin/php to user root and group wheel:

    Code:
    chown root:wheel /usr/local/php5/bin/php
    
    I don't know if this will work or not, but you can try it.
     
  7. fusioncroc

    fusioncroc Well-Known Member

    Joined:
    Sep 28, 2004
    Messages:
    261
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    U.K.
    nope that does'nt work
    but the way be and cyon found out works ok is there any dis advantage of deleting the user + group from httpd.conf ? ( or putting nobody )
     
  8. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    my suexec_log says:

    Code:
    [2005-01-24 23:32:08]: info: (target/actual) uid: (username/username) gid: (username/username) cmd: php
    [2005-01-24 23:32:08]: error: target uid/gid (32005/32005) mismatch with directory (0/0) or program (32005/32005) or trusted user (0/10)
    
    any ideas?
     
  9. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    If php5 is the cgi installation - then I think you would need

    AddHandler

    rather than

    AddType
     
  10. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    thank you, but that didn't helped. I tried many variatons of the entries in the httpd.conf.

    it works, when I do one of the following:
    -Disable the User and Group entry in the virtualhost in the httpd.conf
    -Chown the php binary to the user who calls the script
    -Access it via hostname.tld/~username/phpinfo.php5 (which call it as nobody)

    So the problem seems to be a permission thing which is somehow linked with suexec stuff.. :confused:
     
  11. weaver

    weaver Active Member

    Joined:
    Jan 19, 2005
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    The problem is due to suexec, it basically does NOT work with php installed as a cgi!!

    You can do the following:


    1. 1.) Make a copy of the php-cgi binary for everyone who wants to use it (not recommended if you have lots of users).
    2. 2.) Disable suexec (not recommended if you hate spammers).
    3. 3.) Install suPHP from: http://suphp.org ;)
     
  12. fusioncroc

    fusioncroc Well-Known Member

    Joined:
    Sep 28, 2004
    Messages:
    261
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    U.K.
    thanks i'll probarly try that and see if it works for me or cyon
     
  13. WebOnce

    WebOnce Well-Known Member

    Joined:
    May 20, 2004
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Lansing, MI, USA
    Sure it does... you just have to put it in the right place with the right ownership ;)
     
  14. weaver

    weaver Active Member

    Joined:
    Jan 19, 2005
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    How does that help?

    When php is installed as a cgi it runs as nobody, how would moving it and changing ownership help when suexec requires the binary to run as the user? I suppose you could run it as root but then you would be giving everyone access to root privileges!!

    I would very much like for you to explain your setup rather than simply stating it will run under suexec "in the right place with the right ownership". I only know of a couple of ways it can be done as you suggest and each one compromises the security of your server :eek:
     
    #14 weaver, Jan 29, 2005
    Last edited: Jan 29, 2005
  15. cyon

    cyon Well-Known Member
    PartnerNOC

    Joined:
    Jan 15, 2003
    Messages:
    320
    Likes Received:
    0
    Trophy Points:
    16
    That's what I tried:
    I added
    Code:
     --suexec-safepath=/usr/local/bin:/usr/bin:/bin:/usr/local/php5"
    at the end of line 25 and line 32 in /home/cpapachebuild/buildapache/buildscript and ran ./buildscript, to recompile suexec with other safepathes, but the 500 internal server error persists.
    /usr/local/php5 is the path where I've installed php5.
     
  16. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    Not sure this is helpful for you but it may help - how about installing php5 as an apache module as well as php4?

    I have done this by installing 2 seperate apache installations (mod_php + mod_proxy enabled in the main apache install, the second apache install has the php5 module support.)
    Just install the second apache and make it listen on another port, allow connects only from localhost and forward the requests for php5 enabled domains using mod_proxy in the main apache httpd.conf.

    I found having them both running as apache modules was a more realistic environment to how we would have php5 installed .. in place of php4 .. sometime in the future, if it happens.
     
  17. weaver

    weaver Active Member

    Joined:
    Jan 19, 2005
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    Interesting setup which would definitely work :)

    Something people could consider?
     
  18. rgyure

    rgyure Member

    Joined:
    Jan 27, 2005
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Are there any docs on this?


    Ryan
     
  19. WebOnce

    WebOnce Well-Known Member

    Joined:
    May 20, 2004
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Lansing, MI, USA
    Yes, I know I'm somewhat cryptic, but I wanted to see if anyone could pick up on the trick of how to do it before I said more...

    How many of you have looked at the sys-cgi directory to get php5 running as a cgi? :)

    If that doesn't get you working, I promise I will tell you how I did it in my next response.
     
  20. hbouma

    hbouma Well-Known Member

    Joined:
    Jun 8, 2002
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    6
    How I got it to work

    I didn't want to get into doing a proxy/double apache install so I stuck with the cgi-bin route. After following the steps earlier for compiling PHP5 and adding it to Apache's httpd.conf, I did the following steps to add PHP5 support for a given site on the server:

    1) Copy the php bin into their cgi-bin directory as php5 and chowned it to the site's user. I also copied the php.ini file into the cgi-bin directory so that the userbasedir could be set correctly. I left it owned as root so that the site can't adjust it without our knowledge.

    2) Added the following lines to the site's Virtualhost settings in httpd.conf:

    AddHandler php-script .php5
    Action php-script /cgi-bin/php5

    This will tell Apache to run the php5 bin when a php5 file is requested.

    This solution works using both the preview URL (i.e. http://servername.com/~user/phpscript.php5) and the site itself (http://domain.com/phpscript.php5).

    Granted, its a little work as you have to do this for each site, but its nothing significant and if you need to upgrade php5, you have a list of sites that need to be updated in the httpd.conf (you can also use locate too).

    I hope this helps!

    Hal
     
Loading...

Share This Page