diff options
Diffstat (limited to 'install')
-rw-r--r-- | install/ElggInstaller.php | 128 | ||||
-rw-r--r-- | install/ElggRewriteTester.php | 181 | ||||
-rw-r--r-- | install/languages/en.php | 24 |
3 files changed, 212 insertions, 121 deletions
diff --git a/install/ElggInstaller.php b/install/ElggInstaller.php index 7d2e2355c..57940dda3 100644 --- a/install/ElggInstaller.php +++ b/install/ElggInstaller.php @@ -56,8 +56,8 @@ class ElggInstaller { */ public function run($step) { - // check if this a mod rewrite test coming in - $this->runModRewriteTest(); + // check if this is a URL rewrite test coming in + $this->processRewriteTest(); if (!in_array($step, $this->getSteps())) { $msg = sprintf(elgg_echo('InstallationException:UnknownStep'), $step); @@ -137,14 +137,8 @@ class ElggInstaller { // check PHP parameters and libraries $this->checkPHP($report); - // check rewrite. If failure, create .htaccess and try again. - $rewriteResult = $this->checkRewriteRules($report); - if ($rewriteResult == FALSE) { - $htaccessExists = $this->createHtaccess($report); - if ($htaccessExists) { - $this->checkRewriteRules($report); - } - } + // check URL rewriting + $this->checkRewriteRules($report); // check for existence of settings file if ($this->checkSettingsFile() != TRUE) { @@ -691,6 +685,9 @@ class ElggInstaller { return $url; } + /** + * Load settings.php + */ protected function loadSettingsFile() { global $CONFIG; @@ -740,60 +737,6 @@ class ElggInstaller { */ /** - * Create Elgg's .htaccess file or confirm that it exists - * - * @param array $report Reference to the report array - * @return bool - */ - protected function createHtaccess(&$report) { - global $CONFIG; - - $filename = "{$CONFIG->path}.htaccess"; - if (file_exists($filename)) { - // check that this is the Elgg .htaccess - $data = file_get_contents($filename); - if ($data === FALSE) { - // don't have permission to read the file - } - if (strpos($data, 'Elgg') === FALSE) { - $report['htaccess'] = array( - array( - 'severity' => 'failure', - 'message' => elgg_echo('install:check:htaccess_exists'), - ) - ); - return FALSE; - } else { - // Elgg .htaccess is already there - return TRUE; - } - } - - if (!is_writable($CONFIG->path)) { - $report['htaccess'] = array( - array( - 'severity' => 'failure', - 'message' => elgg_echo('install:check:root'), - ) - ); - return FALSE; - } - - // create the .htaccess file - $result = copy("{$CONFIG->path}htaccess_dist", $filename); - if (!$result) { - $report['htaccess'] = array( - array( - 'severity' => 'failure', - 'message' => elgg_echo('install:check:htaccess_fail'), - ) - ); - } - - return $result; - } - - /** * Check that the engine dir is writable * @param array $report * @return bool @@ -917,64 +860,23 @@ class ElggInstaller { /** * Confirm that the rewrite rules are firing * @param array $report - * @return bool */ protected function checkRewriteRules(&$report) { global $CONFIG; - $url = "{$CONFIG->wwwroot}modrewrite.php"; - - if (function_exists('curl_init')) { - // try curl if installed - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - $response = curl_exec($ch); - curl_close($ch); - $result = $response === 'success'; - } else if (ini_get('allow_url_fopen')) { - // use file_get_contents as fallback - $response = file_get_contents($url); - $result = $response === 'success'; - } else { - $report['htaccess'] = array( - array( - 'severity' => 'warning', - 'message' => elgg_echo('install:check:rewrite:unknown'), - ) - ); - return FALSE; - } + require_once(dirname(__FILE__) . "/ElggRewriteTester.php"); - if ($result) { - $report['htaccess'] = array( - array( - 'severity' => 'pass', - 'message' => elgg_echo('install:check:rewrite:success'), - ) - ); - } else { - if (strpos($response, 'No input file specified.') !== FALSE) { - // nginx with no or bad rewrite rules - } - $report['htaccess'] = array( - array( - 'severity' => 'failure', - 'message' => elgg_echo('install:check:rewrite:fail'), - ) - ); - } - - return $result; + $tester = new ElggRewriteTester(); + $url = "{$CONFIG->wwwroot}rewrite.php"; + $report['rewrite'] = array($tester->run($url, $CONFIG->path)); } /** - * Check if the request is coming from the mod rewrite test on the + * Check if the request is coming from the URL rewrite test on the * requirements page. */ - protected function runModRewriteTest() { - if (strpos($_SERVER['REQUEST_URI'], 'modrewrite.php') !== FALSE) { + protected function processRewriteTest() { + if (strpos($_SERVER['REQUEST_URI'], 'rewrite.php') !== FALSE) { echo 'success'; exit; } @@ -1343,7 +1245,7 @@ class ElggInstaller { } elgg_set_ignore_access(FALSE); - // add validation data to satisfy the user validation plugins + // add validation data to satisfy user validation plugins create_metadata($guid, 'validated', TRUE, '', 0, ACCESS_PUBLIC); create_metadata($guid, 'validated_method', 'admin_user', '', 0, ACCESS_PUBLIC); diff --git a/install/ElggRewriteTester.php b/install/ElggRewriteTester.php new file mode 100644 index 000000000..7f3501059 --- /dev/null +++ b/install/ElggRewriteTester.php @@ -0,0 +1,181 @@ +<?php +/** + * Elgg RewriteTester. + * Test if URL rewriting is working. + * + * @package Elgg + * @subpackage Installer + */ + + +class ElggRewriteTester { + protected $webserver; + protected $serverSupportsRemoteRead; + protected $rewriteTestPassed; + protected $htaccessIssue; + + public function __construct() { + $this->webserver = 'unknown'; + } + + /** + * Run the rewrite test and return a status array + * + * @param string $url URL of rewrite test + * @param string $path Root directory of Elgg with trailing slash + * @return array + */ + public function run($url, $path) { + + $this->guessWebServer(); + + $this->rewriteTestPassed = $this->runRewriteTest($url); + + if ($this->rewriteTestPassed == FALSE) { + if ($this->webserver == 'apache' || $this->webserver == 'unknown') { + if ($this->createHtaccess($path)) { + $this->rewriteTestPassed = $this->runRewriteTest($url); + } + } + } + + return $this->returnStatus($url); + } + + /** + * Guess the web server from $_SERVER['SERVER_SOFTWARE'] + */ + protected function guessWebServer() { + $serverString = strtolower($_SERVER['SERVER_SOFTWARE']); + $possibleServers = array('apache', 'nginx', 'lighttpd', 'iis'); + foreach ($possibleServers as $server) { + if (strpos($serverString, $server) !== FALSE) { + $this->webserver = $server; + return; + } + } + } + + /** + * Hit the rewrite test URL to determine if the rewrite rules are working + * + * @param string $url Rewrite test URL + * @return bool + */ + protected function runRewriteTest($url) { + + $this->serverSupportsRemoteRead = TRUE; + + if (function_exists('curl_init')) { + // try curl if installed + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + $response = curl_exec($ch); + curl_close($ch); + return $response === 'success'; + } else if (ini_get('allow_url_fopen')) { + // use file_get_contents as fallback + $response = file_get_contents($url); + return $response === 'success'; + } else { + $this->serverSupportsRemoteRead = FALSE; + return FALSE; + } + } + + /** + * Create Elgg's .htaccess file or confirm that it exists + * + * @param string $path Elgg's root directory with trailing slash + * @return bool + */ + protected function createHtaccess($path) { + $filename = "{$path}.htaccess"; + if (file_exists($filename)) { + // check that this is the Elgg .htaccess + $data = file_get_contents($filename); + if ($data === FALSE) { + // don't have permission to read the file + $this->htaccessIssue = 'read_permission'; + return FALSE; + } + if (strpos($data, 'Elgg') === FALSE) { + $this->htaccessIssue = 'non_elgg_htaccess'; + return FALSE; + } else { + return TRUE; + } + } + + if (!is_writable($path)) { + $this->htaccessIssue = 'write_permission'; + return FALSE; + } + + // create the .htaccess file + $result = copy("{$path}htaccess_dist", $filename); + if (!$result) { + $this->htaccessIssue = 'cannot_copy'; + return FALSE; + } + + return TRUE; + } + + /** + * Create the status array required by the ElggInstaller + * + * @param string $url Rewrite test URL + * @return array + */ + protected function returnStatus($url) { + if ($this->rewriteTestPassed) { + return array( + 'severity' => 'pass', + 'message' => elgg_echo('install:check:rewrite:success'), + ); + } + + if ($this->serverSupportsRemoteRead == FALSE) { + $msg = sprintf(elgg_echo('install:warning:rewrite:unknown'), $url); + return array( + 'severity' => 'warning', + 'message' => $msg, + ); + } + + if ($this->webserver == 'apache') { + $serverString = elgg_echo('install:error:rewrite:apache'); + $msg = "$serverString\n\n"; + if (!isset($this->htaccessIssue)) { + $msg .= elgg_echo('install:error:rewrite:allowoverride'); + return array( + 'severity' => 'failure', + 'message' => $msg, + ); + } + $msg .= elgg_echo("install:error:rewrite:htaccess:{$this->htaccessIssue}"); + return array( + 'severity' => 'failure', + 'message' => $msg, + ); + } + + if ($this->webserver != 'unknown') { + $serverString = elgg_echo("install:error:rewrite:{$this->webserver}"); + $msg = "$serverString\n\n"; + $msg .= elgg_echo("install:error:rewrite:altserver"); + return array( + 'severity' => 'failure', + 'message' => $msg, + ); + } + + return array( + 'severity' => 'failure', + 'message' => elgg_echo('install:error:rewrite:unknown'), + ); + } +}
\ No newline at end of file diff --git a/install/languages/en.php b/install/languages/en.php index d1c9d4a02..049fd4ad4 100644 --- a/install/languages/en.php +++ b/install/languages/en.php @@ -21,11 +21,11 @@ If you haven't already, read through the installation instructions included with If you are ready to proceed, click the Next button.", 'install:requirements:instructions:success' => "Your server passed the requirement checks.", - 'install:requirements:instructions:failure' => "Your server failed the requirements check. After you have fixed the below issues, refresh this page.", + 'install:requirements:instructions:failure' => "Your server failed the requirements check. After you have fixed the below issues, refresh this page. Check the troubleshooting links at the bottom of this page if you need further assistance.", 'install:requirements:instructions:warning' => "Your server passed the requirements check, but there is at least one warning. We recommend that you check the install troubleshooting page for more details.", 'install:require:php' => 'PHP', - 'install:require:htaccess' => 'Web server', + 'install:require:rewrite' => 'Web server', 'install:require:engine' => 'Settings file', 'install:require:database' => 'Database', @@ -41,12 +41,6 @@ If you are ready to proceed, click the Next button.", 'install:check:php:open_basedir' => 'The open_basedir PHP directive may prevent Elgg from saving files to its data directory.', 'install:check:php:safe_mode' => 'Running PHP in safe mode is not recommened and may cause problems with Elgg.', - 'install:check:htaccess_exists' => 'There is an .htaccess file in the root directory of Elgg. Please remove it.', - 'install:check:htaccess_fail' => 'Unable to create an .htaccess file in the root directory of Elgg. You will need to copy htaccess_dist to .htaccess', - 'install:check:rewrite:success' => 'The test of the rewrite rules was successful.', - 'install:check:rewrite:fail' => 'The URL rewrite test failed.', - 'install:check:rewrite:unknown' => 'The result rewrite test could not be determined. Continue at your own risk.', - 'install:check:enginedir' => 'Your web server does not have permission to create the settings.php file in the engine directory. You have two choices: 1. Change the permissions on the engine directory @@ -54,6 +48,7 @@ If you are ready to proceed, click the Next button.", 2. Copy the file settings.example.php to settings.php and follow the instructions in it for setting your database parameters.', 'install:check:php:success' => "Your server's PHP satisfies all of Elgg's requirements.", + 'install:check:rewrite:success' => 'The test of the rewrite rules was successful.', 'install:check:database' => 'The database requirements are checked when Elgg loads its database.', 'install:database:instructions' => "If you haven't already created a database for Elgg, do that now. Then fill in the values below to initialize the Elgg database.", @@ -133,6 +128,19 @@ If you are ready to proceed, click the Next button.", 'install:error:loadadmin' => 'Unable to load admin user.', 'install:error:adminaccess' => 'Unable to give new user account admin privileges.', 'install:error:adminlogin' => 'Unable to login the new admin user automatically.', + 'install:error:rewrite:apache' => 'We think your server is running the Apache web server.', + 'install:error:rewrite:nginx' => 'We think your server is running the Nginx web server.', + 'install:error:rewrite:lighttpd' => 'We think your server is running the Lighttpd web server.', + 'install:error:rewrite:iis' => 'We think your server is running the IIS web server.', + 'install:error:rewrite:allowoverride' => "The rewrite test failed and the most likely cause is that AllowOverride is not set to All for Elgg's directory. This prevents Apache from processing the .htaccess file which contains the rewrite rules. + \n\nA less likely cause is Apache is configured with an alias for your Elgg directory and you need to set the RewriteBase in your .htaccess. There are further instructions in the .htaccess file in your Elgg directory.", + 'install:error:rewrite:htaccess:write_permission' => 'Your web server does not have permission to create the .htaccess file in Elgg\'s directory. You need to manually copy htaccess_dist to .htaccess or change the permissions on the directory.', + 'install:error:rewrite:htaccess:read_permission' => 'There is an .htaccess file in Elgg\'s directory, but your web server does not have permission to read it.', + 'install:error:rewrite:htaccess:non_elgg_htaccess' => 'There is an .htaccess file in Elgg\'s directory that was not not created by Elgg. Please remove it.', + 'install:error:rewrite:htaccess:cannot_copy' => 'A unknown error occurred while creating the .htaccess file. You need to manually copy htaccess_dist to .htaccess in Elgg\'s directory.', + 'install:error:rewrite:altserver' => 'The rewrite rules test failed. You need to configure your web server with Elgg\'s rewrite rules and try again.', + 'install:error:rewrite:unknown' => 'Oof. We couldn\'t figure out what kind of web server is running on your server and it failed the rewrite rules. We cannot offer any specific advice. Please check the troubleshooting link.', + 'install:warning:rewrite:unknown' => 'Your server does not support automatic testing of the rewrite rules. You can continue the installation, but you may experience problems with your site. You can manually test the rewrite rules by clicking this link: <a href="%s" target="_blank">test</a>. You will see the word success if the rules are working.', ); add_translation("en", $english); |