4 * Note that this installer has been based of the SilverStripe installer.
5 * You can get more information from the SilverStripe Website at
6 * http://www.silverstripe.com/. Please check
7 * http://www.silverstripe.com/licensing for licensing details.
9 * Copyright (c) 2006-7, SilverStripe Limited - www.silverstripe.com
10 * All rights reserved.
12 * Changes and modifications (c) 2007-8 by CiviCRM LLC
20 ini_set('max_execution_time', 3000);
22 if (stristr(PHP_OS
, 'WIN')) {
23 define('CIVICRM_DIRECTORY_SEPARATOR', '/');
24 define('CIVICRM_WINDOWS', 1);
27 define('CIVICRM_DIRECTORY_SEPARATOR', DIRECTORY_SEPARATOR
);
28 define('CIVICRM_WINDOWS', 0);
31 // set installation type - drupal
36 // unset civicrm session if any
37 if (array_key_exists('CiviCRM', $_SESSION)) {
38 unset($_SESSION['CiviCRM']);
41 if (isset($_GET['civicrm_install_type'])) {
42 $_SESSION['civicrm_install_type'] = $_GET['civicrm_install_type'];
45 if (!isset($_SESSION['civicrm_install_type'])) {
46 $_SESSION['civicrm_install_type'] = "drupal";
51 $installType = strtolower($_SESSION['civicrm_install_type']);
53 if (!in_array($installType, array(
58 $errorTitle = "Oops! Unsupported installation mode";
60 errorDisplayPage($errorTitle, $errorMsg);
64 global $installDirPath;
65 global $installURLPath;
66 if ($installType == 'drupal') {
67 $crmPath = dirname(dirname($_SERVER['SCRIPT_FILENAME']));
68 $installDirPath = $installURLPath = '';
70 elseif ($installType == 'wordpress') {
71 $crmPath = WP_PLUGIN_DIR
. DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
;
72 $installDirPath = WP_PLUGIN_DIR
. DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
. 'install' . DIRECTORY_SEPARATOR
;
74 $installURLPath = WP_PLUGIN_URL
. DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
. 'install' . DIRECTORY_SEPARATOR
;
77 set_include_path(get_include_path() . PATH_SEPARATOR
. $crmPath);
79 require_once $crmPath . '/CRM/Core/ClassLoader.php';
80 CRM_Core_ClassLoader
::singleton()->register();
82 $docLink = CRM_Utils_System
::docURL2('Installation and Upgrades', FALSE, 'Installation Guide', NULL, NULL, "wiki");
84 if ($installType == 'drupal') {
85 //lets check only /modules/.
86 $pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR
. 'modules', CIVICRM_DIRECTORY_SEPARATOR
) . '/';
88 if (!preg_match($pattern,
89 str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME'])
92 $errorTitle = "Oops! Please Correct Your Install Location";
93 $errorMsg = "Please untar (uncompress) your downloaded copy of CiviCRM in the <strong>" . implode(CIVICRM_DIRECTORY_SEPARATOR
, array(
97 )) . "</strong> directory below your Drupal root directory. Refer to the online " . $docLink . " for more information.";
98 errorDisplayPage($errorTitle, $errorMsg);
102 // Load civicrm database config
103 if (isset($_REQUEST['mysql'])) {
104 $databaseConfig = $_REQUEST['mysql'];
107 $databaseConfig = array(
108 "server" => "localhost",
109 "username" => "civicrm",
111 "database" => "civicrm",
115 if ($installType == 'drupal') {
116 // Load drupal database config
117 if (isset($_REQUEST['drupal'])) {
118 $drupalConfig = $_REQUEST['drupal'];
121 $drupalConfig = array(
122 "server" => "localhost",
123 "username" => "drupal",
125 "database" => "drupal",
131 if (isset($_REQUEST['loadGenerated'])) {
135 require_once dirname(__FILE__
) . CIVICRM_DIRECTORY_SEPARATOR
. 'langs.php';
136 foreach ($langs as $locale => $_) {
137 if ($locale == 'en_US') {
140 if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR
, array($crmPath, 'sql', "civicrm_data.$locale.mysql")))) {
141 unset($langs[$locale]);
145 $seedLanguage = 'en_US';
146 if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) {
147 $seedLanguage = $_REQUEST['seedLanguage'];
151 if ($installType == 'drupal') {
152 //CRM-6840 -don't force to install in sites/all/modules/
153 $object = new CRM_Utils_System_Drupal();
154 $cmsPath = $object->cmsRootPath();
156 $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
157 $alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR
.
158 'sites' . CIVICRM_DIRECTORY_SEPARATOR
.
159 $siteDir . CIVICRM_DIRECTORY_SEPARATOR
.
160 'civicrm.settings.php'
163 elseif ($installType == 'wordpress') {
164 $cmsPath = WP_PLUGIN_DIR
. DIRECTORY_SEPARATOR
. 'civicrm';
165 $alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR
.
166 'civicrm.settings.php'
170 // Exit with error if CiviCRM has already been installed.
171 if ($alreadyInstalled) {
172 $errorTitle = "Oops! CiviCRM is Already Installed";
173 if ($installType == 'drupal') {
175 $errorMsg = "CiviCRM has already been installed in this Drupal site. <ul><li>To <strong>start over</strong>, you must delete or rename the existing CiviCRM settings file - <strong>civicrm.settings.php</strong> - from <strong>" . implode(CIVICRM_DIRECTORY_SEPARATOR
, array(
176 '[your Drupal root directory]',
179 )) . "</strong>.</li><li>To <strong>upgrade an existing installation</strong>, refer to the online " . $docLink . ".</li></ul>";
181 elseif ($installType == 'wordpress') {
182 $errorMsg = "CiviCRM has already been installed in this WordPress site. <ul><li>To <strong>start over</strong>, you must delete or rename the existing CiviCRM settings file - <strong>civicrm.settings.php</strong> - from <strong>" . $cmsPath . "</strong>.</li><li>To <strong>upgrade an existing installation</strong>, refer to the online " . $docLink . ".</li></ul>";
184 errorDisplayPage($errorTitle, $errorMsg);
187 $versionFile = $crmPath . CIVICRM_DIRECTORY_SEPARATOR
. 'civicrm-version.php';
188 if (file_exists($versionFile)) {
189 require_once $versionFile;
190 $civicrm_version = civicrmVersion();
193 $civicrm_version = 'unknown';
196 if ($installType == 'drupal') {
197 // Ensure that they have downloaded the correct version of CiviCRM
198 if ($civicrm_version['cms'] != 'Drupal' &&
199 $civicrm_version['cms'] != 'Drupal6'
201 $errorTitle = "Oops! Incorrect CiviCRM Version";
202 $errorMsg = "This installer can only be used for the Drupal version of CiviCRM. Refer to the online " . $docLink . " for information about installing CiviCRM on PHP4 servers OR installing CiviCRM for Joomla!";
203 errorDisplayPage($errorTitle, $errorMsg);
206 define('DRUPAL_ROOT', $cmsPath);
207 $drupalVersionFiles = array(
209 implode(CIVICRM_DIRECTORY_SEPARATOR
, array($cmsPath, 'modules', 'system', 'system.module')),
211 implode(CIVICRM_DIRECTORY_SEPARATOR
, array($cmsPath, 'includes', 'bootstrap.inc')),
213 foreach ($drupalVersionFiles as $drupalVersionFile) {
214 if (file_exists($drupalVersionFile)) {
215 require_once $drupalVersionFile;
219 if (!defined('VERSION') or version_compare(VERSION
, '6.0') < 0) {
220 $errorTitle = "Oops! Incorrect Drupal Version";
221 $errorMsg = "This version of CiviCRM can only be used with Drupal 6.x or 7.x. Please ensure that '" . implode("' or '", $drupalVersionFiles) . "' exists if you are running Drupal 7.0 and over. Refer to the online " . $docLink . " for information about installing CiviCRM.";
222 errorDisplayPage($errorTitle, $errorMsg);
225 elseif ($installType == 'wordpress') {
227 $civicrm_version['cms'] = 'WordPress';
229 // Ensure that they have downloaded the correct version of CiviCRM
230 if ($civicrm_version['cms'] != 'WordPress') {
231 $errorTitle = "Oops! Incorrect CiviCRM Version";
232 $errorMsg = "This installer can only be used for the WordPress version of CiviCRM. Refer to the online " . $docLink . " for information about installing CiviCRM for Drupal or Joomla!";
233 errorDisplayPage($errorTitle, $errorMsg);
237 // Check requirements
238 $req = new InstallRequirements();
241 if ($req->hasErrors()) {
242 $hasErrorOtherThanDatabase = TRUE;
245 if ($databaseConfig) {
246 $dbReq = new InstallRequirements();
247 $dbReq->checkdatabase($databaseConfig, 'CiviCRM');
248 if ($installType == 'drupal') {
249 $dbReq->checkdatabase($drupalConfig, 'Drupal');
254 if (isset($_REQUEST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
255 // Confirm before reinstalling
256 if (!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
257 include $installDirPath . 'template.html';
260 $inst = new Installer();
261 $inst->install($_REQUEST);
264 // Show the config form
267 include $installDirPath . 'template.html';
271 * This class checks requirements
272 * Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array
274 * $description[0] - The test catetgory
275 * $description[1] - The test title
276 * $description[2] - The test error to show, if it goes wrong
278 class InstallRequirements
{
279 var $errors, $warnings, $tests;
281 // @see CRM_Upgrade_Form::MINIMUM_THREAD_STACK
282 const MINIMUM_THREAD_STACK
= 192;
285 * Just check that the database configuration is okay
287 function checkdatabase($databaseConfig, $dbName) {
288 if ($this->requireFunction('mysql_connect',
292 "MySQL support not included in PHP.",
296 $this->requireMySQLServer($databaseConfig['server'],
298 "MySQL $dbName Configuration",
299 "Does the server exist",
300 "Can't find the a MySQL server on '$databaseConfig[server]'",
301 $databaseConfig['server'],
304 if ($this->requireMysqlConnection($databaseConfig['server'],
305 $databaseConfig['username'],
306 $databaseConfig['password'],
308 "MySQL $dbName Configuration",
309 "Are the access credentials correct",
310 "That username/password doesn't work",
314 @$this->requireMySQLVersion("5.1",
316 "MySQL $dbName Configuration",
317 "MySQL version at least 5.1",
318 "MySQL version 5.1 or higher is required, you only have ",
319 "MySQL " . mysql_get_server_info(),
322 $this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'],
323 $databaseConfig['username'],
324 $databaseConfig['password'],
326 "MySQL $dbName Configuration",
327 "Is auto_increment_increment set to 1",
328 "An auto_increment_increment value greater than 1 is not currently supported. Please see issue CRM-7923 for further details and potential workaround.",
331 $this->requireMySQLThreadStack($databaseConfig['server'],
332 $databaseConfig['username'],
333 $databaseConfig['password'],
334 $databaseConfig['database'],
335 self
::MINIMUM_THREAD_STACK
,
337 "MySQL $dbName Configuration",
338 "Does MySQL thread_stack meet minimum (" . self
::MINIMUM_THREAD_STACK
. "k)",
340 // "The MySQL thread_stack does not meet minimum " . CRM_Upgrade_Form::MINIMUM_THREAD_STACK . "k. Please update thread_stack in my.cnf.",
344 $onlyRequire = ($dbName == 'Drupal') ?
TRUE : FALSE;
345 $this->requireDatabaseOrCreatePermissions(
346 $databaseConfig['server'],
347 $databaseConfig['username'],
348 $databaseConfig['password'],
349 $databaseConfig['database'],
351 "MySQL $dbName Configuration",
352 "Can I access/create the database",
353 "I can't create new databases and the database '$databaseConfig[database]' doesn't exist",
357 if ($dbName != 'Drupal') {
358 $this->requireMySQLInnoDB($databaseConfig['server'],
359 $databaseConfig['username'],
360 $databaseConfig['password'],
361 $databaseConfig['database'],
363 "MySQL $dbName Configuration",
364 "Can I access/create InnoDB tables in the database",
365 "Unable to create InnoDB tables. MySQL InnoDB support is required for CiviCRM but is either not available or not enabled in this MySQL database server.",
368 $this->requireMySQLTempTables($databaseConfig['server'],
369 $databaseConfig['username'],
370 $databaseConfig['password'],
371 $databaseConfig['database'],
373 "MySQL $dbName Configuration",
374 'Can I create temporary tables in the database',
375 'Unable to create temporary tables. This MySQL user is missing the CREATE TEMPORARY TABLES privilege.',
378 $this->requireMySQLLockTables($databaseConfig['server'],
379 $databaseConfig['username'],
380 $databaseConfig['password'],
381 $databaseConfig['database'],
383 "MySQL $dbName Configuration",
384 'Can I create lock tables in the database',
385 'Unable to lock tables. This MySQL user is missing the LOCK TABLES privilege.',
388 $this->requireMySQLTrigger($databaseConfig['server'],
389 $databaseConfig['username'],
390 $databaseConfig['password'],
391 $databaseConfig['database'],
393 "MySQL $dbName Configuration",
394 'Can I create triggers in the database',
395 'Unable to create triggers. This MySQL user is missing the CREATE TRIGGERS privilege.',
403 * Check everything except the database
406 global $crmPath, $installType;
408 $this->errors
= NULL;
410 $this->requirePHPVersion('5.3.3', array(
414 "PHP version " . phpversion()
417 // Check that we can identify the root folder successfully
418 $this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR
. 'README.txt',
421 "Does the webserver know where files are stored?",
422 "The webserver isn't letting me identify where files are stored.",
428 // CRM-6485: make sure the path does not contain PATH_SEPARATOR, as we don’t know how to escape it
429 $this->requireNoPathSeparator(
432 'does the CiviCRM path contain PATH_SEPARATOR?',
433 'the ' . $this->getBaseDir() . ' path contains PATH_SEPARATOR (the ' . PATH_SEPARATOR
. ' character)',
438 $requiredDirectories = array('CRM', 'packages', 'templates', 'js', 'api', 'i', 'sql');
439 foreach ($requiredDirectories as $dir) {
440 $this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR
. $dir,
443 "$dir folder exists",
444 "There is no $dir folder"
449 $configIDSiniDir = NULL;
451 $siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
452 if ($installType == 'drupal') {
454 // make sure that we can write to sites/default and files/
455 $writableDirectories = array(
456 $cmsPath . CIVICRM_DIRECTORY_SEPARATOR
.
457 'sites' . CIVICRM_DIRECTORY_SEPARATOR
.
458 $siteDir . CIVICRM_DIRECTORY_SEPARATOR
.
460 $cmsPath . CIVICRM_DIRECTORY_SEPARATOR
.
461 'sites' . CIVICRM_DIRECTORY_SEPARATOR
.
465 elseif ($installType == 'wordpress') {
466 // make sure that we can write to plugins/civicrm and plugins/files/
467 $writableDirectories = array(WP_PLUGIN_DIR
. DIRECTORY_SEPARATOR
. 'files', $cmsPath);
470 foreach ($writableDirectories as $dir) {
471 $dirName = CIVICRM_WINDOWS ?
$dir : CIVICRM_DIRECTORY_SEPARATOR
. $dir;
472 $this->requireWriteable($dirName,
473 array("File permissions", "Is the $dir folder writeable?", NULL),
478 //check for Config.IDS.ini, file may exist in re-install
479 $configIDSiniDir = array($cmsPath, 'sites', $siteDir, 'files', 'civicrm', 'upload', 'Config.IDS.ini');
481 if (is_array($configIDSiniDir) && !empty($configIDSiniDir)) {
482 $configIDSiniFile = implode(CIVICRM_DIRECTORY_SEPARATOR
, $configIDSiniDir);
483 if (file_exists($configIDSiniFile)) {
484 unlink($configIDSiniFile);
488 // Check for rewriting
489 if (isset($_SERVER['SERVER_SOFTWARE'])) {
490 $webserver = strip_tags(trim($_SERVER['SERVER_SOFTWARE']));
492 elseif (isset($_SERVER['SERVER_SIGNATURE'])) {
493 $webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
496 if ($webserver == '') {
497 $webserver = "I can't tell what webserver you are running";
500 // Check for $_SERVER configuration
501 $this->requireServerVariables(array('SCRIPT_NAME', 'HTTP_HOST', 'SCRIPT_FILENAME'), array(
503 "Recognised webserver",
504 "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."
507 // Check for MySQL support
508 $this->requireFunction('mysql_connect',
509 array("PHP Configuration", "MySQL support", "MySQL support not included in PHP.")
512 // Check for JSON support
513 $this->requireFunction('json_encode',
514 array("PHP Configuration", "JSON support", "JSON support not included in PHP.")
517 // Check for xcache_isset and emit warning if exists
518 $this->checkXCache(array(
520 "XCache compatibility",
521 "XCache is installed and there are known compatibility issues between XCache and CiviCRM. Consider using an alternative PHP caching mechanism or disable PHP caching altogether.",
524 // Check memory allocation
525 $this->requireMemory(32 * 1024 * 1024,
529 "Memory allocated (PHP config option 'memory_limit')",
530 "CiviCRM needs a minimum of 32M allocated to PHP, but recommends 64M.",
531 ini_get("memory_limit"),
535 return $this->errors
;
540 * @param $recommended
541 * @param $testDetails
543 function requireMemory($min, $recommended, $testDetails) {
544 $this->testing($testDetails);
545 $mem = $this->getPHPMemory();
547 if ($mem < $min && $mem > 0) {
548 $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
549 $this->error($testDetails);
551 elseif ($mem < $recommended && $mem > 0) {
552 $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
553 $this->warning($testDetails);
556 $testDetails[2] .= " We can't determine how much memory you have allocated. Install only if you're sure you've allocated at least 20 MB.";
557 $this->warning($testDetails);
564 function getPHPMemory() {
565 $memString = ini_get("memory_limit");
567 switch (strtolower(substr($memString, -1))) {
569 return round(substr($memString, 0, -1) * 1024);
572 return round(substr($memString, 0, -1) * 1024 * 1024);
575 return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
578 return round($memString);
582 function listErrors() {
584 echo "<p>The following problems are preventing me from installing CiviCRM:</p>";
585 foreach ($this->errors
as $error) {
586 echo "<li>" . htmlentities($error) . "</li>";
592 * @param null $section
594 function showTable($section = NULL) {
596 $tests = $this->tests
[$section];
597 echo "<table class=\"testResults\" width=\"100%\">";
598 foreach ($tests as $test => $result) {
599 echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
604 foreach ($this->tests
as $section => $tests) {
605 echo "<h3>$section</h3>";
606 echo "<table class=\"testResults\" width=\"100%\">";
608 foreach ($tests as $test => $result) {
609 echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
617 * @param string $funcName
618 * @param $testDetails
622 function requireFunction($funcName, $testDetails) {
623 $this->testing($testDetails);
625 if (!function_exists($funcName)) {
626 $this->error($testDetails);
635 * @param $testDetails
637 function checkXCache($testDetails) {
638 if (function_exists('xcache_isset') &&
639 ini_get('xcache.size') > 0
641 $this->testing($testDetails);
642 $this->warning($testDetails);
648 * @param $testDetails
649 * @param null $maxVersion
651 function requirePHPVersion($minVersion, $testDetails, $maxVersion = NULL) {
653 $this->testing($testDetails);
655 $phpVersion = phpversion();
656 $aboveMinVersion = version_compare($phpVersion, $minVersion) >= 0;
657 $belowMaxVersion = $maxVersion ?
version_compare($phpVersion, $maxVersion) < 0 : TRUE;
659 if ($maxVersion && $aboveMinVersion && $belowMaxVersion) {
662 elseif (!$maxVersion && $aboveMinVersion) {
666 if (!$testDetails[2]) {
667 if (!$aboveMinVersion) {
668 $testDetails[2] = "You need PHP version $minVersion or later, only {$phpVersion} is installed. Please upgrade your server, or ask your web-host to do so.";
671 $testDetails[2] = "PHP version {$phpVersion} is not supported. PHP version earlier than $maxVersion is required. You might want to downgrade your server, or ask your web-host to do so.";
675 $this->error($testDetails);
679 * @param string $filename
680 * @param $testDetails
681 * @param bool $absolute
683 function requireFile($filename, $testDetails, $absolute = FALSE) {
684 $this->testing($testDetails);
686 $filename = $this->getBaseDir() . $filename;
688 if (!file_exists($filename)) {
689 $testDetails[2] .= " (file '$filename' not found)";
690 $this->error($testDetails);
695 * @param $testDetails
697 function requireNoPathSeparator($testDetails) {
698 $this->testing($testDetails);
699 if (substr_count($this->getBaseDir(), PATH_SEPARATOR
)) {
700 $this->error($testDetails);
705 * @param string $filename
706 * @param $testDetails
708 function requireNoFile($filename, $testDetails) {
709 $this->testing($testDetails);
710 $filename = $this->getBaseDir() . $filename;
711 if (file_exists($filename)) {
712 $testDetails[2] .= " (file '$filename' found)";
713 $this->error($testDetails);
718 * @param string $filename
719 * @param $testDetails
721 function moveFileOutOfTheWay($filename, $testDetails) {
722 $this->testing($testDetails);
723 $filename = $this->getBaseDir() . $filename;
724 if (file_exists($filename)) {
725 if (file_exists("$filename.bak")) {
728 rename($filename, "$filename.bak");
733 * @param string $filename
734 * @param $testDetails
735 * @param bool $absolute
737 function requireWriteable($filename, $testDetails, $absolute = FALSE) {
738 $this->testing($testDetails);
740 $filename = $this->getBaseDir() . $filename;
743 if (!is_writable($filename)) {
745 if (function_exists('posix_getpwuid')) {
746 $user = posix_getpwuid(posix_geteuid());
747 $name = '- ' . $user['name'] . ' -';
750 if (!isset($testDetails[2])) {
751 $testDetails[2] = NULL;
753 $testDetails[2] .= "The user account used by your web-server $name needs to be granted write access to the following directory in order to configure the CiviCRM settings file:\n$filename";
754 $this->error($testDetails);
759 * @param string $moduleName
760 * @param $testDetails
762 function requireApacheModule($moduleName, $testDetails) {
763 $this->testing($testDetails);
764 if (!in_array($moduleName, apache_get_modules())) {
765 $this->error($testDetails);
771 * @param string $username
773 * @param $testDetails
775 function requireMysqlConnection($server, $username, $password, $testDetails) {
776 $this->testing($testDetails);
777 $conn = @mysql_connect
($server, $username, $password);
783 $testDetails[2] .= ": " . mysql_error();
784 $this->error($testDetails);
790 * @param $testDetails
792 function requireMySQLServer($server, $testDetails) {
793 $this->testing($testDetails);
794 $conn = @mysql_connect
($server, NULL, NULL);
796 if ($conn ||
mysql_errno() < 2000) {
800 $testDetails[2] .= ": " . mysql_error();
801 $this->error($testDetails);
807 * @param $testDetails
809 function requireMySQLVersion($version, $testDetails) {
810 $this->testing($testDetails);
812 if (!mysql_get_server_info()) {
813 $testDetails[2] = 'Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.';
814 $this->warning($testDetails);
817 list($majorRequested, $minorRequested) = explode('.', $version);
818 list($majorHas, $minorHas) = explode('.', mysql_get_server_info());
820 if (($majorHas > $majorRequested) ||
($majorHas == $majorRequested && $minorHas >= $minorRequested)) {
824 $testDetails[2] .= "{$majorHas}.{$minorHas}.";
825 $this->error($testDetails);
832 * @param string $username
835 * @param $testDetails
837 function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) {
838 $this->testing($testDetails);
839 $conn = @mysql_connect
($server, $username, $password);
841 $testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
842 $this->error($testDetails);
846 $innodb_support = FALSE;
847 $result = mysql_query("SHOW ENGINES", $conn);
848 while ($values = mysql_fetch_array($result)) {
849 if ($values['Engine'] == 'InnoDB') {
850 if (strtolower($values['Support']) == 'yes' ||
851 strtolower($values['Support']) == 'default'
853 $innodb_support = TRUE;
857 if ($innodb_support) {
858 $testDetails[3] = 'MySQL server does have innodb support';
861 $testDetails[2] .= ' Could not determine if mysql has innodb support. Assuming no';
867 * @param string $username
870 * @param $testDetails
872 function requireMySQLTempTables($server, $username, $password, $database, $testDetails) {
873 $this->testing($testDetails);
874 $conn = @mysql_connect
($server, $username, $password);
876 $testDetails[2] = 'Could not login to the database.';
877 $this->error($testDetails);
881 if (!@mysql_select_db
($database, $conn)) {
882 $testDetails[2] = 'Could not select the database.';
883 $this->error($testDetails);
887 $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
889 $testDetails[2] = 'Could not create a temp table.';
890 $this->error($testDetails);
892 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
897 * @param string $username
900 * @param $testDetails
902 function requireMySQLTrigger($server, $username, $password, $database, $testDetails) {
903 $this->testing($testDetails);
904 $conn = @mysql_connect
($server, $username, $password);
906 $testDetails[2] = 'Could not login to the database.';
907 $this->error($testDetails);
911 if (!@mysql_select_db
($database, $conn)) {
912 $testDetails[2] = 'Could not select the database.';
913 $this->error($testDetails);
917 $result = mysql_query('CREATE TABLE civicrm_install_temp_table_test (test text)', $conn);
919 $testDetails[2] = 'Could not create a table.';
920 $this->error($testDetails);
923 $result = mysql_query('CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END');
925 mysql_query('DROP TABLE civicrm_install_temp_table_test');
926 $testDetails[2] = 'Could not create a trigger.';
927 $this->error($testDetails);
930 mysql_query('DROP TRIGGER civicrm_install_temp_table_test_trigger');
931 mysql_query('DROP TABLE civicrm_install_temp_table_test');
937 * @param string $username
940 * @param $testDetails
942 function requireMySQLLockTables($server, $username, $password, $database, $testDetails) {
943 $this->testing($testDetails);
944 $conn = @mysql_connect
($server, $username, $password);
946 $testDetails[2] = 'Could not login to the database.';
947 $this->error($testDetails);
951 if (!@mysql_select_db
($database, $conn)) {
952 $testDetails[2] = 'Could not select the database.';
953 $this->error($testDetails);
957 $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn);
959 $testDetails[2] = 'Could not create a table.';
960 $this->error($testDetails);
964 $result = mysql_query('LOCK TABLES civicrm_install_temp_table_test WRITE', $conn);
966 $testDetails[2] = 'Could not obtain a write lock for the table.';
967 $this->error($testDetails);
968 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
972 $result = mysql_query('UNLOCK TABLES', $conn);
974 $testDetails[2] = 'Could not release the lock for the table.';
975 $this->error($testDetails);
976 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
980 $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test');
986 * @param string $username
988 * @param $testDetails
990 function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) {
991 $this->testing($testDetails);
992 $conn = @mysql_connect
($server, $username, $password);
994 $testDetails[2] = 'Could not connect to the database server.';
995 $this->error($testDetails);
999 $result = mysql_query("SHOW variables like 'auto_increment_increment'", $conn);
1001 $testDetails[2] = 'Could not query database server variables.';
1002 $this->error($testDetails);
1006 $values = mysql_fetch_row($result);
1007 if ($values[1] == 1) {
1008 $testDetails[3] = 'MySQL server auto_increment_increment is 1';
1011 $this->error($testDetails);
1018 * @param string $username
1021 * @param $minValueKB
1022 * @param $testDetails
1024 function requireMySQLThreadStack($server, $username, $password, $database, $minValueKB, $testDetails) {
1025 $this->testing($testDetails);
1026 $conn = @mysql_connect
($server, $username, $password);
1028 $testDetails[2] = 'Could not login to the database.';
1029 $this->error($testDetails);
1033 if (!@mysql_select_db
($database, $conn)) {
1034 $testDetails[2] = 'Could not select the database.';
1035 $this->error($testDetails);
1039 $result = mysql_query("SHOW VARIABLES LIKE 'thread_stack'", $conn); // bytes => kb
1041 $testDetails[2] = 'Could not query thread_stack.';
1042 $this->error($testDetails);
1045 $values = mysql_fetch_row($result);
1046 if ($values[1] < (1024 * $minValueKB)) {
1047 $testDetails[2] = 'MySQL "thread_stack" is ' . ($values[1] / 1024) . 'k';
1048 $this->error($testDetails);
1055 * @param string $username
1058 * @param $testDetails
1059 * @param bool $onlyRequire
1061 function requireDatabaseOrCreatePermissions(
1067 $onlyRequire = FALSE
1069 $this->testing($testDetails);
1070 $conn = @mysql_connect
($server, $username, $password);
1073 if (@mysql_select_db
($database)) {
1074 $okay = "Database '$database' exists";
1076 elseif ($onlyRequire) {
1077 $testDetails[2] = "The database: '$database' does not exist";
1078 $this->error($testDetails);
1082 if (@mysql_query
("CREATE DATABASE $database")) {
1083 $okay = "Able to create a new database";
1086 $testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
1087 $this->error($testDetails);
1093 $testDetails[3] = $okay;
1094 $this->testing($testDetails);
1100 * @param $errorMessage
1102 function requireServerVariables($varNames, $errorMessage) {
1103 //$this->testing($testDetails);
1104 foreach ($varNames as $varName) {
1105 if (!$_SERVER[$varName]) {
1106 $missing[] = '$_SERVER[' . $varName . ']';
1109 if (!isset($missing)) {
1113 $testDetails[2] = " (the following PHP variables are missing: " . implode(", ", $missing) . ")";
1114 $this->error($testDetails);
1119 * @param $testDetails
1123 function isRunningApache($testDetails) {
1124 $this->testing($testDetails);
1125 if (function_exists('apache_get_modules') ||
stristr($_SERVER['SERVER_SIGNATURE'], 'Apache')) {
1129 $this->warning($testDetails);
1136 function getBaseDir() {
1137 return dirname($_SERVER['SCRIPT_FILENAME']) . CIVICRM_DIRECTORY_SEPARATOR
;
1141 * @param $testDetails
1143 function testing($testDetails) {
1144 if (!$testDetails) {
1148 $section = $testDetails[0];
1149 $test = $testDetails[1];
1152 if (isset($testDetails[3])) {
1153 $message .= " ($testDetails[3])";
1156 $this->tests
[$section][$test] = array("good", $message);
1160 * @param $testDetails
1162 function error($testDetails) {
1163 $section = $testDetails[0];
1164 $test = $testDetails[1];
1166 $this->tests
[$section][$test] = array("error", $testDetails[2]);
1167 $this->errors
[] = $testDetails;
1171 * @param $testDetails
1173 function warning($testDetails) {
1174 $section = $testDetails[0];
1175 $test = $testDetails[1];
1177 $this->tests
[$section][$test] = array("warning", $testDetails[2]);
1178 $this->warnings
[] = $testDetails;
1184 function hasErrors() {
1185 return sizeof($this->errors
);
1191 function hasWarnings() {
1192 return sizeof($this->warnings
);
1199 class Installer
extends InstallRequirements
{
1206 function createDatabaseIfNotExists($server, $username, $password, $database) {
1207 $conn = @mysql_connect
($server, $username, $password);
1209 if (@mysql_select_db
($database)) {
1210 // skip if database already present
1214 if (@mysql_query
("CREATE DATABASE $database")) {
1217 $errorTitle = "Oops! Could not create Database $database";
1218 $errorMsg = "We encountered an error when attempting to create the database. Please check your mysql server permissions and the database name and try again.";
1219 errorDisplayPage($errorTitle, $errorMsg);
1228 function install($config) {
1229 global $installDirPath;
1231 // create database if does not exists
1232 $this->createDatabaseIfNotExists($config['mysql']['server'],
1233 $config['mysql']['username'],
1234 $config['mysql']['password'],
1235 $config['mysql']['database']
1238 global $installDirPath;
1241 require_once $installDirPath . 'civicrm.php';
1242 civicrm_main($config);
1244 if (!$this->errors
) {
1245 global $installType, $installURLPath;
1247 $registerSiteURL = "https://civicrm.org/register-site";
1248 $commonOutputMessage = "
1249 <li>Have you registered this site at CiviCRM.org? If not, please help strengthen the CiviCRM ecosystem by taking a few minutes to <a href='$registerSiteURL' target='_blank'>fill out the site registration form</a>. The information collected will help us prioritize improvements, target our communications and build the community. If you have a technical role for this site, be sure to check Keep in Touch to receive technical updates (a low volume mailing list).</li>
1250 <li>We have integrated KCFinder with CKEditor and TinyMCE. This allows a user to upload images. All uploaded images are public.</li>
1255 $installType == 'drupal' &&
1256 version_compare(VERSION
, '7.0-rc1') >= 0
1262 $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
1263 $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1264 $output .= '<head>';
1265 $output .= '<title>CiviCRM Installed</title>';
1266 $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
1267 $output .= '</head>';
1268 $output .= '<body>';
1269 $output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
1271 $docLinkConfig = CRM_Utils_System
::docURL2('Configuring a New Site', FALSE, 'here', NULL, NULL, "wiki");
1272 if (!function_exists('ts')) {
1273 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1275 $drupalURL = civicrm_cms_base();
1276 $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/people/permissions";
1277 $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
1279 $output .= "<li>Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a target='_blank' href={$drupalPermissionsURL}>review these permissions</a> to ensure that they are appropriate for your requirements (<a target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'>learn more...</a>)</li>
1280 <li>Use the <a target='_blank' href=\"$drupalURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1281 {$commonOutputMessage}";
1283 // automatically enable CiviCRM module once it is installed successfully.
1284 // so we need to Bootstrap Drupal, so that we can call drupal hooks.
1285 global $cmsPath, $crmPath;
1287 // relative / abosolute paths are not working for drupal, hence using chdir()
1290 include_once "./includes/bootstrap.inc";
1291 include_once "./includes/unicode.inc";
1293 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL
);
1295 // prevent session information from being saved.
1296 drupal_save_session(FALSE);
1298 // Force the current user to anonymous.
1299 $original_user = $GLOBALS['user'];
1300 $GLOBALS['user'] = drupal_anonymous_user();
1302 // explicitly setting error reporting, since we cannot handle drupal related notices
1305 // rebuild modules, so that civicrm is added
1306 system_rebuild_module_data();
1308 // now enable civicrm module.
1309 module_enable(array('civicrm', 'civicrmtheme'));
1311 // clear block, page, theme, and hook caches
1312 drupal_flush_all_caches();
1314 //add basic drupal permissions
1315 civicrm_install_set_drupal_perms();
1317 // restore the user.
1318 $GLOBALS['user'] = $original_user;
1319 drupal_save_session(TRUE);
1322 $output .= '</div>';
1323 $output .= '</body>';
1324 $output .= '</html>';
1327 elseif ($installType == 'drupal' && version_compare(VERSION
, '6.0') >= 0) {
1331 $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
1332 $output .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1333 $output .= '<head>';
1334 $output .= '<title>CiviCRM Installed</title>';
1335 $output .= '<link rel="stylesheet" type="text/css" href="template.css" />';
1336 $output .= '</head>';
1337 $output .= '<body>';
1338 $output .= '<div style="padding: 1em;"><p class="good">CiviCRM has been successfully installed</p>';
1340 $docLinkConfig = CRM_Utils_System
::docURL2('Configuring a New Site', FALSE, 'here', NULL, NULL, "wiki");
1341 if (!function_exists('ts')) {
1342 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1344 $drupalURL = civicrm_cms_base();
1345 $drupalPermissionsURL = "{$drupalURL}index.php?q=admin/user/permissions";
1346 $drupalURL .= "index.php?q=civicrm/admin/configtask&reset=1";
1348 $output .= "<li>Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you <a target='_blank' href={$drupalPermissionsURL}>review these permissions</a> to ensure that they are appropriate for your requirements (<a target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'>learn more...</a>)</li>
1349 <li>Use the <a target='_blank' href=\"$drupalURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1350 {$commonOutputMessage}";
1352 // explicitly setting error reporting, since we cannot handle drupal related notices
1355 // automatically enable CiviCRM module once it is installed successfully.
1356 // so we need to Bootstrap Drupal, so that we can call drupal hooks.
1357 global $cmsPath, $crmPath;
1359 // relative / abosolute paths are not working for drupal, hence using chdir()
1362 include_once "./includes/bootstrap.inc";
1363 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL
);
1365 // rebuild modules, so that civicrm is added
1366 module_rebuild_cache();
1368 // now enable civicrm module.
1369 module_enable(array('civicrm'));
1371 // clear block, page, theme, and hook caches
1372 drupal_flush_all_caches();
1374 //add basic drupal permissions
1375 db_query('UPDATE {permission} SET perm = CONCAT( perm, \', access CiviMail subscribe/unsubscribe pages, access all custom data, access uploaded files, make online contributions, profile create, profile edit, profile view, register for events, view event info\') WHERE rid IN (1, 2)');
1379 elseif ($installType == 'wordpress') {
1380 echo '<h1>CiviCRM Installed</h1>';
1381 echo '<div style="padding: 1em;"><p style="background-color: #0C0; border: 1px #070 solid; color: white;">CiviCRM has been successfully installed</p>';
1383 $docLinkConfig = CRM_Utils_System
::docURL2('Configuring a New Site', FALSE, 'here', NULL, NULL, "wiki");
1384 if (!function_exists('ts')) {
1385 $docLinkConfig = "<a href=\"{$docLinkConfig}\">here</a>";
1388 $cmsURL = civicrm_cms_base();
1389 $cmsURL .= "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/configtask&reset=1";
1390 $wpPermissionsURL = "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/access/wp-permissions&reset=1";
1393 <li>WordPress user permissions have been automatically set - giving Anonymous and Subscribers access to public CiviCRM forms and features. We recommend that you <a target='_blank' href={$wpPermissionsURL}>review these permissions</a> to ensure that they are appropriate for your requirements (<a target='_blank' href='http://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles'>learn more...</a>)</li>
1394 <li>Use the <a target='_blank' href=\"$cmsURL\">Configuration Checklist</a> to review and configure settings for your new site</li>
1395 {$commonOutputMessage}
1403 return $this->errors
;
1407 function civicrm_install_set_drupal_perms() {
1408 if (!function_exists('db_select')) {
1409 db_query('UPDATE {permission} SET perm = CONCAT( perm, \', access CiviMail subscribe/unsubscribe pages, access all custom data, access uploaded files, make online contributions, profile listings and forms, register for events, view event info, view event participants\') WHERE rid IN (1, 2)');
1413 'access all custom data',
1414 'access uploaded files',
1415 'make online contributions',
1419 'register for events',
1421 'view event participants',
1422 'access CiviMail subscribe/unsubscribe pages',
1425 // Adding a permission that has not yet been assigned to a module by
1426 // a hook_permission implementation results in a database error.
1428 $allPerms = array_keys(module_invoke_all('permission'));
1429 foreach (array_diff($perms, $allPerms) as $perm) {
1431 'Cannot grant the %perm permission because it does not yet exist.',
1437 $perms = array_intersect($perms, $allPerms);
1438 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID
, $perms);
1439 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID
, $perms);
1449 function getSiteDir($cmsPath, $str) {
1450 static $siteDir = '';
1456 $sites = CIVICRM_DIRECTORY_SEPARATOR
. 'sites' . CIVICRM_DIRECTORY_SEPARATOR
;
1457 $modules = CIVICRM_DIRECTORY_SEPARATOR
. 'modules' . CIVICRM_DIRECTORY_SEPARATOR
;
1458 preg_match("/" . preg_quote($sites, CIVICRM_DIRECTORY_SEPARATOR
) .
1459 "([\-a-zA-Z0-9_.]+)" .
1460 preg_quote($modules, CIVICRM_DIRECTORY_SEPARATOR
) . "/",
1461 $_SERVER['SCRIPT_FILENAME'], $matches
1463 $siteDir = isset($matches[1]) ?
$matches[1] : 'default';
1465 if (strtolower($siteDir) == 'all') {
1466 // For this case - use drupal's way of finding out multi-site directory
1467 $uri = explode(CIVICRM_DIRECTORY_SEPARATOR
, $_SERVER['SCRIPT_FILENAME']);
1468 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
1469 for ($i = count($uri) - 1; $i > 0; $i--) {
1470 for ($j = count($server); $j > 0; $j--) {
1471 $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
1472 if (file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR
.
1473 'sites' . CIVICRM_DIRECTORY_SEPARATOR
. $dir
1480 $siteDir = 'default';
1487 * @param $errorTitle
1490 function errorDisplayPage($errorTitle, $errorMsg) {
1491 include 'error.html';