PHP issue, not displaying but PHP is working

Hi,

i am having an issue with php, i installed and configured my web server with ispconfig as followed in this tutorial : http://www.howtoforge.com/perfect-server-opensuse-11.1-p2

Everything has gone fine, im able to go to my domain over the internet and its working just fine, however my php pages will not load, i have checked to see if there is any errors in my php by adding the phpinfo page as located hear : http://www.hbcomputers.eu/database/phpinfo.php

as you can see it is working but when i go to install my customer database php script i get this 500 error as you can see hear : http://www.hbcomputers.eu/database/

how can i fix this and what is wrong?

Thanks

Andy.

Look in /var/log/apache2/error_log for clues.

Hi,

Than you for your reply.

I checked the file and this is what i get :

[Fri Nov 20 09:40:11 2009] [error] [client 81.149.197.22] PHP Parse error: syntax error, unexpected $end in /srv/www/htdocs/database/setup.php on line 402
[Fri Nov 20 09:44:11 2009] [error] [client 81.149.197.22] Directory index forbidden by Options directive: /srv/www/htdocs/
[Fri Nov 20 10:08:50 2009] [error] [client 66.249.67.34] File does not exist: /srv/www/htdocs/robots.txt
[Fri Nov 20 10:08:51 2009] [error] [client 66.249.67.34] PHP Parse error: syntax error, unexpected $end in /srv/www/htdocs/database/setup.php on line 402
[Fri Nov 20 10:17:10 2009] [notice] caught SIGTERM, shutting down
[Fri Nov 20 10:19:38 2009] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Fri Nov 20 10:19:38 2009] [notice] mod_python: using mutex_directory /tmp
[Fri Nov 20 10:19:39 2009] [notice] Apache/2.2.10 (Linux/SUSE) mod_ssl/2.2.10 OpenSSL/0.9.8h PHP/5.2.11 with Suhosin-Patch mod_ruby/1.3.0 Ruby/1.8.7(2008-08-11) mod_python/3.3.$
[Fri Nov 20 10:29:57 2009] [error] [client 220.253.77.131] PHP Parse error: syntax error, unexpected $end in /srv/www/htdocs/database/setup.php on line 402, referer: http://fo$
[Fri Nov 20 10:30:53 2009] [error] [client 81.149.197.22] Directory index forbidden by Options directive: /srv/www/htdocs/
[Fri Nov 20 10:30:58 2009] [error] [client 81.149.197.22] PHP Parse error: syntax error, unexpected $end in /srv/www/htdocs/database/setup.php on line 402

It does mention an error in the setup.php code, i tried this script on another server (hbcomputers.com/database) and it works but.

the log also mentions index forbidden by options directrive. would this be the problem?

Check that setup.php is using full tags, i.e. <?php ?> and not <? ?>

Another reason is wrong kind of line endings, e.g. PHP files terminated with Mac CRs won’t work on Unix/Linux where the line ending is NL.

You can check the syntax from the command line PHP without having to use the webserver, e.g.:

php -l setup.php

in the directory containing it, of course or provide the full path.

The Index restriction only prevents you from listing the directory if an index.html or index.php cannot be found. The PHP syntax error is the one you have to fix.

I have checked the code in the setup.php, hear it is:

<?php

/**

  • Simple Admin System
  • Version 1.
    */

// some hosting accounts dont have default session settings that work :-/
// if you get session errors try setting the full path to a temp directory like this:
//ini_set(“error_reporting”,0);
//error_reporting(E_ALL);
//ini_set(“session.save_handler”, “files”);
//session_save_path (get_cwd() . “/tmp/”);

function stripslashes_deep(&$value){
$value = is_array($value) ? array_map(‘stripslashes_deep’, $value) : stripslashes($value);
return $value;
}
// oldschool setups:
if(get_magic_quotes_gpc()){
stripslashes_deep($_GET);
stripslashes_deep($_POST);
}

session_start();
ini_set(“display_errors”,false);

if(is_file(“includes/config.php”)){
echo “The file includes/config.php already exists, please remove this file first before running setup again.”;
exit;
}else{

require_once("includes/database.php");
require_once("includes/session.php");


// modules
require_once("includes/plugin.php");
$plugins = $plugins_unsorted = $plugin_positions = array();
foreach(glob("includes/plugin_*") as $plugin_dir){
	$plugin_name = str_replace("plugin_", "", basename($plugin_dir));
	if(is_dir($plugin_dir) && is_file($plugin_dir."/".$plugin_name.".php")){
		require_once($plugin_dir."/".$plugin_name.".php");
		eval('$plugins_unsorted$plugin_name] = new module_'.$plugin_name.'();');
		$plugins_unsorted$plugin_name]-&gt;init();
		$plugin_positions$plugins_unsorted$plugin_name]-&gt;module_position] = $plugin_name;
	}
}
// now we need to sort these plugins.
ksort($plugin_positions);
foreach($plugin_positions as $plugin_name){
	$plugins$plugin_name] =& $plugins_unsorted$plugin_name];
}
unset($plugins_unsorted);
// end modules.


require_once("design_header.php");
$errors = array();
$sqlerrors = array();

if($_REQUEST'build']){
	
	$install_sql = $_REQUEST'install_sql'];
	
	// check database connection.
	if($_REQUEST'db_host'] && $_REQUEST'db_user'] && $_REQUEST'db_pass'] && $_REQUEST'db_name']){
		
		$dbcnx = @mysql_connect($_REQUEST'db_host'],$_REQUEST'db_user'],$_REQUEST'db_pass']);
		if(!$dbcnx){
			$errors ] = "Unable to connect to database, please ensure your database connection information is correct";
		}else{
			$db = @mysql_select_db($_REQUEST'db_name']);
			if(!$db){
				$errors ] = "Connection successful, but unable to select your database. Is your database name correct?";
			}
		}
	}else{
		$errors ] = "Please enter all your database connection details";
	}
	
	if(!$errors){
	// build the config file.
	$config_file = '&lt;?php ' ."

";
ob_start();
?>

/* DATABASE CONFIGURATION VARIABLES */
define("_DB_SERVER","<?php echo $_REQUEST’db_host’]; ?>");
define("_DB_NAME","<?php echo $_REQUEST’db_name’]; ?>");
define("_DB_USER","<?php echo $_REQUEST’db_user’]; ?>");
define("_DB_PASS","<?php echo $_REQUEST’db_pass’]; ?>");
define("_DB_PREFIX","<?php echo $_REQUEST’db_prefix’]; ?>");

/* GENERAL CONFIG STUFF */
// this means 10% tax in the payment module.
define("_DEFAULT_TAX","<?php echo $_REQUEST’tax’]; ?>");
// date format for printing dates to the screen (uses php date syntax)
define("_DATE_FORMAT","<?php echo $_REQUEST’date_format’]; ?>");
// date format for inputting dates into the system
// 1 = DD/MM/YYYY
// 2 = YYYY/MM/DD
// 3 = MM/DD/YYYY
define("_DATE_INPUT",<?php echo (int)$_REQUEST’date_input’]; ?>);
switch(_DATE_INPUT){
case 1: define(’_DATE_INPUT_HELP’,‘DD/MM/YYYY’); break;
case 2: define(’_DATE_INPUT_HELP’,‘YYYY/MM/DD’); break;
case 3: define(’_DATE_INPUT_HELP’,‘MM/DD/YYYY’); break;
}
// used in outgoing emails for links, set this to something custom if you have problems.
define("_ADMIN_HOSTNAME",$_SERVER’HTTP_HOST’]);
// the folder (eg: internal/widget_admin) where the admin system is installed.
define("_ADMIN_DIRECTORY",dirname($_SERVER’REQUEST_URI’]));
// title that appears at the top of admin system and on home page.
define("_ADMIN_SYSTEM_NAME","<?php echo $_REQUEST’admin_system_name’]; ?>");
// subject of email that gets sent to customer on payment request.
define("_PAYMENT_EMAIL_SUBJECT","<?php echo $_REQUEST’paypal_subject’]; ?>");
// set this to your email, if there are errors (like with paypal) you will be notified here.
define("_ERROR_EMAIL","<?php echo $_REQUEST’admin_email’]; ?>");
// should generally always be 1, this is the id for “admin guy” who we use details for when emailing.
define("_ADMIN_USER_ID",1);
// show alerts 15 days in the future.
define("_ALERT_DAY_LIMIT",15);
// currency code
define("_CURRENCY_CODE",’<?php echo $_REQUEST’currency_code’]; ?>’);
define("_CURRENCY_NAME",’<?php echo $_REQUEST’currency_name’]; ?>’);
// currency location (before / after) the amount
define("_CURRENCY_LOCATION",’<?php echo $_REQUEST’currency_location’]; ?>’);
// default language code. the corresponding includes/lang/CODE.php file must exist
define("_DEFAULT_LANGUAGE",’<?php echo $_REQUEST’default_language’]; ?>’);
// default hourly rate
define("_DEFAULT_RATE",’<?php echo $_REQUEST’default_rate’]; ?>’);

/* PAYPAL SETTINGS */
define("_PAYPAL_BUSINESS_EMAIL","<?php echo $_REQUEST’paypal_email’]; ?>"); // email payment goes to.
define("_PAYPAL_SANDBOX_MODE",false); // only set to try if you know what ur doing…

/* ONLY REALLY USED FOR DEVELOPING */
define("_DEMO_MODE",false);

<?
$config_file .= ob_get_clean();
$config_file .= ‘?>’;

	}
	
	if(!$errors && $config_file){
		// insert the database
		
		define("_DB_PREFIX",$_REQUEST'db_prefix']);
		
		$mysql = '';
		//pull the sql in from the modules.
		foreach($plugins as $plugin_name =&gt; &$plugin){
			if($plugin-&gt;is_installed()){
				$sqlerrors ] ="It looks like the '$plugin_name' plugin is already installed. Please remove it to re-install from scratch.";
			}
			$mysql .= $plugin -&gt; get_install_sql();
		
		}
		
		// check if table already exists..
		/*$sql = "SELECT * FROM `".$_REQUEST'db_prefix'] . "users`";
		$res = @mysql_query($sql);
		if(!$res){
			// good! it threw an error that table doesnt' exist.
			
		}else{
			$errors] = "We detected the table `".$_REQUEST'db_prefix'] . "users` already exists in your database, please remove (DROP) the database tables if you wish to re-install. Note: You will loose any previous information if you drop your database tables";
		}*/
		
		if(!$sqlerrors && $install_sql){
			// run the mysql
			$sql_bits = explode(";",$mysql);
			foreach($sql_bits as $sql){
				$sql = trim($sql);
				if(!$sql)continue;
				$res = mysql_query($sql);
				if(!$res){
					$sqlerrors] = "Mysql Error: $sql - " . mysql_error();
				}
			}
			
		}
	} // if no errors
	
}


@include("includes/config.sample.php");

?&gt;

&lt;h2&gt;&lt;?php echo _ADMIN_SYSTEM_NAME; ?&gt; - Setup&lt;/h2&gt;

&lt;?php if($errors){
	?&gt;
	&lt;h4&gt;Errors:&lt;/h4&gt;
	&lt;?php foreach($errors as $error){
		?&gt;
		&lt;span style="color:#FF0000;"&gt;&lt;?php echo $error; ?&gt;&lt;/span&gt; &lt;br/&gt;
		&lt;?
	}
}

if(!isset($_REQUEST'build']) || $errors){
?&gt;

	&lt;form action="?build=true" method="post"&gt;
	
	&lt;h3&gt;Step 1: Setup a database&lt;/h3&gt;
	
	&lt;p&gt;
		First step is to create a MySQL database, and a database user. This process is explained in great detail on many websites. Once you have a database, please enter it's details below:
	&lt;/p&gt;
	
	&lt;table cellpadding="4"&gt;
		&lt;tr&gt;
			&lt;td&gt;Database Host:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="db_host" value="&lt;?php echo ($_REQUEST'db_host'])?$_REQUEST'db_host']:_DB_SERVER; ?&gt;"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Database Name:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="db_name" value="&lt;?php echo ($_REQUEST'db_name'])?$_REQUEST'db_name']:_DB_NAME; ?&gt;"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Database Username:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="db_user" value="&lt;?php echo ($_REQUEST'db_user'])?$_REQUEST'db_user']:_DB_USER; ?&gt;"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Database Password:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="db_pass" value="&lt;?php echo ($_REQUEST'db_pass'])?$_REQUEST'db_pass']:_DB_PASS; ?&gt;"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Table Prefix:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="db_prefix" value="&lt;?php echo ($_REQUEST'db_prefix'])?$_REQUEST'db_prefix']:_DB_PREFIX; ?&gt;" size="5"&gt; &lt;em&gt;Useful if you are re-using an existing database&lt;/em&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Install Database:&lt;/td&gt;
			&lt;td&gt;&lt;input type="checkbox" name="install_sql" value="yes" checked&gt; &lt;em&gt;Try to install database automatically, untick to get SQL code and do it manually.&lt;/em&gt;&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	
	&lt;h3&gt;Step 2: PayPal&lt;/h3&gt;
	
	&lt;p&gt;
		If you would like to use the PayPal features of this system, please enter your PayPal email address below. This is where payments will be made:
	&lt;/p&gt;
	&lt;table cellpadding="5"&gt;
		&lt;tr&gt;
			&lt;td&gt;PayPal Email Address:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="paypal_email" value="&lt;?php echo ($_REQUEST'paypal_email'])?$_REQUEST'paypal_email']:_PAYPAL_BUSINESS_EMAIL; ?&gt;"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;PayPal Email Subject:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="paypal_subject" value="&lt;?php echo ($_REQUEST'paypal_subject'])?$_REQUEST'paypal_subject']:_PAYMENT_EMAIL_SUBJECT; ?&gt;"&gt;
				&lt;em&gt;The email subject for 'payment requests' sent to your customers.&lt;/em&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	
	&lt;h3&gt;Step 3: General Config&lt;/h3&gt;
	
	&lt;p&gt;
		Please fill in the below information, the "Admin Email Address" is where payment notifications and error messages get sent.
	&lt;/p&gt;
	&lt;table cellpadding="5"&gt;
		&lt;tr&gt;
			&lt;td&gt;Admin Email Address:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="admin_email" value="&lt;?php echo ($_REQUEST'admin_email'])?$_REQUEST'admin_email']:_ERROR_EMAIL; ?&gt;"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Admin System Name:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="admin_system_name" value="&lt;?php echo ($_REQUEST'admin_system_name'])?$_REQUEST'admin_system_name']:_ADMIN_SYSTEM_NAME; ?&gt;" size="40"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Tax:&lt;/td&gt;
			&lt;td&gt;&lt;input type="text" name="tax" value="&lt;?php echo ($_REQUEST'tax'])?$_REQUEST'tax']:_DEFAULT_TAX; ?&gt;" size="5"&gt;% 
			&lt;em&gt;Optional, add this much tax ontop of payment requests (can be overridden later)&lt;/em&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Default Language:&lt;/td&gt;
			&lt;td&gt;
				&lt;select name="default_language"&gt;
					&lt;?php foreach(glob("includes/lang/*.php") as $file){
						$lang = basename(str_replace('.php','',$file));
						?&gt;
						&lt;option value="&lt;?php echo $lang; ?&gt;"&gt;&lt;?php echo $lang; ?&gt;&lt;/option&gt;
						&lt;?
					}
					?&gt;
				&lt;/select&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Date Formats:&lt;/td&gt;
			&lt;td&gt; 
			
				Date Input: 
				
				&lt;select name="date_input"&gt;
					&lt;option value="1"&gt;DD/MM/YYYY&lt;/option&gt;
					&lt;option value="2"&gt;YYYY/MM/DD&lt;/option&gt;
					&lt;option value="3"&gt;MM/DD/YYYY&lt;/option&gt;
				&lt;/select&gt;
				
				Date Output:
				
				&lt;input type="text" name="date_format" value="d/m/Y" size="6"&gt; &lt;em&gt;&lt;a href="http://php.net/date"&gt;php date syntax&lt;/a&gt;&lt;/em&gt;
				
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Currency:&lt;/td&gt;
			&lt;td&gt; 
			
				Symbol: &lt;input type="text" name="currency_code" value="$" size="4"&gt;
				Code: &lt;input type="text" name="currency_name" value="AUD" size="4"&gt;
				
				&lt;input type="radio" name="currency_location" value="before" checked&gt;(&lt;strong&gt;$&lt;/strong&gt; xxx.xx)
				&lt;input type="radio" name="currency_location" value="after"&gt;(xxx.xx &lt;strong&gt;$&lt;/strong&gt;)
				
			&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Hourly Rate:&lt;/td&gt;
			&lt;td&gt; 
			
				&lt;input type="text" name="default_rate" value="25" size="4"&gt; Per Hour
				
			&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	
	&lt;h3&gt;Step 4: Build Configuration&lt;/h3&gt;
	
	&lt;p&gt;
		Please click the button below, we will check your database connection and populate it with some default values.
	&lt;/p&gt;
	&lt;p&gt;
		&lt;input type="submit" name="submit" value="Build Configuration File"&gt;
	&lt;/p&gt;
	
	&lt;/form&gt;
&lt;?
}else{
	
	?&gt;
	
	&lt;h2&gt;Success!&lt;/h2&gt;
	
	&lt;h3&gt;Next step: Uploading your new config.php file.&lt;/h3&gt;
	
	&lt;p&gt;
		Below is the contents for your very own &lt;b&gt;config.php&lt;/b&gt; file, please upload this file into the &lt;strong&gt;includes/&lt;/strong&gt; directory (ie: includes/config.php)
	&lt;/p&gt;
	
	&lt;textarea rows=40 cols=110&gt;&lt;?php echo htmlspecialchars($config_file); ?&gt;&lt;/textarea&gt;
	
	&lt;?php if(!$install_sql || $sqlerrors){ ?&gt;
	
		&lt;h3&gt;Next step: Loading your database.&lt;/h3&gt;
		
		&lt;?php if($sqlerrors){
			?&gt;
			&lt;h4&gt;There were some errors when we tried to do this automatically, so you will have to do it manually:&lt;/h4&gt;
			&lt;?php foreach($sqlerrors as $error){
				?&gt;
				&lt;span style="color:#FF0000;"&gt;&lt;?php echo $error; ?&gt;&lt;/span&gt; &lt;br/&gt;
				&lt;?
			}
		} ?&gt;
		
		&lt;p&gt;
			Here is the SQL you need to execute on your database:
		&lt;/p&gt;
		
		&lt;textarea rows=40 cols=110&gt;&lt;?php echo htmlspecialchars($mysql); ?&gt;&lt;/textarea&gt;
	
	&lt;?php } ?&gt;
	
	&lt;h3&gt;First time login:&lt;/h3&gt;
	
	&lt;p&gt;
		After you upload the above config.php file, you can &lt;a href="index.php"&gt;login&lt;/a&gt; with the email address &lt;strong&gt;admin@example.com&lt;/strong&gt; and the password &lt;strong&gt;password&lt;/strong&gt; 
	&lt;/p&gt;
	&lt;?
}

require_once("design_footer.php");

}

Can you see any thing wrong in this?

thanks for your help, you have been a star.

As I said before, you have some short tags in there, i.e. <?. Change them all to <?php.

You should also shoot the person who wrote this script. It’s horrible.

beleave it or not, i purchased this script. I tested my server by uploading oscommerce and that script works, its evedently thiis script that is the problem and not my server configuration. I removed all the <? and changed them to <?php but now all i get it loads of weird text on the screen, this script is not functinal.

i am wondering why it works on another server? is this due to php versions?

You should look at /var/log/apache2/error_log for more clues. There may be other problems with the script which are not syntax errors but would stop proper working.

There are a lot of dubious practices in that code the result of which might depend on the whim of the PHP interpreter. I wouldn’t hire that programmer.

i have sent the php developer of this script a email, letting him know im not happy and asking him to clean this code up and resend it me, i have now wasted a week and a half playing with this and its costing our company to much money, i should ask for a refund.

I must say that you have been a great deal of help to me today, im greatfull for it.

Thankyou,

Andy