register();
$docLink = CRM_Utils_System::docURL2('Installation and Upgrades', FALSE, 'Installation Guide',NULL,NULL,"wiki");
if ($installType == 'drupal') {
//lets check only /modules/.
$pattern = '/' . preg_quote(CIVICRM_DIRECTORY_SEPARATOR . 'modules', CIVICRM_DIRECTORY_SEPARATOR) . '/';
if (!preg_match($pattern,
str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME'])
)) {
$errorTitle = "Oops! Please Correct Your Install Location";
$errorMsg = "Please untar (uncompress) your downloaded copy of CiviCRM in the " . implode(CIVICRM_DIRECTORY_SEPARATOR, array(
'sites', 'all', 'modules')) . " directory below your Drupal root directory. Refer to the online " . $docLink . " for more information.";
errorDisplayPage($errorTitle, $errorMsg);
}
}
// Load civicrm database config
if (isset($_REQUEST['mysql'])) {
$databaseConfig = $_REQUEST['mysql'];
}
else {
$databaseConfig = array(
"server" => "localhost",
"username" => "civicrm",
"password" => "",
"database" => "civicrm",
);
}
if ($installType == 'drupal') {
// Load drupal database config
if (isset($_REQUEST['drupal'])) {
$drupalConfig = $_REQUEST['drupal'];
}
else {
$drupalConfig = array(
"server" => "localhost",
"username" => "drupal",
"password" => "",
"database" => "drupal",
);
}
}
$loadGenerated = 0;
if (isset($_REQUEST['loadGenerated'])) {
$loadGenerated = 1;
}
require_once dirname(__FILE__) . CIVICRM_DIRECTORY_SEPARATOR . 'langs.php';
foreach ($langs as $locale => $_) {
if ($locale == 'en_US') {
continue;
}
if (!file_exists(implode(CIVICRM_DIRECTORY_SEPARATOR, array($crmPath, 'sql', "civicrm_data.$locale.mysql"))))unset($langs[$locale]);
}
$seedLanguage = 'en_US';
if (isset($_REQUEST['seedLanguage']) and isset($langs[$_REQUEST['seedLanguage']])) {
$seedLanguage = $_REQUEST['seedLanguage'];
}
global $cmsPath;
if ($installType == 'drupal') {
//CRM-6840 -don't force to install in sites/all/modules/
$object = new CRM_Utils_System_Drupal();
$cmsPath = $object->cmsRootPath();
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
$alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir . CIVICRM_DIRECTORY_SEPARATOR .
'civicrm.settings.php'
);
}
elseif ($installType == 'wordpress') {
$cmsPath = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm';
$alreadyInstalled = file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'civicrm.settings.php'
);
}
// Exit with error if CiviCRM has already been installed.
if ($alreadyInstalled) {
$errorTitle = "Oops! CiviCRM is Already Installed";
if ($installType == 'drupal') {
$errorMsg = "CiviCRM has already been installed in this Drupal site.
To start over, you must delete or rename the existing CiviCRM settings file - civicrm.settings.php - from " . implode(CIVICRM_DIRECTORY_SEPARATOR, array(
'[your Drupal root directory]', 'sites', $siteDir)) . ".
To upgrade an existing installation, refer to the online " . $docLink . ".
";
}
elseif ($installType == 'wordpress') {
$errorMsg = "CiviCRM has already been installed in this WordPress site.
To start over, you must delete or rename the existing CiviCRM settings file - civicrm.settings.php - from " . $cmsPath . ".
To upgrade an existing installation, refer to the online " . $docLink . ".
";
}
errorDisplayPage($errorTitle, $errorMsg);
}
$versionFile = $crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'civicrm-version.php';
if (file_exists($versionFile)) {
require_once ($versionFile);
$civicrm_version = civicrmVersion();
}
else {
$civicrm_version = 'unknown';
}
if ($installType == 'drupal') {
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'Drupal' &&
$civicrm_version['cms'] != 'Drupal6'
) {
$errorTitle = "Oops! Incorrect CiviCRM Version";
$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!";
errorDisplayPage($errorTitle, $errorMsg);
}
define('DRUPAL_ROOT', $cmsPath);
$drupalVersionFiles = array(
// D6
implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'modules', 'system', 'system.module')),
// D7
implode(CIVICRM_DIRECTORY_SEPARATOR, array($cmsPath, 'includes', 'bootstrap.inc')),
);
foreach ($drupalVersionFiles as $drupalVersionFile) {
if (file_exists($drupalVersionFile)) {
require_once $drupalVersionFile;
}
}
if (!defined('VERSION') or version_compare(VERSION, '6.0') < 0) {
$errorTitle = "Oops! Incorrect Drupal Version";
$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.";
errorDisplayPage($errorTitle, $errorMsg);
}
}
elseif ($installType == 'wordpress') {
//HACK for now
$civicrm_version['cms'] = 'WordPress';
// Ensure that they have downloaded the correct version of CiviCRM
if ($civicrm_version['cms'] != 'WordPress') {
$errorTitle = "Oops! Incorrect CiviCRM Version";
$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!";
errorDisplayPage($errorTitle, $errorMsg);
}
}
// Check requirements
$req = new InstallRequirements();
$req->check();
if ($req->hasErrors()) {
$hasErrorOtherThanDatabase = TRUE;
}
if ($databaseConfig) {
$dbReq = new InstallRequirements();
$dbReq->checkdatabase($databaseConfig, 'CiviCRM');
if ($installType == 'drupal') {
$dbReq->checkdatabase($drupalConfig, 'Drupal');
}
}
// Actual processor
if (isset($_REQUEST['go']) && !$req->hasErrors() && !$dbReq->hasErrors()) {
// Confirm before reinstalling
if (!isset($_REQUEST['force_reinstall']) && $alreadyInstalled) {
include ($installDirPath . 'template.html');
}
else {
$inst = new Installer();
$inst->install($_REQUEST);
}
// Show the config form
}
else {
include ($installDirPath . 'template.html');
}
/**
* This class checks requirements
* Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array
* of 3 parts:
* $description[0] - The test catetgory
* $description[1] - The test title
* $description[2] - The test error to show, if it goes wrong
*/
class InstallRequirements {
var $errors, $warnings, $tests;
// @see CRM_Upgrade_Form::MINIMUM_THREAD_STACK
const MINIMUM_THREAD_STACK = 192;
/**
* Just check that the database configuration is okay
*/
function checkdatabase($databaseConfig, $dbName) {
if ($this->requireFunction('mysql_connect',
array(
"PHP Configuration",
"MySQL support",
"MySQL support not included in PHP.",
)
)) {
$this->requireMySQLServer($databaseConfig['server'],
array(
"MySQL $dbName Configuration",
"Does the server exist",
"Can't find the a MySQL server on '$databaseConfig[server]'",
$databaseConfig['server'],
)
);
if ($this->requireMysqlConnection($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
array(
"MySQL $dbName Configuration",
"Are the access credentials correct",
"That username/password doesn't work",
)
)) {
@$this->requireMySQLVersion("5.1",
array(
"MySQL $dbName Configuration",
"MySQL version at least 5.1",
"MySQL version 5.1 or higher is required, you only have ",
"MySQL " . mysql_get_server_info(),
)
);
$this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
array(
"MySQL $dbName Configuration",
"Is auto_increment_increment set to 1",
"An auto_increment_increment value greater than 1 is not currently supported. Please see issue CRM-7923 for further details and potential workaround.",
)
);
$this->requireMySQLThreadStack($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
self::MINIMUM_THREAD_STACK,
array(
"MySQL $dbName Configuration",
"Does MySQL thread_stack meet minimum (" . self::MINIMUM_THREAD_STACK . "k)",
"", // "The MySQL thread_stack does not meet minimum " . CRM_Upgrade_Form::MINIMUM_THREAD_STACK . "k. Please update thread_stack in my.cnf.",
)
);
}
$onlyRequire = ($dbName == 'Drupal') ? TRUE : FALSE;
$this->requireDatabaseOrCreatePermissions(
$databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
"Can I access/create the database",
"I can't create new databases and the database '$databaseConfig[database]' doesn't exist",
),
$onlyRequire
);
if ($dbName != 'Drupal') {
$this->requireMySQLInnoDB($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
"Can I access/create InnoDB tables in the database",
"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.",
)
);
$this->requireMySQLTempTables($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
'Can I create temporary tables in the database',
'Unable to create temporary tables. This MySQL user is missing the CREATE TEMPORARY TABLES privilege.',
)
);
$this->requireMySQLLockTables($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
'Can I create lock tables in the database',
'Unable to lock tables. This MySQL user is missing the LOCK TABLES privilege.',
)
);
$this->requireMySQLTrigger($databaseConfig['server'],
$databaseConfig['username'],
$databaseConfig['password'],
$databaseConfig['database'],
array(
"MySQL $dbName Configuration",
'Can I create triggers in the database',
'Unable to create triggers. This MySQL user is missing the CREATE TRIGGERS privilege.',
)
);
}
}
}
/**
* Check everything except the database
*/
function check() {
global $crmPath, $installType;
$this->errors = NULL;
$this->requirePHPVersion('5.3.3', array("PHP Configuration", "PHP5 installed", NULL, "PHP version " . phpversion()));
// Check that we can identify the root folder successfully
$this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . 'README.txt',
array(
"File permissions",
"Does the webserver know where files are stored?",
"The webserver isn't letting me identify where files are stored.",
$this->getBaseDir(),
),
TRUE
);
// CRM-6485: make sure the path does not contain PATH_SEPARATOR, as we don’t know how to escape it
$this->requireNoPathSeparator(
array(
'File permissions',
'does the CiviCRM path contain PATH_SEPARATOR?',
'the ' . $this->getBaseDir() . ' path contains PATH_SEPARATOR (the ' . PATH_SEPARATOR . ' character)',
$this->getBaseDir(),
)
);
$requiredDirectories = array('CRM', 'packages', 'templates', 'js', 'api', 'i', 'sql');
foreach ($requiredDirectories as $dir) {
$this->requireFile($crmPath . CIVICRM_DIRECTORY_SEPARATOR . $dir,
array(
"File permissions", "$dir folder exists", "There is no $dir folder"), TRUE
);
}
$configIDSiniDir = NULL;
global $cmsPath;
if ($installType == 'drupal') {
$siteDir = getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']);
// make sure that we can write to sites/default and files/
$writableDirectories = array(
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir . CIVICRM_DIRECTORY_SEPARATOR .
'files',
$cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR .
$siteDir,
);
}
elseif ($installType == 'wordpress') {
// make sure that we can write to plugins/civicrm and plugins/files/
$writableDirectories = array(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'files', $cmsPath);
}
foreach ($writableDirectories as $dir) {
$dirName = CIVICRM_WINDOWS ? $dir : CIVICRM_DIRECTORY_SEPARATOR . $dir;
$this->requireWriteable($dirName,
array("File permissions", "Is the $dir folder writeable?", NULL),
TRUE
);
}
//check for Config.IDS.ini, file may exist in re-install
$configIDSiniDir = array($cmsPath, 'sites', $siteDir, 'files', 'civicrm', 'upload', 'Config.IDS.ini');
if (is_array($configIDSiniDir) && !empty($configIDSiniDir)) {
$configIDSiniFile = implode(CIVICRM_DIRECTORY_SEPARATOR, $configIDSiniDir);
if (file_exists($configIDSiniFile)) {
unlink($configIDSiniFile);
}
}
// Check for rewriting
if (isset($_SERVER['SERVER_SOFTWARE'])) {
$webserver = strip_tags(trim($_SERVER['SERVER_SOFTWARE']));
}
elseif (isset($_SERVER['SERVER_SIGNATURE'])) {
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
}
if ($webserver == '') {
$webserver = "I can't tell what webserver you are running";
}
// Check for $_SERVER configuration
$this->requireServerVariables(array('SCRIPT_NAME', 'HTTP_HOST', 'SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
// Check for MySQL support
$this->requireFunction('mysql_connect',
array("PHP Configuration", "MySQL support", "MySQL support not included in PHP.")
);
// Check for JSON support
$this->requireFunction('json_encode',
array("PHP Configuration", "JSON support", "JSON support not included in PHP.")
);
// Check for xcache_isset and emit warning if exists
$this->checkXCache(array(
"PHP Configuration",
"XCache compatibility",
"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.",
));
// Check memory allocation
$this->requireMemory(32 * 1024 * 1024,
64 * 1024 * 1024,
array(
"PHP Configuration",
"Memory allocated (PHP config option 'memory_limit')",
"CiviCRM needs a minimum of 32M allocated to PHP, but recommends 64M.",
ini_get("memory_limit"),
)
);
return $this->errors;
}
function requireMemory($min, $recommended, $testDetails) {
$this->testing($testDetails);
$mem = $this->getPHPMemory();
if ($mem < $min && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
$this->error($testDetails);
}
elseif ($mem < $recommended && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
$this->warning($testDetails);
}
elseif ($mem == 0) {
$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.";
$this->warning($testDetails);
}
}
function getPHPMemory() {
$memString = ini_get("memory_limit");
switch (strtolower(substr($memString, -1))) {
case "k":
return round(substr($memString, 0, -1) * 1024);
case "m":
return round(substr($memString, 0, -1) * 1024 * 1024);
case "g":
return round(substr($memString, 0, -1) * 1024 * 1024 * 1024);
default:
return round($memString);
}
}
function listErrors() {
if ($this->errors) {
echo "
The following problems are preventing me from installing CiviCRM:
";
foreach ($this->errors as $error) {
echo "
" . htmlentities($error) . "
";
}
}
}
function showTable($section = NULL) {
if ($section) {
$tests = $this->tests[$section];
echo "
Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you review these permissions to ensure that they are appropriate for your requirements (learn more...)
Have you registered this site at CiviCRM.org? If not, please help strengthen the CiviCRM ecosystem by taking a few minutes to fill out the site registration form. 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).
We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.
";
// automatically enable CiviCRM module once it is installed successfully.
// so we need to Bootstrap Drupal, so that we can call drupal hooks.
global $cmsPath, $crmPath;
// relative / abosolute paths are not working for drupal, hence using chdir()
chdir($cmsPath);
include_once "./includes/bootstrap.inc";
include_once "./includes/unicode.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// prevent session information from being saved.
drupal_save_session(FALSE);
// Force the current user to anonymous.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
// explicitly setting error reporting, since we cannot handle drupal related notices
error_reporting(1);
// rebuild modules, so that civicrm is added
system_rebuild_module_data();
// now enable civicrm module.
module_enable(array('civicrm', 'civicrmtheme'));
// clear block, page, theme, and hook caches
drupal_flush_all_caches();
//add basic drupal permissions
civicrm_install_set_drupal_perms();
// restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
$output .= '
Drupal user permissions have been automatically set - giving anonymous and authenticated users access to public CiviCRM forms and features. We recommend that you review these permissions to ensure that they are appropriate for your requirements (learn more...)
Have you registered this site at CiviCRM.org? If not, please help strengthen the CiviCRM ecosystem by taking a few minutes to fill out the site registration form. 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).
We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.
";
// explicitly setting error reporting, since we cannot handle drupal related notices
error_reporting(1);
// automatically enable CiviCRM module once it is installed successfully.
// so we need to Bootstrap Drupal, so that we can call drupal hooks.
global $cmsPath, $crmPath;
// relative / abosolute paths are not working for drupal, hence using chdir()
chdir($cmsPath);
include_once "./includes/bootstrap.inc";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// rebuild modules, so that civicrm is added
module_rebuild_cache();
// now enable civicrm module.
module_enable(array('civicrm'));
// clear block, page, theme, and hook caches
drupal_flush_all_caches();
//add basic drupal permissions
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)');
echo $output;
}
elseif ($installType == 'wordpress') {
echo '
CiviCRM Installed
';
echo '
CiviCRM has been successfully installed
';
echo '
';
$docLinkConfig = CRM_Utils_System::docURL2('Configuring a New Site', FALSE, 'here',NULL,NULL,"wiki");
if (!function_exists('ts')) {
$docLinkConfig = "here";
}
$cmsURL = civicrm_cms_base();
$cmsURL .= "wp-admin/admin.php?page=CiviCRM&q=civicrm/admin/configtask&reset=1";
$registerSiteURL = "http://civicrm.org/civicrm/profile/create?reset=1&gid=15";
echo "
Have you registered this site at CiviCRM.org? If not, please help strengthen the CiviCRM ecosystem by taking a few minutes to fill out the site registration form. 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).
We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.
";
echo '
';
echo '
';
}
}
return $this->errors;
}
}
function civicrm_install_set_drupal_perms() {
if (!function_exists('db_select')) {
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)');
}
else {
$perms = array(
'access all custom data',
'access uploaded files',
'make online contributions',
'profile create',
'profile edit',
'profile view',
'register for events',
'view event info',
'view event participants',
'access CiviMail subscribe/unsubscribe pages',
);
// Adding a permission that has not yet been assigned to a module by
// a hook_permission implementation results in a database error.
// CRM-9042
$allPerms = array_keys(module_invoke_all('permission'));
foreach (array_diff($perms, $allPerms) as $perm) {
watchdog('civicrm',
'Cannot grant the %perm permission because it does not yet exist.',
array(
'%perm' => $perm), WATCHDOG_ERROR
);
}
$perms = array_intersect($perms, $allPerms);
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $perms);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, $perms);
}
}
function getSiteDir($cmsPath, $str) {
static $siteDir = '';
if ($siteDir) {
return $siteDir;
}
$sites = CIVICRM_DIRECTORY_SEPARATOR . 'sites' . CIVICRM_DIRECTORY_SEPARATOR;
$modules = CIVICRM_DIRECTORY_SEPARATOR . 'modules' . CIVICRM_DIRECTORY_SEPARATOR;
preg_match("/" . preg_quote($sites, CIVICRM_DIRECTORY_SEPARATOR) .
"([\-a-zA-Z0-9_.]+)" .
preg_quote($modules, CIVICRM_DIRECTORY_SEPARATOR) . "/",
$_SERVER['SCRIPT_FILENAME'], $matches
);
$siteDir = isset($matches[1]) ? $matches[1] : 'default';
if (strtolower($siteDir) == 'all') {
// For this case - use drupal's way of finding out multi-site directory
$uri = explode(CIVICRM_DIRECTORY_SEPARATOR, $_SERVER['SCRIPT_FILENAME']);
$server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
for ($i = count($uri) - 1; $i > 0; $i--) {
for ($j = count($server); $j > 0; $j--) {
$dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i));
if (file_exists($cmsPath . CIVICRM_DIRECTORY_SEPARATOR .
'sites' . CIVICRM_DIRECTORY_SEPARATOR . $dir
)) {
$siteDir = $dir;
return $siteDir;
}
}
}
$siteDir = 'default';
}
return $siteDir;
}
function errorDisplayPage($errorTitle, $errorMsg) {
include ('error.html');
exit();
}