XHanch Studio Log in | Register | Cart

Forum

[Troubleshoot] Gett...
 
Notifications
Clear all

[Troubleshoot] Getting a "500 Internal Server Error" when viewing PHP file/page

1 Posts
1 Users
0 Likes
1,646 Views
XHanch
(@xhanch-alt)
Posts: 2105
Member Admin
Topic starter
 

If you try to open/view/visit/access PHP files/pages and get a 500 Internal server error page through a URL (ex: http://example.com/index.php ) but you can view other file types (html, javascript, css, image, or others) without any problem, you can find some of these solutions.

Actually, there are some problems that may cause this issue.

SuPHP - the files and/or folders are not owned by you

First, check your apache error log and see if you can find this error.

[Sun Mar 07 16:19:33 2010] [error] [client xx.xx.xxx.xxx] SoftException in Application.cpp:422: Mismatch between target UID (506) and UID (500) of file "/home/myAccount/public_html/index.php"

If you found an error like that, it is certainly a SuPHP issue which is ownership of the PHP files does not match the domain owner. What you need to do is to change the PHP files owners.

Use this command to change your PHP files ownership

chown -R siteuser:siteuser /home/siteuser/public_html

See who users 500 and 506 are if you don't know. Check the /etc/passwd

cat /etc/passwd |grep 500

Error in .htAccess

False codes in .htaccess file can result in "500 Internal Server Error" page.
In this case, try to remove/rename the .htaccess file and try to open/view/access your PHP file/page.
If you managed to open your PHP file/page correctly, you can be certained that something wrong in your .htaccess file.
Then, try fix your .htaccess codes.

Your .htaccess file may have php_values or php_flags in it. This can cause a 500 Internal server error when attempting to execute the script. The php_values and php_flags will need to be removed from your .htaccess file (please make a backup of the .htaccess by copying its contents and saving it on your desktop as htaccess.txt). Take the contents removed from .htaccess and place it into a file you create called php.ini. Remember to remove the php_flag and php_value part before the directives as php.ini files do not require those in front of the values. You can always make the changes and ask us if the changed files are correct.

SuPHP - improper/wrong file or folder permissions

The permissions on some of the folders or files are 777 or 666. If this is the case, change them to either 755 or 644 in Cpanel's File Manager (or using your local FTP client).

To explain in depth why suPHP requires these changes to the file permissions, please note that suPHP runs scripts with the permissions of their owners. Regular PHP executes scripts under the permissions of the system user running the web server, which means that your script runs with different permissions than your own user account and makes it very hard to use a PHP script to modify and create files without giving everyone on the server access to your files (this means that on regular PHP you provide write or execute access to group and world even for some files). Since SuPHP makes your PHP scripts run with the same permissions as your regular user account, you do not need group or world write access or execute access for files and suPHP will even prevent files from running that are group or world writable or executable as a security precaution.

666 equals the following:

Mode User Group World
Read 4 4 4 (all checked)
Write 2 2 2 (all checked)
Execute(none checked)

This makes group and world able to write to the file, a security risk

777 equals the following:

Mode User Group World
Read 4 4 4 (all checked)
Write 2 2 2 (all checked)
Execute 1 1 1 (all checked)

This makes group and world able to write and execute the file, a very large security risk.

Basically, suPHP is more secure, and preventing scripts from running as 666 or 777 prevents group or world from maliciously writing to the files and hacking your scripts.

Missing or cannot read php.ini

Try to find your php.ini. You may have deleted it unintentionally.

It also can happen because of php.ini values are not shared across directories, you would need a separate php.ini file in each folder that has .htaccess or that requires the php_values or php_flags. In order to avoid doing this, you can place a line in the .htaccess file in your public_html folder to have all values in your public_html php.ini to be shared across all folder. This line would be the following:

suPHP_ConfigPath /home/username/public_html
 
Posted : 07/05/2011 1:15 pm
Share:

× Close Menu