Powered by MediaWiki
Personal tools

Debugging

From b2evolution manual

Revision as of 20:35, 27 March 2012 by Fplanque (Talk | contribs)
Jump to: navigation, search

Contents

Enable Debuglog

To have a Debuglog with a load of information on the bottom of each page, set

$debug = 1;

in /conf/_advanced.php.

For even more verbose debug info, you can use

$debug = 2;

Note: this may break the proper display of some pages by inserting debug information inline.

If you want to be able to turn on/off the debuglog selectively at will, leave the default setting of $debug = 'pwd' but define a password in $debug_pwd like this:

$debug = 'pwd';
$debug_pwd = 'mysecret';

Once this is done, you can go to any page and append the following to the URL to turn on the debuglog:

?debug=mysecret

To turn off, just load a page with

?debug=

Enable the AJAX debuglog

You can also display a debuglog for AJAX calls. It will float in a CSS window about the page and will be populated in real time (for example, when loading a comment form).

Turn on with:

$debug_jslog = 1;

Alternatively, as above:

$debug_jslog = 'pwd';
$debug_pwd = 'mysecret';

Then call any page with the following appended to the url:

?jslog=mysecret

Turn off with

?jslog=

Note: For the JSlog to work properly should disable the page caching for current blog or clear the cache folder every time you want to use this param in the URL.

Enable logging of XMLRPC

To debug communication between a blogging tool which uses the XMLRPC interface, you can set

$debug_xmlrpc_logging = 1;

in /conf/_advanced.php. This will log to the file `/xmlsrv/xmlrpc.log` then and will be helpful when debugging what's going on or why a particular request fails.

You may also want to test against the latest code by using http://test.b2evo.net/HEAD/xmlsrv/xmlrpc.php (login: admin, password: demopass).

Configuration overrides

Sometimes it's useful to override some configuration settings on a specific test machine without affecting the normal configuration files that are synchronized with the production server.

To do this you can create a file called /conf/_overrides_TEST.php

This file will be loaded after all other configuration files and any setting in that file will override previous values.

Blank pages

Blank pages or sudden script abortion often mean that there's a fatal error during the PHP script execution and the website/server is configured to not display them.

A cause for this might be a parse error or the exhaustion of the memory limit).

You can try to look into the server's error log or add the following code to /conf/_basic_config.php (/conf/_config.php before b2evo 1.8):

ini_set( 'error_reporting', E_ALL ); /* report all errors */
ini_set( 'display_errors', 'on' ); /* display them on the page */

Add this after the opening "<?php" tag at the beginning of the page.

Note that this won't help, if you have a parse error in the config file you're editing itself, because PHP cannot execute the statements that change the reporting..

phpinfo

Often additional information may be useful/required.

Therefore you can setup a simple file in your web root directory like so:

<?php
phpinfo();
?>

Save this as p.php and give the URL to that file to the developer that asks for it or mention it in your bug report.

E.g., you can search on the resulting page for "safe_mode" to see if your installation is setup like so.

Permissions

If you have file permission problems, try the following script. Upload it into your "blogs" directory, where "media" is and call it from a browser. It will display a recursive list of the subdirectories in "media" and display info about the permissions that apply to each directory (including and especially user/group permissions).

Code: Display permissions and owner/group of directories recursively
<?php

$dir = dirname(__FILE__).'/media/';
#$dir = '';

echo 'Current script owner (irrelevant): '.get_current_user();
echo "<br />\n";

$processUser = posix_getpwuid(posix_geteuid());
echo 'Process user:'.$processUser['name'];
echo "<br />\n";

echo '<h1>Dirs:</h1>';
?>

<p>
Effective perms are <strong>highlighted/bold</strong>.
<br />
<span style="color:green">Green</span> user and groupnames can write.<br />
<span style="color:brown">Brown</span> user and groupnames can read.<br />
<span style="color:red">Red</span> user and groupnames cannot read/write.<br />
</p>


<?php

echo '<ul>';
print_dir_owners($dir);
echo '</ul>';

function print_dir_owners($dir)
{
	$uid = fileowner( $dir );
	$gid = filegroup( $dir );

	if( function_exists('posix_getpwuid') )
	{
		$user = posix_getpwuid($uid);
		$user = $user['name'];
		$group = posix_getpwuid($gid);
		$group = $group['name'];
	}
	else
	{
		$user = '#'.$uid;
		$group = '#'.$gid;
	}

	$perms = substr( sprintf('%o', fileperms($dir)), -3 );

	echo '<li>'.$dir.":<br />\n";

	for( $i = 0; $i < strlen($perms); $i++ )
	{
		$highlight = false;
		switch($i)
		{
			case 0:
				if( $uid == posix_geteuid() )
					$highlight = true;
				break;
			case 1:
				if( $gid == posix_geteuid() )
					$highlight = true;
				break;
			case 2:
				$highlight = true;
				break;
		}
		if( $highlight )
			echo '<strong>'.$perms{$i}.'</strong>';
		else
			echo $perms{$i};
	}
	echo ' / ';

	echo '<span style="color:';
	if( $perms{0} < 4 )
		echo 'red';
	elseif($perms{0} < 6)
		echo 'brown';
	else
		echo 'green';
	echo '">'.$user.'</span>';

	echo '/<span style="color:';
	if( $perms{1} < 4 )
		echo 'red';
	elseif($perms{1} < 6)
		echo 'brown';
	else
		echo 'green';
	echo '">'.$group.'</span>';

	if( ($dh = dir($dir)) !== false )
	{
		echo '<ul>';
		while( $entry = $dh->read() )
		{
			if( $entry == '.' || $entry == '..' )
				continue;

			if( is_dir($dir.$entry) )
			{
				print_dir_owners($dir.$entry.'/');
			}
		}
		echo '</ul>';
	}

	echo '</li>';
}


?>