From 65f8d1920f01f8b6fee86ad53e0b6554ba26e210 Mon Sep 17 00:00:00 2001 From: Wruczek Date: Thu, 29 Mar 2018 16:41:48 +0200 Subject: [PATCH] Better error messages Yep, people still message me about problems installing ts-website, so i thought to update the modulecheck --- include/modulecheck.php | 67 +++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/include/modulecheck.php b/include/modulecheck.php index 93e4a66..afd7937 100644 --- a/include/modulecheck.php +++ b/include/modulecheck.php @@ -1,54 +1,69 @@ = 50500; -} - -if (!isPHPVersionSupported()) { +if (!defined("PHP_VERSION_ID") || PHP_VERSION_ID < 50500) { $title = 'Unsupported PHP version'; - $text = '

You are using old, unsupported PHP version.

Your PHP version: ' . phpversion() . ', required PHP version: 5.5.0.

Please update your PHP installation and try again.

'; + $text = + '

You are using old, unsupported PHP version.

' . + '

Your PHP version: ' . PHP_VERSION . ', required PHP version: 5.5.0.

' . + '

Please update your PHP installation and try again.

'; showError($title, $text); - die(); + exit; } if (!function_exists("utf8_encode")) { - $title = 'Required function "utf8_encode" is missing'; - - $text = '

Required PHP extension: mbstring has not been found on the server.

-

For PHP 7.0 (recommended), install this package: sudo apt-get install php-xml php7.0-xml and restart apache. Otherwise, installation instructions can be found on Google ;)

-

If you are using Web Hosting service, please contact the Hosting support for instruction on enabling needed packages.

'; - - showError($title, $text); - die(); + showExtensionMissingError("xml"); + exit; } -if(!is_writable(__DIR__ . '/../cache')) { +if (!extension_loaded("json")) { + showExtensionMissingError("json"); + exit; +} + +if (!extension_loaded("mbstring")) { + showExtensionMissingError("mbstring"); + exit; +} + +if((fileperms(__DIR__ . '/../cache') & 0777) !== 0777) { $title = 'Cache directory is not writable'; - $text = '

Please make sure that the cache directory is fully writable.

'; + + $text = + '

Please make sure that the cache directory is fully readable, writable and executable.

' . + '

Running: sudo chmod 777 -R ' . realpath(__DIR__ . '/../cache') . ' should fix the problem.

'; + showError($title, $text); - die(); + exit; } if (!file_exists(__DIR__ . "/../config/config.php")) { $title = 'config.php does not exists'; - $text = '

Please go into the directory config and rename config.template.php to config.php.

-

Edit the new file and tweak it to suite your needs.

'; + $text = + '

Please go into the directory config and rename config.template.php to config.php.

' . + '

Edit the new file and tweak it to suite your needs.

'; showError($title, $text); - die(); + exit; } + // FUNCTION +function showExtensionMissingError($extension_name) { + $title = 'Required extension "' . $extension_name . '" is missing'; + + $text = '

Required PHP extension ' . $extension_name . ' is missing or is not loaded.

+

Install it and restart your server. Usually running sudo apt-get install php-' . $extension_name . ' should be enough.
+

If you still get this error, try restarting your web server and php-fpm service or just reboot your machine

+

If you are using Web Hosting service, please contact their support for instructions on enabling ' . $extension_name . ' extension

'; + + showError($title, $text); +} + function showError($title, $text) { ?>