From TuxFamilyFAQ
< WebArea/Compat/PHP
Revision as of 21:23, 16 October 2020 by Xavier (talk | contribs) (First draft.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

PHP on TuxFamily

Accessing error logs

TuxFamily sysadmins are very nice. But sometimes, they are simply not available RIGHT NOW, i.e. when you are in a dire need to access PHP error logs. You can work around this issue by instructing PHP to log errors to a file of yours.

To do so, copy the adequate php.ini file in the same directory as your application's entry point (typically index.php) then append error_log = /absolute/path/to/some/file.log. Since this is easier said than done (after all TuxFamily paths can sometimes be a little counter-intuitive), you may use the following PHP script:

function nope_the_fuck_out_of_here($message) {
    echo $message . ' Aborting.';
$ini_file = php_ini_loaded_file();
if (!is_file($ini_file)) nope_the_fuck_out_of_here('Unable to determine php.ini location.');
$base_path = implode(array_slice(explode('/', realpath(getcwd()), 8), 0, 7), '/');
if (!is_dir($base_path)) nope_the_fuck_out_of_here('Non-existing webarea base path.');
$error_dirpath = $base_path . '/php-include';
if (!is_dir($error_dirpath)) nope_the_fuck_out_of_here('No php-include directory.');
$error_filepath = $error_dirpath . '/error.log';
if (!is_file('php.ini')) {
    $copy = copy($ini_file, 'php.ini');
    if (!$copy) nope_the_fuck_out_of_here("Copying ${ini_file} failed.");
} else echo "php.ini already exists, skipping copy.\n
"; $config = file_put_contents('php.ini', "error_log = ${error_filepath}\n", FILE_APPEND); if (!$config) nope_the_fuck_out_of_here("Error while setting error_log."); echo "Success! Copied ${ini_file} to the current directory and adjusted error_log to log errors into ${error_filepath}.";

Place it in the same directory as your application's entry point (typically index.php), name it own-error-log.php or own-error-log.php7 and execute it through your browser. You should get a message stating "Success!" along with details about where PHP errors will end up. Once you are done troubleshooting, remove both php.ini (or at least its error_log directive) and php-includes/error.log (otherwise you will probably fill up your project quota).