Apache.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Grav\Plugin\Problems;
  3. use Grav\Plugin\Problems\Base\Problem;
  4. class Apache extends Problem
  5. {
  6. public function __construct()
  7. {
  8. $this->id = 'Apache Modules';
  9. $this->class = get_class($this);
  10. $this->order = 1;
  11. $this->level = Problem::LEVEL_CRITICAL;
  12. $this->status = true;
  13. $this->help = 'https://learn.getgrav.org/basics/requirements#apache-requirements';
  14. }
  15. public function process()
  16. {
  17. // Perform some Apache checks
  18. if (function_exists('apache_get_modules') && strpos(PHP_SAPI, 'apache') !== false) {
  19. $require_apache_modules = ['mod_rewrite'];
  20. $apache_modules = apache_get_modules();
  21. $apache_errors = [];
  22. $apache_success = [];
  23. foreach ($require_apache_modules as $module) {
  24. if (in_array($module, $apache_modules, true)) {
  25. $apache_success[$module] = 'module required but not enabled';
  26. } else {
  27. $apache_errors[$module] = 'module is not installed or enabled';
  28. }
  29. }
  30. if (empty($apache_errors)) {
  31. $this->status = true;
  32. $this->msg = 'All modules look good!';
  33. } else {
  34. $this->status = false;
  35. $this->msg = 'There were problems with required modules:';
  36. }
  37. $this->details = ['errors' => $apache_errors, 'success' => $apache_success];
  38. } else {
  39. $this->msg = 'Apache not installed, skipping...';
  40. }
  41. return $this;
  42. }
  43. }