Apache.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 (strpos(php_sapi_name(), 'apache') !== false && function_exists('apache_get_modules')) {
  19. $require_apache_modules = ['mod_rewrite'];
  20. $apache_modules = apache_get_modules();
  21. $apache_errors = [];
  22. $apache_success = [];
  23. foreach ((array) $require_apache_modules as $module) {
  24. if (in_array($module, $apache_modules)) {
  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. }