HostMonster Web Hosting Help

PHP Script Throws Server 500 Error


Why am I getting Server 500 errors with php scripts?


Here are some possibilities as to why you are getting 500 errors with php scripts.

When a php script requires write access to a file or directory (like Nucleus does for the 'media'-directory if you want to be able to upload pictures etc), you have to chmod that directory (or file) to 777 (or 666 for files) on most servers. This gives world write access to this folder (file). This is because on most servers apache (and php) runs as user 'nobody'.
Although giving world write access will make it possible to use the script, it also means a security hole, which can be used by hackers and other riff-raff.

To avoid this security hole we run phpsuexec on our servers. Using phpsuexec, php runs under your own username on the server. This removes the necessity to make files and folders world writable. Instead you can just use 755 for folders (the default) and 644 for files (also the default).

Using phpsuexec may have some consequences. Specific statements in your .htaccess file may result in an error 500 (internal server error). So here are two possible problems, and how to solve them:


When you are using files with (or without) an extension different then the normal extension for that filetype you can use ForceType in your .htaccess file to make it clear to the server how to handle that file (or all the files in the folder) (this works on servers without phpsuexec).
An example: When you have a file called 'item' (like Nucleus uses for FancyURL's) and want it to be parsed by the server as php you use the following code in your .htaccess file:

However, because our servers use phpsuexec this will result in an internal server error. To solve this you can simply use SetHandler instead of ForceType, so your .htaccess-file becomes:

SetHandler application/x-httpd-php


On a server without phpsuexec it is possible to use the php_value statement in a .htaccess file to change the settings of php (actually overwrite the settings from php.ini). On a sever with phpsuexec this will also result in a server error. To solve this you can use a php.ini file which you put in the same folder as where you would have put your .htaccess file. In that php.ini file you can change all the php values. You only have to put the values you want to modify in that file. By example if you want to set the short_open_tag to Off you would have used short_open_tag? = off in your .htaccess file. Using a php.ini file this results in:
        short_open_tag = Off

Knowledgebase Article 95,934 views bookmark tags: directive forcetype phpsuexec tricks (updated 1044 days ago)

Was this resource helpful?

Did this resolve your issue?

Please add any other comments or suggestions about this content:

Recommended Help Content

500 Internal Server Error when installing via the MOJO Marketplace installer. (updated 627 days ago)
Knowledgebase Article 98,212 views tags: cpanel errors htaccess panel php script simpel

In the newer versions of PHP, they have included a new directive to control and handle remote includes. We disable this option, by default, which may affect some of your PHP scripts. (updated 1964 days ago)
Knowledgebase Article 57,803 views tags: php remote url

When performing an upgrade (in this case, Joomla) in Simple Scripts, it can throw the following error: "Host Server Unresponsive Unfortunately, the server you are attempting to install on appears to b (updated 1965 days ago)
Knowledgebase Article 63,675 views tags: htaccess scripts simple

Related Help Content

Website shows a server 500 error, what can I do to fix it? (updated 808 days ago)
Knowledgebase Article 267,523 views tags: error

How to customize your html or php error pages. (updated 874 days ago)
Knowledgebase Article 69,584 views tags: errors php

PHP vs PHP single php.ini vs PHP with FastCGI (updated 1045 days ago)
Knowledgebase Article 136,456 views tags: configuration php server

When creating a symlink to a php page, I get a 500 error. I am able to use symlinks to other files and folders fine. (updated 1755 days ago)
Knowledgebase Article 53,448 views tags: link php

After installing phpAuction and attempt to sign in as admin, you get php script errors. (updated 1995 days ago)
Knowledgebase Article 58,711 views tags: install php

How do I change the PHP environment for my site with php.ini? (updated 334 days ago)
Knowledgebase Article 354,888 views tags: configuration php server

I installed TikiWiki and I am getting the following error: Notice: Only variable references should be returned by reference in /home/~/lib/adodb/ on line 2741 Notice: Only variable refere (updated 2000 days ago)
Knowledgebase Article 56,863 views tags: fantastico php wiki

We need to execute a Perl script from inside a PHP page and display the results as part of the page. We tried the 'virtual' command but the server returns: blank. (updated 2000 days ago)
Knowledgebase Article 55,502 views tags: perl script