另一种SuiteCRM安装方法

SuiteCRM安装
SuiteCRM安装

您可能偶尔需要通过一些自动化过程来安装SuiteCRM。SuiteCRM提供了一种进行“静默”安装的方法,当给定包含某些安装详细信息的config_si.php文件时,它将执行安装。涉及的步骤非常简单。首先,我们在SuiteCRM根目录中创建一个config_si.php文件:

<?php
$sugar_config_si  = array (
    'dbUSRData' => 'create',
    'default_currency_iso4217' => 'USD',
    'default_currency_name' => 'US Dollar',
    'default_currency_significant_digits' => '2',
    'default_currency_symbol' => '$',
    'default_date_format' => 'Y-m-d',
    'default_decimal_seperator' => '.',
    'default_export_charset' => 'ISO-8859-1',
    'default_language' => 'en_us',
    'default_locale_name_format' => 's f l',
    'default_number_grouping_seperator' => ',',
    'default_time_format' => 'H:i',
    'export_delimiter' => ',',
    'setup_db_admin_password' => 'DB Password',
    'setup_db_admin_user_name' => 'DB Username',
    'setup_db_create_database' => 1,
    'setup_db_database_name' => 'DB Name',
    'setup_db_drop_tables' => 0,
    'setup_db_host_name' => 'DB Host',
    'setup_db_pop_demo_data' => false,
    'setup_db_type' => 'mysql',
    'setup_db_username_is_privileged' => true,
    'setup_site_admin_password' => 'Admin Password',
    'setup_site_admin_user_name' => 'Admin username',
    'setup_site_url' => 'Site URL',
    'setup_system_name' => 'Site Name',
  );

其中应包含适当的数据库凭据以及新的SuiteCRM安装站点url,管理员用户名等。例如,如果您转到适当的SuiteCRM位置,则将该文件放置在适当的位置

example.com/install.php?goto=SilentInstall&cli=true对于命令行或example.com/install.php?goto=SilentInstall在浏览器中使用,则SuiteCRM将执行独立安装。或者,您也可以在终端中调用以下命令:

php -r "$_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['REQUEST_URI'] = 'install.php';$_REQUEST = array('goto' => 'SilentInstall', 'cli' => true);require_once 'install.php';";

以下脚本采用必需的参数,包括未压缩的SuiteCRM软件包的位置,并将创建必要的配置文件并运行安装:

<?php

/*
 * php suitecrmsilentinstall.php --install_location /var/www/html/suitecrmpath --db_host localhost --db_user dbuser --db_pass dbpass --db_name dbname --site_username admin --site_pass password --site_host example.com --site_name "SuiteCRM Silent Install"
 */
$args = getArguments();
createConfigFile($args);
$url = "http://".$args['site_host']."/install.php?goto=SilentInstall&cli=true";
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$results = curl_exec($ch);
$matches = array();
preg_match("/<bottle>(.*)<\/bottle>/s",$results,$matches);
echo "Install message was: ".$matches[1]."\n";

function getCLIArguments(){
  return getopt("",array("install_location:","db_host:","db_user:","db_pass:","db_name:","site_username:","site_pass:","site_host:","site_name:"));
}

function getArguments(){
  return getCLIArguments();
}

function createConfigFile($args){
    $installLoc = $args['install_location'];
    $config = createConfigArray($args);
    $contents = '<?php'."\n".'$sugar_config_si = '.var_export($config,1).";\n";
    file_put_contents($installLoc.'/config_si.php',$contents);
}

function createConfigArray($args){
  $dbUser = $args['db_user'];
  $dbPass = $args['db_pass'];
  $dbName = $args['db_name'];
  $dbHost = $args['db_host'];
  $siteUserName = $args['site_username'];
  $siteUserPass = $args['site_pass'];
  $siteHost = $args['site_host'];
  $siteName = $args['site_name'];
  $configArr = array (
    'dbUSRData' => 'create',
    'default_currency_iso4217' => 'USD',
    'default_currency_name' => 'US Dollar',
    'default_currency_significant_digits' => '2',
    'default_currency_symbol' => '$',
    'default_date_format' => 'Y-m-d',
    'default_decimal_seperator' => '.',
    'default_export_charset' => 'ISO-8859-1',
    'default_language' => 'en_us',
    'default_locale_name_format' => 's f l',
    'default_number_grouping_seperator' => ',',
    'default_time_format' => 'H:i',
    'export_delimiter' => ',',
    'setup_db_admin_password' => $dbPass,
    'setup_db_admin_user_name' => $dbUser,
    'setup_db_create_database' => 1,
    'setup_db_database_name' => $dbName,
    'setup_db_drop_tables' => 0,
    'setup_db_host_name' => $dbHost,
    'setup_db_pop_demo_data' => false,
    'setup_db_type' => 'mysql',
    'setup_db_username_is_privileged' => true,
    'setup_site_admin_password' => $siteUserPass,
    'setup_site_admin_user_name' => $siteUserName,
    'setup_site_url' => $siteHost,
    'setup_system_name' => $siteName,
  );
  return $configArr;
}

与往常一样,您应该始终在运行在Internet上找到的代码之前进行备份。

滚动至顶部
扫码添加微信联系我们 关闭