系統環境:
官方教學:
SugarCRM 6.x 必須安裝在 PHP 5.3+ 的環境,所以請先將 PHP 升級到 5.3,可參閱此篇 CentOS 5.5 升級至 PHP 5.3。
不要使用 PHP 5.2,此版本會使 SugarCRM 無法順利完成安裝。
http://www.sugarforge.org/frs/?group_id=6
wget http://www.sugarforge.org/frs/download.php/9248/SugarCE-6.5.0.zip unzip SugarCE-6.5.0.zip mv SugarCE-Full-6.5.0 /var/www/html/sugarcrm650
變更目錄權現
cd /var/www/html/sugarcrm650/ chown -R root:asterisk cache/ custom/ modules/ upload/ config.php config_override.php sugarcrm.log chmod 0775 -R cache/ custom/ modules/ upload/ config.php config_override.php sugarcrm.log
NOTE:
Group asterisk 是指 apache 所執行的的 group name。
修改 php.ini
upload_max_filesize = 20M memory_limit = 256M
前往 http://<server.ip>/<sugarcrm directory>/install.php。
安裝重點提示:
Database Configuration
Databas Name: sugarcrm
Host Name: localhost
Database Administrator Username: root
Database Administrator Password: <管理員密碼>
Sugar Database Name: Define user to create
Sugar Database Username: sugar
Sugar Database User Password: sugarpass
Re-enter Sugar Database User Password: sugarpass
Site Configuration
Sugar Application Admin Name: admin
Sugar Admin User Password: 登入密碼
Re-eneter Sugar Admin User Password: 登入密碼
安裝完成後,還需要做以下步驟
編輯 <sugarcrm 根目錄>/.htaccess
# BEGIN SUGARCRM RESTRICTIONS RedirectMatch 403 (?i)^.*\.log$ RedirectMatch 403 (?i)/+not_imported_.*\.txt RedirectMatch 403 (?i)/+(soap|cache|xtemplate|data|examples|include|log4php|metadata|modules)/+.*\.(php|tpl) RedirectMatch 403 (?i)/+emailmandelivery\.php RedirectMatch 403 (?i)/+cache/+upload # END SUGARCRM RESTRICTIONS
新增 cron jib
crontab -e -u asterisk
* * * * * cd /var/www/html/sugarcrm650 && /usr/bin/php -f cron.php 2>&1
TIPs:
asterisk 是指 apache 的用戶名稱
有關 cron 的用途,請參閱 http://support.sugarcrm.com/04_Find_...bout_Cron_Jobs
功能測試
系統需求
TIPs
如何檢查 Asterisk Manager 版本?
執行 telnet localhost 5038Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Asterisk Call Manager/1.1
Step1:使用 Module Loader 安裝 Yaai
SugarCRM > Admin(右上角) > Administration > Module Loader > 選擇 *.zip 檔
Step2:編輯 /etc/asterisk/manager.conf
[dialog] secret = dialog deny = 0.0.0.0/0.0.0.0 permit = 127.0.0.1/255.255.255.0 read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
Step3:複製 asteriskLogger.php
將下載的 zip 檔解壓後
cd misc/asteriskLogger_v6.1_AMIv1.1.php <sugarcrm>/custom/modules/Asterisk cd <sugarcrm>/custom/modules/Asterisk mv asteriskLogger.php asteriskLogger.php.default mv asteriskLogger_v6.1_AMIv1.1.php asteriskLogger.php
Step4:建立 asteriskLogger.php 的啟動檔
/usr/local/bin/asterisk_Logger-start
#!/bin/bash ### # quick and dirty start stop script # Parts of this code are (c) 2009 abcona e. K. Angelo Malaguarnera E-Mail admin@abcona.de # http://www.sugarforge.org/projects/yaai/ # gnu public licence # ### ### # modified by alang 2012/6/25 # ### # Please edit this for your environment path=/var/www/html/sugarcrm650/custom/modules/Asterisk pid_file=/var/run/asterisk_Logger.pid ### finish to edit :-) start() { KIND="asteriskLogger" echo -n "Starting $KIND services: " # Checking if it's already running if [ -r $pid_file ]; then pid="$(cat $pid_file)" if [ "$(ps -ef | grep $pid | grep -v grep)" ]; then echo " Running" echo "The process ID is $pid" echo exit fi fi cd $path php asteriskLogger.php >> /var/log/asterisklogger& if [ $? -eq 0 ]; then pid="$!" echo " Done" echo "The process ID is $pid" echo "$pid" > $pid_file echo else echo " failed" echo fi } stop() { KIND="asterisklogger" echo -n $"Shutting down $KIND services: " if [ -r $pid_file ]; then pid=`cat $pid_file` kill $pid [ $? -eq 0 ] && echo " Done" rm $pid_file echo exit fi echo " failed" echo } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: $0 {start|stop|restart}" exit 2 esac exit $?
將開機啟動的指令寫在 /etc/rc.local
Ans: 檢查 /etc/php.init 的參數 session.save_path 所設定的目錄,是否可讓 apache 寫入。
Ans: 使用 yum 安裝缺少的模組
yum install php-mbstring
TIPs:
如果 php 5.3 是由 php 5.1 升級上來的,必須要再加上 --enablerepo=<套件庫名稱>,否則會出現套件衝突的錯誤訊息。
Ans: 檢查網頁檔目錄內的 upload 目錄是否有 apache 可寫入的權限。
Fetching FreePBX settings with gen_amp_conf.php..
PHP Fatal error: Call to undefined function posix_getpwuid() in /var/lib/asterisk/bin/gen_amp_conf.php on line 3
Ans:這是因為升級 php 5.3 後,某個 php 模組被移除了,使用以下指令安裝
yum --enablerepo=remi install php-posix 或 yum --enablerepo=remi install php-process
錯誤:
! Error 0 connecting to Asterisk: Failed to parse address ""PHP Warning: fsockopen(): unable to connect to :0 (Failed to parse address "") in /var/www/html/sugarcrm650/custom/modules/Asterisk/asteriskLogger.php on line 231
Ans:檢查 SurgarCRM 的 Asterisk Configuration 是否與 manager.conf 的內容相符,如果是第一次安裝,請在 Asterisk Configuration 的表單上做一次儲存。
錯誤:
PHP Warning: Attempt to modify property of non-object in /var/www/html/sugarcrm650/include/nusoap/nusoap.php on line 6160
Ans:這是 nusoap 在 PHP 5.3 的 bug,以下步驟可解
編輯 <sugarcrm>/include/nusoap/class.wsdl.php
搜尋 Schema imports
... // Schema imports foreach ($this->schemas as $ns => $list) { // fixed for PHP5.3 by alang //foreach ($list as $xs) { foreach ($list as $ilist => $xs) { ... ... if (! $list2[$ii]['loaded']) { // fixed for PHP5.3 by alang //$this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true; $this->schemas[$ns][$ilist]->imports[$ns2][$ii]['loaded'] = true; ...
編輯 <sugarcrm>/include/nusoap/nusoap.php
搜尋 Schema imports
... // Schema imports foreach ($this->schemas as $ns => $list) { // fixed for PHP5.3 by alang //foreach ($list as $xs) { foreach ($list as $ilist => $xs) { ... ... if (! $list2[$ii]['loaded']) { // fixed for PHP5.3 by alang //$this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true; $this->schemas[$ns][$ilist]->imports[$ns2][$ii]['loaded'] = true; ...
[FATAL] Configuration variable date.timezone is not set, guessed timezone Asia/Chongqing. Please set date.timezone="Asia/Chongqing" in php.ini!
Ans:修改 /etc/php.ini,重啟 apache 服務。
date.timezone = Asia/Taipei
Call Record ID returned from server is -1, unable to save call notes for 0702500267 - 'Ringing'
Ans:這是因為 Sugar 6.5.0 的密碼編碼改成 crypt(md5('yourpassword'),而 SOAP 僅支援 md5 編碼,所以 SOAP 認證始終失敗,解決方式是稍微修改 asteriskLogger.php。
asteriskLogger.php:
... // Get SOAP config $sugarSoapEndpoint = $sugar_config['site_url'] . "/soap.php"; $sugarSoapUser = $sugar_config['asterisk_soapuser']; $sugarSoapCredential = ""; { $sql = "select user_hash from users where user_name='$sugarSoapUser'"; $sqlResult = mysql_query($sql); if ($sqlResult) { $rowData = mysql_fetch_assoc($sqlResult); $sugarSoapCredential = $rowData['user_hash']; } else { echo "! FATAL: Cannot find login credentials for user $sugarSoapUser\n"; die(); } } // fixed for SugarCRM 650 by alang // Below is the username/password for SOAP connection $SOAP_USER="admin"; $SOAP_PASS="osslab"; $sugarSoapUser=$SOAP_USER; $sugarSoapCredential = md5($SOAP_PASS); // // And finally open a SOAP connection to SugarCRM // ...
NOTEs:
SOAP_USER, SOAP_PASS 是 SugarCRM 的任一個用戶帳號/密碼。
Ans:建立一個 test.php
test.php:
<?php define('sugarEntry', TRUE); require_once('/var/www/html/sugarcrm650/include/nusoap/nusoap.php'); $soap_username='admin'; $soap_password='yourpass'; $myWsdl = 'http://192.168.7.76/sugarcrm650/soap.php?wsdl'; $myAuth = array( 'user_name' => $soap_username, 'password' => md5($soap_password), ); $soapClient = new nusoap_client($myWsdl,true); $loginParams = array('user_auth' => $myAuth); $loginResult = $soapClient->call('login', $loginParams); $sessionId = $loginResult['id']; echo "[SESSIONID]= ".$sessionId ."\n"; echo "[Encrypted PASS]= ".$myAuth['password']."\n"; ?>
TIPs:
修改 soap_username, soap_password, myWsdl 路徑
修改 require_once 路徑