May
17
2010

PHP 500 Internal Server Errors

500 Internal Server Errors are one of the most common PHP issues that I see customer experience, and it will occur mostly on servers with suPHP or PHP running as CGI.  These errors can be caused by something on the server, or an issue on the user’s site. Here ‘s what you should do if you see errors:

Check the logs

You can solve most problems quickly just by looking at the logs:

/usr/local/apache/logs/error_log

/usr/local/apache/logs/suphp.log

Here are some common errors:

SoftException in Application.cpp:357: UID of script "/home/user/public_html/test.php" is smaller than min_uid

SoftException in Application.cpp:422: Mismatch between target UID (511) and UID (510) of file "/home/user/public_html/test.php"

SoftException in Application.cpp:264: File "/home/user/public_html/test.php" is writeable by others

These are all permission/ownership issues, indicating that the owner of the PHP file being called in incorrect, or the permissions are higher than what is allowed in suphp.conf.

Invalid directions in .htaccess

If you’re running PHP in CGI or suPHP mode, you can’t use php_flag or php_value directives in .htaccess – you either need to use htscanner to allow Apache to parse those commands, or make php-related changes in php.ini within the user’s account. You can check the Apache error log in /usr/local/apache/logs/error_log to see if you get something like this:

/home/user/public_html/.htaccess: Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration

If the error log indicates a problem with .htaccess, you need to remove the directives indicated and make sure your ssyntax is correct, and that they are in the correct places.

Incorrect ownership or permissions

PHP scripts and their immediate parent folder will usually have permissions limits when PHP runs in CGI/suPHP mode. By default, PHP files and their parent folders can not have group or ‘other’ writable permissions, and cannot be owned by a user on the system other than than the user that owns the home folder it is located in. Additionally, cPanel’s implementation of suPHP does not allow PHP to execute via browser from locations that are not inside a user’s home folder. The first thing you should check is that the PHP script and its parent folder(s) are not writable by ‘group’ or ‘other’, or owned by a different system user. You can usually see if this is an issue by tailing the suphp log in /usr/local/apache/logs/suphp.log, or whatever the suphp.conf has set as the log location.

You can adjust suPHP’s permissions allowances in /opt/suphp/etc/suphp.conf to allow ‘group’ and ‘other’ writable permissions if it’s necessary by modifying these values:

allow_file_group_writeable=false
allow_file_others_writeable=false
allow_directory_group_writeable=false
allow_directory_others_writeable=false

If the problem is with the min_uid value being too low (such as if you’re running a PHP script as root), you can also modify the “min_uid” and “min_gid” values to be more permissive. Changing anything in the suphp.conf requires a restart of Apache.

SuPHP binary missing its “sticky” permissions

Take a look at the suphp binary. It should look a bit like this, and in most shells, will be highlighted in red:

-rwsr-xr-x 1 root root 341K Mar 30 12:25 /opt/suphp/sbin/suphp*

If it’s missing the ‘s’ in the permissions column, you need to re-add the sticky bit to allow users on the system to execute it properly:

chmod +s /opt/suphp/sbin/suphp

Last resort

If all else fails, you could be running a bum Apache build.  Try running EasyApache to reinstall to see if that fixes the problem.  You can also submit a support request to us and we may be able to fix this for you:

About the Author: Vanessa Vasile

I'm too lazy to write anything interesting here because I was too busy writing this awesome post.

14 Comments+ Add Comment

  • [...] here at work was giving a 500 Internal Server error whenever a PHP page was loaded. Among the various things that can cause this error when you’re running PHP in CGI mode (suPHP), this error showing up [...]

  • [...] here at work was giving a 500 Internal Server error whenever a PHP page was loaded. Among the various things that can cause this error when you’re running PHP in CGI mode (suPHP), this error showing up in [...]

  • Hi here i’m working on a page inbox.If i’m trying to do any function it is updating but the page goes to internal error 500. Can any one help me

    Module FastCgiModule
    Notification ExecuteRequestHandler
    Handler PHP via FastCGI (*.php)
    Error Code 0×80070102
    Requested URL http://www.hitbullseye.com:80/index.php?action=inbox
    Physical Path C:\HostingSpaces\hitbulls\hitbullseye.com\wwwroot\index.php
    Logon Method Anonymous
    Logon User Anonymous

    this is the detailed error

  • Of course, this site helps again.

    Just had a client with ZenCart malfunctioning.

    Turned out the root user owned his files, since I had untarre’d the ZenCart installation file on his server.

    Search in Google revealed this page.

    Thanks again Vanessa!

  • Hi Vanessa, I’m trying to do a secure installation of WordPress and having trouble with this very thing. What I want is to redirect all traffic to https://www.wineoceroswineclub.com. My htaccess redirect is as follows:
    RewriteCond %{HTTP_HOST} ^wineoceroswineclub\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.wineoceroswineclub\.com$
    RewriteRule ^/?$ “https\:\/\/www\.wineoceroswineclub\.com\/” [R=301,L]

    and wp-config site settings are:
    define(‘WP_HOME’,'http://www.wineoceroswineclub.com’);
    define(‘WP_SITEURL’,'https://www.wineoceroswineclub.com’);

    yet I can only access the site here: http://www.wineoceroswineclub.com/wp-admin/login.php/

    and clicking the login link, the redirect works properly, taking me to https://www.wineoceroswineclub.com/wp-login.php, yet I get an internal server error, with a 500 internal server error encountered when trying to use an ErrorDocument to handle the request.

    Checking my error log gives me this: mismatch between target UID and UID of file “/home/wineocer/public_html/index.php”, referer: http://www.wineoceroswineclub.com/wp-admin/login.php/

    I have tried every possible combination of http://, https://, www. and non-www. settings for the site url and this is as good as it gets so far. Can you clue me in to what I’ve done incorrectly?

    Thanks so much, Hannah

  • I should add that previous redirect configurations have pulled up the temp page @ https://www.wineoceroswineclub.com/index.html I have hiding the WordPress installation while I work on it, but now I get the “redirecting in a way that will never complete” error. I’m so confused!

  • Sorry, more info. This installation is on a VPS with SSL cert assigned to http://www.wineoceroswineclub.com. the complete error message in the error log is:
    SoftException in Application.cpp:422: Mismatch between target UID (99) and UID (510) of file “/home/wineocer/public_html/index.php”, referer: http://www.wineoceroswineclub.com/wp-admin/login.php/

  • I searched on your website to find out the problems associated with error log 500.shtml (internal server error), you seem quite experienced in this regard. The following are the detected errors in the Error Log CPanel:
    [Wed April 04 10:12:59 2012] [error] [client 180.76.xxx.xx] File does not exist: / home/MySite/public_html/500.shtml
    [Wed April 04 09:53:25 2012] [error] [client 110.85.xxx.xxx] File does not exist: / home/MySite/public_html/500.shtml, referer: referer name
    There are several questions that I ask:
    Does this 500 error mostly occur on the website or the hosting site server. FYI, I use a shared hosting site.
    May the 500 errors occur in the .htaccess script of my website or the hosting site server?

  • [...] every solution listed from this cPanel Forums Be Sociable, Share! Tweet Posted in StackOverflow | Tagged email, php | Leave [...]

  • [...] here at work was giving a 500 Internal Server error whenever a PHP page was loaded. Among the various things that can cause this error when you’re running PHP in CGI mode (suPHP), this error showing up in [...]

  • Thanks For the information.
    I solved my problem of gk.hitbullseye.com with this.
    Really Thanks for the information

  • Gid mismatch error:

    In case, you had changed the permissions please restart apache and/or nginx for the permissions to take affect.

  • […] PHP 500 Internal Server Errors […]

Leave a comment