ads2

Tuesday, 15 January 2013

SugarCRM Install on Redhat Enterprise Linux


This install procedure was tested using the Redhat Enterprise Linux distribution known as CentOS.
Software used:
Linux commands executed at a command prompt are in courier font.
Let's get started
If you are installing Linux from scratch using Anaconda via install CD select "basic server" and proceed with the install which will install with no groups.   Skip down to the yum -y update part.
Otherwise, it is assumed you already have a server with a base CentOS installation before you begin.  Do NOT install a GUI such as Gnome or KDE.  We only want to be running in console text mode not GUI graphics mode.  If you already have a desktop or server GUI installed you will want to exit to console mode.  You do that by typing init 3 from a terminal or console window.  You will need to be logged in as root in order to do this so if not you can su root.  All instructions in this guide are assuming you are always logged in as root.
Get rid of all installed groups except 'Yum Utilities' so we are starting with a clean slate.  Check the delete list before entering 'y' to make sure none of these remove 'sshd' or 'yum' (they don't but check just in case things change with newer revisions).
yum grouplist installed
Installed Groups:
   DNS Name Server
   Editors
   Legacy Network Server
   Mail Server
   Network Servers
   System Tools
   Text-based Internet
   Web Server
   Windows File Server
   Yum Utilities
yum groupremove 'DNS Name Server'
yum groupremove 'Editors'
yum groupremove 'Legacy Network Server'
yum groupremove 'Mail Server'
yum groupremove 'Network Servers'
yum groupremove 'System Tools'
yum groupremove 'Text-based Internet'
yum groupremove 'Web Server'
yum groupremove 'Windows File Server'
Now update the base install
yum -y update
Install the basic set of packages required for a linux server.
yum -y groupinstall core
yum -y groupinstall base
Install required packages for sugarcrm install and nano editor.
yum -y install php php-pear php-mbstring mysql-server php-mysql httpd nano
Set mysql and apache to start on boot then start them.
chkconfig httpd on
chkconfig mysqld on
service httpd start
service mysqld start
Selinux is not required or recommended.  This will create the required file if it does not already exist.  If it already exists copy paste or edit the contents indicated here to be sure selinux never runs.
nano /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0


(Ctrl-x> y >Enter)
Make sure selinux is turned off for this session
setenforce 0
RHEL v5 Section:
If using RHEL v6 skip over this section
SugarCRM currently requires PHP v5.2 at a minimum.  RHEL v5 comes with php v5.1.  We can find php v5.2 in the testing repository.  If running RHEL v6 we would have PHP v5.3 and shouldn't have to do this.

cd /etc/yum.repos.d/
wget http://dev.centos.org/centos/5/CentOS-Testing.repo
yum -y --enablerepo=c5-testing update php*


Restart httpd for the new version of php to take effect
service httpd restart

verify we are now running php v5.2
php -v
On RHEL 5 shutdown unnecessary daemon brcm-iscsi which is enabled by default and tends to do a lot of logging even when not used. This creates unnecessary I/O load.
chkconfig iscsi off
chkconfig iscsid off
service iscsi stop
service iscsid stop
Replace syslog with the improved and backwards compatible rsyslog (standard in RHEL6 but not RHEL5).  This also prevents a problem that comes up with improper timestamps in /var/log/secure when you get disconnects. 
NOTE:This is only for RHEL5 based systems.  You do not need to do this for RHEL6.
yum -y install rsyslog
chkconfig syslog off
chkconfig rsyslog on
service syslog stop
service rsyslog start
End of RHEL v5 Section-------------

Set Timezone
Copy your timezone from this link.
System timezone
Create a symbolic link to the appropriate timezone from /etc/localtime.
Example:
ln -sf /usr/share/zoneinfo/America/Vancouver /etc/localtime
PHP timezone
for RHEL5:
nano +633 /etc/php.ini
for RHEL6
nano +946 /etc/php.ini
Uncomment (;) date.timezone = and add your timezone.  For example:
date.timezone = America/Vancouver

Restart apache for the changes to take effect.
service httpd restart
MySQL security enhancement
This will prevent outside IP's from connecting to the MySQL port
nano /etc/my.cnf
[mysqld]
.
.
.
bind-address = 127.0.0.1
(Ctl-x > y > ENTER)
MySQL performance tuning for low memory (optional)
This will reduce memory usage significantly without affecting performance.  RHEL 6 does not include bdb so do not add the skip-bdb line.
nano /etc/my.cnf
[mysqld]
.
.
.
skip-innodb
skip-bdb
(Ctl-x > y > ENTER)
Restart service for the changes to take effect
service mysqld restart
Improving SugarCRM Performance
Using this sugarcrm performance tutorial as a reference and the 2 most important suggestions.
MySQL optimization
Note:  If you have already set mysql root password use mysql -p instead of mysql

mysql

mysql> SHOW VARIABLES LIKE "query_cache%";

If query_cache_type is set to something other than “ON” or query_cache_size is set to 0, you will want to change these! 32MB is a fine start, but depending on your workload you may need (a lot) more to get the full benefit from this:

mysql> SET GLOBAL query_cache_type = 'ON';
mysql> SET GLOBAL query_cache_size = 32000000;
mysql> \q

This one change can make a significant difference in mysql performance when running SugarCRM.  After some time has passed and some usage taken place you can check the status of this optimization as follows:

mysql> SHOW STATUS LIKE "Qcache%";

The two numbers to pay the most attention to are free_memory and lowmem_prunes.  If free_memory is approaching 0 and lowmem_prunes keeps increasing that means you should probably increase the query_cache_size.
PHP Performance optimization
Perhaps the single biggest perfomance enhancement that you can make for SugarCRM and many other PHP applications is OpCode Caching.  One of the ways of doing this is by installing Alternative PHP Cache otherwise known as APC.  For php v5.2, php-pecl-apc-3.0.19 from one of the 3rd party archives is the version we need.

For RHEL 5
rpm -ivh http://rpms.famillecollet.com/enterprise/5/olds/i386/php-pecl-apc-3.0.19-1.el5.remi.i386.rpm
The 64bit version can be found at the same domain replacing "i386" with "x86_64".
For RHEL 6 the package is already included in the repositories
yum -y install php-pecl-apc
Configuration is done in /etc/php.d/apc.ini.  The defaults should be fine for now.  To monitor this optimization after some time has passed copy the apc.php file to your webroot and view it on a browser.
cp /usr/share/doc/php-pecl-apc*/apc.php /var/www/html

then from a web browser go to http://myserverIP/apc.php

On the left hand side compare File Cache Information>Hits with Cache full count.  Over time you want Hits vs Cache Full count to be at least 98%.   Same thing with the Hits & Misses graph on the right.  If it's lower than this you will probably benefit from increasing apc.shm_size in /etc/php.d/apc.ini.  Remember to issue service httpd restart in order for the changes to take effect.  Wait for memory usage to reach 100% or to stay steady over a period of time before making this measurement.
SugarCRM Install

Using this SugarCRM install guide as a reference.

RHEL 5
nano +302 /etc/php.ini
RHEL  6
nano +457 /etc/php.ini

memory_limit = 128M
(Ctl-x > y > ENTER)
RHEL 5
nano +573 /etc/php.ini

RHEL 6
nano +878 /etc/php.ini

upload_max_filesize = 20M
(Ctl-x > y > ENTER)
RHEL 5
nano +327 /etc/httpd/conf/httpd.conf

RHEL 6
nano +338 /etc/httpd/conf/httpd.conf

AllowOverride All
(Ctl-x > y > ENTER)

Make the changes take effect.
service httpd restart
Download and unpack sugarcrm and rename it "crm" (or whatever you want to call the webroot directory)
cd /var/www/html
wget http://www.sugarforge.org/frs/download.php/8724/SugarCE-6.3.1.zip
unzip SugarCE-6.3.1.zip
mv SugarCE-Full-6.3.1 crm
Set ownership and permissions
This is an important step that has to be correct in order for the install to work and for sugarcrm to run correctly.  User and group ownership needs to be set to whatever user and group ownership are set to in Apache.

If unsure what Apache user/group ownership is set to:
RHEL 5
nano -v +231 /etc/httpd/conf/httpd.conf
RHEL 6
nano -v +242 /etc/httpd/conf/httpd.conf

Default is "apache".  You can set it to whatever you want as long as you make the sugarcrm folders the same.  We are going to keep the defaults in this procedure. The "-R" means that in addition to the root folder we are going to recursively set all subfolders and all files in those folders as well.
chown -R apache:apache /var/www/html/crm

SugarCRM recommends permissions set to 755
chmod -R 755 /var/www/html/crm
Before running the install we should set mysql root password.  This is the database administrator password that the sugarcrm installer will ask for so it can create the sugarcrm database.
For this example we are making the password somepassword.
mysqladmin -u root password 'somepassword'
Now run the sugarcrm setup wizard from a webbrowser replacing serverIP with the IP address of your server.
http://ServerIP/crm/install.php
When you get to the database configuration screen you can leave database name at default
Database Name = sugarcrm

Assuming you have followed this guide and are therefore installing sugarcrm on the same machine as the database:
Host Name = localhost

Change password to whatever you used when setting mysql root password above.
Database Administrator Username = root
Database Administrator password = somepassword
Sugar Database Username.   Probably best to define a user.
Sugar Database Username = someusername
Sugar Database password = someotherpassword
Choose Demo Data.  If you are new to sugarcrm and want to see what it looks like with typical data choose yes.  You can delete the data later.  Otherwise choose no.
After you log in the first time you should see a confirm settings page.  Check for any errors or warnings and modify as necessary.  If you don't have IMAP installed you will get a warning which should explain that it is required for inbound email campaigns only.  Remember to restart httpd for any changes to /etc/php.ini to take effect.
Lastly, setup crontab schedule as explained at the bottom of the confirm settings page.

First change default editor to nano then add the cron job.
export EDITOR=nano
crontab -e
*  *  *  *  *   cd /var/www/html/crm; php -f cron.php > /dev/null 2>&1
You can verify it was added by checking:
nano -v /var/spool/cron/root

It's best to use the crontab -e command to edit this file.  Editing directly is not recommended
Press install.  
The rest of the settings from here on are self explanatory GUI based administrator level.  Make sure to complete them before exiting otherwise ownership isn't set correctly for the theme and cache folder which gets created at the very end.  If that happens you will see strange formatting on your screen with things scattered all over the place.  
If you find yourself with this problem or with a problem of the screen being blank after logging in then try the chown -Rcommand above once again.

No comments:

Post a Comment