We help IT Professionals succeed at work.

Internal Server Error 500 - PHP Production Server Only

I keep getting an Internal server error 500 when trying to run my PHP web app, it works fine on my dev server (Zend Server CE on Windows) but not on the production server (Apache on Ubuntu). Other projects run fine on the production server. I have a suspicion that it may be to do with the way I am including files. For example I have a small script below which handles a POST and is supposed to process accordingly but fails. I've checked the PHP error log, Apache error log with no results. I've tried to reduce the code to the point where I am just using the setters, and it still fails. I'm completey stumped! Please help!
## Includes
set_include_path($_SERVER['DOCUMENT_ROOT'] . "/onlinebookingv4/scripts/php");
include_once("/controllers/session.controller.php");

## POST/GET
if ($_SERVER['REQUEST_METHOD'] == "POST") {
	
	SessionController::set_username($_REQUEST['txt-username']);  
	SessionController::set_password($_REQUEST['txt-password']);  
		
	SessionController::validate_user();
	
}

Open in new window

Comment
Watch Question

Commented:
include_once("/controllers/session.controller.php");
set_include_path($_SERVER['DOCUMENT_ROOT'] . "/onlinebookingv4/scripts/php");


These path is looking at the root of the drive. Linux paths start at / where as windows is C:/


you need to use a relative path unless you are actually using a folder /onlinebookingv4 in the root of the drive

Author

Commented:
Relative to the current document?

e.g.

include_once("/scripts/php/controllers/session.controller.php");
Commented:
it doesnt work that way in linux. if you use a relative path put

folder/folder/file as relative.

../folder/folder/file to go up directories


in linux putting /folder/folder/file

is the same as putting C:/folder/folder/file as / = C:

so to do a relative path from the current directories put both your paths without the leading /

Commented:
include_once("controllers/session.controller.php");
set_include_path($_SERVER['DOCUMENT_ROOT'] . "onlinebookingv4/scripts/php");

This would be the correct settings on the basis that the controllers and onlinebookingv4 folders are both in the same directory as the file.php that this code is being ran from
It's not necessary a root of the drive.
DOCUMENT_ROOT is a variable defined in server configuration and in many live systems will return nothing at all.

Depends on your system you may want to get your location from:

$_SERVER['SCRIPT_NAME'] or $_SERVER['SCRIPT_FILENAME']

Author

Commented:
Ok,

attached is a pic of project structure, Aeqil I need to set the include path before incuding the file dont i? niepodoba, its a dedicated server, so I have complete control over it, so $_SERVER['DOCUMENT_ROOT']  is all good :) Project Structure

Author

Commented:
So the intial request come from login.php which has

set_include_path($_SERVER['DOCUMENT_ROOT'] . "onlinebookingv4/scripts/php");
include_once("/bootstrp/all.inc.php");

Open in new window


all.inc.php has

## Includes
set_include_path($_SERVER['DOCUMENT_ROOT'] . "onlinebookingv4/scripts/php");
include_once('/models/server.php');
include_once('/controllers/company.controller.php');
include_once('/controllers/session.controller.php');

## Function Calls

// Set server defaults
Server::set_server("Europe/London");

// Get company details
CompanyController::getCompanyInfo();

// Get account details
SessionController::set_useraccount();

Open in new window


login.php then posts to login.inc.php which has

## Includes
set_include_path($_SERVER['DOCUMENT_ROOT'] . "/onlinebookingv4/scripts/php");
include_once("/controllers/session.controller.php");

## POST/GET
if ($_SERVER['REQUEST_METHOD'] == "POST") {
	
	SessionController::set_username($_REQUEST['txt-username']);  
	SessionController::set_password($_REQUEST['txt-password']);  
		
	SessionController::validate_user();
	
}

Open in new window

Author

Commented:
Sorted it,

instead of

set_include_path($_SERVER['DOCUMENT_ROOT'] . "/onlinebookingv4/scripts/php");
include_once('/bootstrp/all.inc.php');

Open in new window


it needed to be;-

set_include_path($_SERVER['DOCUMENT_ROOT'] . "/onlinebookingv4/scripts/php/");
include_once('bootstrp/all.inc.php');

Open in new window

Commented:
Hey,
sorry I didnt get back to you, glad you got it sorted. Usually a good place to look is /var/log/apache2 or /var/log/httpd which can give some help in trouble shooting.

Glad you got it sorted though :)