Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, 29 December 2013

How to write shell script

Following steps are required to write shell script:
(1) Use any editor like vi or mcedit to write shell script.
(2) After writing shell script set execute permission for your script as follows
syntax: 
chmod permission your-script-name
Examples:
$ chmod +x your-script-name
$ chmod 755 your-script-name
Note: This will set read write execute(7) permission for owner, for group and other permission is read and execute only(5).
(3) Execute your script as
syntax: 
bash your-script-name
sh your-script-name
./your-script-name
Examples:
$ bash bar
$ sh bar
$ ./bar
NOTE In the last syntax ./ means current directory, But only . (dot) means execute given command file in current shell without starting the new copy of shell, The syntax for . (dot) command is as follows
Syntax:
. command-name

Example:
$ . foo
Now you are ready to write first shell script that will print "Knowledge is Power" on screen. See the common vi command list , if you are new to vi.
$ vi first
#
# My first shell script
#
clear
echo "Knowledge is Power"
After saving the above script, you can run the script as follows:
$ ./first
This will not run script since we have not set execute permission for our script first; to do this type command
$ chmod 755 first
$ ./first
First screen will be clear, then Knowledge is Power is printed on screen.
Script Command(s)
Meaning
$ vi firstStart vi editor
#
# My first shell script
#
# followed by any text is considered as comment. Comment gives more information about script, logical explanation about shell script.
Syntax:
# comment-text
clearclear the screen
echo "Knowledge is Power"To print message or value of variables on screen, we use echo command, general form of echo command is as follows
syntax: 
echo "Message"
 How Shell Locates the file (My own bin directory to execute script)
Tip: For shell script file try to give file extension such as .sh, which can be easily identified by you as shell script.
Exercise:
1)Write following shell script, save it, execute it and note down the it's output.
$ vi ginfo
#
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit 0

Variables in Shell

Variables in Shell

To process our data/information, data must be kept in computers RAM memory. RAM memory is divided into small locations, and each location had unique number called memory location/address, which is used to hold our data. Programmer can give a unique name to this memory location/address called memory variable or variable (Its a named storage location that may take different values, but only one at a time).
In Linux (Shell), there are two types of variable:
(1) System variables - Created and maintained by Linux itself. This type of variable defined in CAPITAL LETTERS.
(2) User defined variables (UDV) - Created and maintained by user. This type of variable defined in lower letters.
You can see system variables by giving command like $ set, some of the important System variables are:
System Variable
Meaning
BASH=/bin/bashOur shell name
BASH_VERSION=1.14.7(1)Our shell version name
COLUMNS=80No. of columns for our screen
HOME=/home/vivekOur home directory
LINES=25No. of columns for our screen
LOGNAME=studentsstudents Our logging name
OSTYPE=LinuxOur Os type
PATH=/usr/bin:/sbin:/bin:/usr/sbinOur path settings
PS1=[\u@\h \W]\$Our prompt settings
PWD=/home/students/CommonOur current working directory
SHELL=/bin/bashOur shell name
USERNAME=vivekUser name who is currently login to this PC
NOTE that Some of the above settings can be different in your PC/Linux environment. You can print any of
the above variables contains as follows:

$ echo $USERNAME
$ echo $HOME

Exercise:
1) If you want to print your home directory location then you give command:
a)$ echo $HOME
OR
(b)$ echo HOME
Which of the above command is correct & why? Click here for answer.
Caution: Do not modify System variable this can some time create problems.

Install Centos

[1]Insert Install media and restart Computer. After booting, following screen is shown, then Push Enter key.
[2]This is the section to check a media, Skip it if you don't need it.
[3]Click "Next" button to proceed.
[4]Select the language you'd like to use during the installation.
[5]Select the keyboard type you using.
[6]Select the type of storage. If you install CentOS 6 to local HD, select 'Basic Storage Devices'. If you install to HD that is connected in storage network area or mainframe, select the bottom.
[7]If your HD is new one and not formatted, following warning is shown, Click "Re-initialize all" if it's OK.
[8]Set a Hostname of your computer.
[9]Set your timezone.
[10]Set root user's password.
[11]Select installation type as follows. On this example, select "Use All Space" and check a box "Review and modify partitioning layout" to configure partitions manually.
[12]This is the section for changing partition layouts. This example shows to configure LVM partition layouts (Set /boot, /. swap, /home on here) . First, select "/" and Click "Edit" button.
[13]Reduce the volume size for "/" to make free areas.
[14]Click "Create" button, then following screen is shown, Select "LVM Logical Volume" and Click "Create".
[15]Input mount point, logical volume's name, size and so on.
[16]Click "Next" button if it's OK all.
[17]Click 'Format' if it's OK all.
[18]Click 'Write Changes to Disk' if it's OK all.
[19]Click 'Next' button with keeping default. If you set some parameters for bootloader, Configure it.
[20]Select softwares to install. Select 'Minimal' and go next. It's unnecessarry to install many packages at first. But if you are beginer on Linux system, check a box 'Customize now' and Install additional packages because it's inconvenience if only 'Minimal' is installed.
[21]If you selected "Customize now" at previous section, following screen is shown. It's better to check a box "Base" if you are beginer.
[22]Installation starts.
[23]Installation completed. Click "Reboot" button.

Linux Timeline

Linux.org presented one of the most detailed important events in the history of the Linux operating system development
1983
September    Richard M. Stallman announces the GNU Project, an attempt at creating a completely free operating system.
1984
January    Work begins on the GNU operating system
1985
October    Free Software Foundation established as a non-profit organization to promote the development of Free Software. Sponsors the GNU Project.
1987
January    Computer science professor Andrew Tannenbaum publishes the textbook Operating Systems: Design and Implementation which includes a copy of a teaching version of Unix called Minix.

December    Larry Wall releases version 1.0 of Perl
1989
February    Version 1 of the GNU General Public License (GPL) is released.

1991
June    Version 2 of the GNU General Public License (GPL) is released.
August    Linus Torvalds announces that he’s working on an operating system similar to Minix.
October    Richard Stallman expresses interest in having the Free Software Foundation distribute a GNU system with the Linux kernel.
September    Version 0.01 of Torvald’s project is made available via ftp.funet.fi. Ari Lemmke, the systems administrator, gives the directory the name Linux.
December    Robert Blum posts the first Linux FAQ
1992
January    alt.os.linux newsgroup created.
Minix creator Andrew Tannenbaum claims “Linux is obsolete” in a posting to comp.os.minix and starts a public discussion on the merits of Linux in which Linus Torvalds participates.
February    What could be described as the first Linux “distribution”, called MCC Interim Linux is released by the University of Manchester, England.
March    Version 0.95 of the Linux kernel released. First version to be able to support X-Window.
September    A Linux distribution called Softlanding Linux System (SLS) is released. Early users include Patrick Volkerding and Ian Murdock.
November    Software und System Entwicklung GmbH (SuSE) founded in Nuremberg, Germany. Distributes a German version of SLS with corresponding manuals.
1993
March    Matt Welsh issues the Linux Documentation Project Manifesto. He states that the goal of the LDP is to “collaborate in taking care of all of the issues of Linux documentation”.
August    Ian Murdock creates the Debian distribution.
August    Version 1.0 of Slackware released by Patrick Volkerding. It is based on the SLS distribution.
1994
March    Linux kernel version 1.0 released.
First issue of Linux Journal published
April    Version 1.0 of SuSE Linux released. It is based on SLS.
May    Michael McLagan registers the linux.org domain.
June    Jon ‘maddog’ Hall founds Linux International
Rasmus Lerdorf releases the first version of the PHP scripting language.
September    William R. Della Croce, Jr. of Boston, Massachusetts registers the Linux trademark. He begins, shortly thereafter, to ask for compensation for the use of the word Linux.
October    Marc Ewing releases the first version of Red Hat Linux.
Linux distributor Caldera founded by Ray Noorda of Novell and Ransom Love.
1995
March Bob Young partners with Marc Ewing and forms Red Hat Software.
Apache web server project started as a series of patches to the NCSA HTTPd server (a patchy server).
1996
March    Linux kernel version 2.0 released.
May    Linus Torvalds suggests that a “slightly overweight penguin” would be the best mascot for Linux. He recommends Larry Ewing’s “Tux” penguin images.
September    Linus Torvalds along with Linux Journal, Yggdrasil Computing, Inc., Linux International Work Group Solutions and with the help of Digital Equipment Corporation and Red Hat, file suit against William R. Della Croce, Jr.     to re-assign the Linux trademark to Linus Torvalds. The firm of Davis & Schroeder handles the case on an almost pro-bono basis.
October    Kool Desktop Environment (KDE) project announced.
1997
February Linus Torvalds moves to California and begins working for Transmeta, a microprocessor manufacturer.
May Eric S. Raymond gives a paper entitled The Cathedral and the Bazaar at Linux Kongress. It outlines the principles of what would become known as the “open source” method.
August The Linux trademark dispute between William Della Croce and Linus Torvalds is settled, with Della Croce re-assigning the trademark to Torvalds.
Miguel de Icaza starts the GNOME project.
1998
February Bruce Perens and Eric S. Raymond found the Open Source Initiative, an organization to promote the use of open source software and establish guidelines for open source licenses.
May Google search engine appears using servers running Linux.
July Sam Ockman founds Penguin Computing. It is the first hardware company to produce Linux-only systems.
Version 1.0 of the K Desktop Environment (KDE) released.
Gael Duval creates Mandrake Linux.
August     Forbes magazine devotes its cover story to Linus Torvalds.
November  Eric S. Raymond releases internal Microsoft memos, known as the “Halloween Documents”, that show that the company is formulating plans to deal with the increasing use of Linux.
December Corel releases Word Perfect 8 for Linux as a free download.
1999
January Linux kernel version 2.2 released.
March The Burlington Coat Factory announces that it is using Linux in its stores.
GNOME 1.0 desktop released.
May Dell pre-installs Red Hat Linux on some servers and workstations.
August Red Hat has its initial public offering (IPO) and becomes a publicly traded company.
VA Linux systems stock reaches $320 US after starting its initial public offering (IPO) at $30. Ending the day at $239.25, it is the largest first-day gain in history to date.
Matthew Szulik replaces Bob Young as CEO of Red Hat.
Corel releases Linux distribution.
2000
March A Netcraft survey reveals that Apache webserver powers 60% of the World Wide Web.
Linux distributor Caldera Systems Inc has its initial public offering (IPO).
May Microsoft CEO Steve Ballmer calls Linux “a cancer that attaches itself in an intellectual property sense to everything it touches.” in an interview with the Chicago Sun-Times.
August Caldera Systems acquires the Santa Cruz Operation’s (SCO) Unix server division.
September Trolltech releases the QT libraries, used by KDE, under the GPL.
October Microsoft buys a large stake in Corel.
IBM CEO Louis Gerstner announces that the company will invest $1 billion in Linux development.
2001
January Linux kernel version 2.4 released.
Corel announces that it is selling its Linux unit.
May Linus Torvalds publishes his autobiography entitled Just for Fun with the help of journalist David Diamond.
August MP3.com founder Michael Robertson starts development on Lindows, a Debian-based distribution which promises to be a Linux distribution that can be used by anybody.
October Amazon.com reveals in a SEC filing that switching to Linux has saved them over $20 million.
November 18 year-old Brazilian developer Marcelo Tosatti becomes the maintainer of the 2.4 kernel
Microsoft files a trademark infringement suit against Lindows, claiming the similarity to the name Windows “confuses the public”.
2002
January Credit Suisse First Boston fined $100 million for fraud in connection with the VA Linux IPO.
February Linus Torvalds begins using BitMover’s BitKeeper to manage kernel development. Bitkeeper is proprietary software and many, including Richard Stallman, criticize the decision.
May Linux distributors Caldera, SuSE, Turbolinux and Conectiva sign an agreement to form UnitedLinux and jointly develop a Linux distribution for servers.
June Ransom Love is ousted as CEO of Caldera and is replaced by Darl McBride.
July Walmart begins selling Microtel PCs through their online store with Lindows and Mandrake Linux pre-installed
Version 1.0 of the free sound codec Ogg Vorbis is released.
August Caldera announces that they are changing their name to The SCO Group and are going to concentrate on Unix development
Free office suite OpenOffice.org 1.0 is released.
Shares of VA Linux stock reach an history low $0.64 US. Having been the highest climber in IPO history, VA Linux becomes the poster child for the dot-com bust.
2003
January Maureen O’Gara of LinuxGram posts a story that SCO is planning on suing Linux vendors for using proprietary Unix intellectual property. The SCO Controversy begins.(see separate SCO timeline)
May The city of Munich, Germany announces that it’s switching 14,000 PCs from Windows to Linux.
June La Junta de Extremadura (Spain) announces that 80,000 computers in their schools are running a distribution called GNU/LinEx.
Linus Torvalds announces that he’s leaving Transmeta to work full time on the kernel for the Open Source Development Labs. The Torvalds family moves to Oregon.
July Red Hat announces that they will no longer sell boxed sets of their Linux distribution for retail customers. Instead, they will distribute Linux to end users via a development distribution called Fedora Core.
August Novell buys Linux desktop software company Ximian.
November Novell acquires German Linux distributor SuSE.
December Linux kernel version 2.6 is released.
2004
July Microsoft settles its trademark dispute with Lindows. Lindows changes its name to Linspire and assigns Microsoft the rights to the Lindows name. Microsoft pays $20 million and grants Linspire licenses to use certain Windows media     libraries.
October First version of Ubuntu Linux released.
During the Superbowl, IBM runs a commercial promoting Linux featuring Muhammed Ali and other celebrities
2005
April Larry McVoy, creator of BitKeeper, discontinues support for the free BitKeeper client after complaining about attempts to reverse engineer it. Linus Torvalds announces that he will no longer use BitKeeper for kernel development.         Torvalds starts work on a replacement he calls Git.
December In strongly worded emails to the GNOME mailing list, Linus Torvalds reveals that he prefers KDE to GNOME, starting a small controversy. “Gnome seems to be developed by interface nazis…”, claims Torvalds.
2006
January Linus Torvalds reveals that he doesn’t like the anti-DRM provisions in the draft for version 3 of the GNU General Public License and as it stands, he won’t convert the Linux kernel to it.
April Oracle CEO Larry Ellison announces that the company may develop their own Linux distribution. “…it makes a lot of sense for us to look at distributing and supporting Linux.”, states Ellison.
May Nicolas Negroponte displays the first working prototype of a $100 laptop computer running Linux and designed for children in the third world. Bill Gates ridicules the project.
November Novell and Microsoft sign a controversial agreement in which Novell agrees to work on SUSE Linux/Windows interoperability while Microsoft pledges not to sue Novell’s customers for possible patent infringement. The         agreement is poorly received by the Linux-user community. It also prompts a re-write of the upcoming version 3 of the GNU General Public License in order to insert clauses to prohibit distribution of GPL software under such         patent agreements.
2007
May Dell announces that it will pre-load Ubuntu Linux on selected desktop and laptop models of their computers.
Microsoft general counsel Brad Smith states in a Fortune magazine interview that his company believes that Linux and related projects infringe on over 230 Microsoft patents. There are fears that a patent war between Microsoft     and the Free Software/Open Source developers. might break out.
June Linux distributors Xandros and Linspire sign patent agreements with Microsoft similar to the pact previously signed between Novell and Microsoft. Ubuntu Linux maintainer Mark Shuttleworth and Mandriva CEO François     Bancilhon publicly rule out making such agreements. It is also revealed that Red Hat had been negotiating a pact with Microsoft though finally no agreement was reached.

Download Centos 6

[1]
Here is the configuration Examples for CentOS 6 that is compatible with Red Hat Enterprise Linux 6.
Download ISO file ( CentOS-6.3-x86_64-bin-DVD1.iso ) for installation from the following site.
It's OK to download 64 bit version commonly. But if your computer is old and not supported 64 bit computing, download 32 bit version from below.
* The examples on this site uses 64 bit version.
[2]
Burn ISO file to DVD with an application on your computer and Make an Installation Disk. After finishing it, proceed to next step for installing CentOS 6.

Tuesday, 15 January 2013

FreePBX on Debian



UPDATE:Try this to fix the problems with mysql permissions.  This was suggested by someone else.  I have not tried it myself.  "The 'astrundir' must be changed to  /var/run/asterisk before installing FreePBX. Otherwise, the owner for /var/run/mysqld will be changed to asterisk and that causes mysqld to fail starting. Or you can just change permission of /var/run/mysqld to 777"
I have updated the how-to build asterisk with freepbx on debian sarge with a minimal install that was originally located atsquishychicken.com.
The total install is around 500MB (after deb archives are removed of course :)  )... enjoy.  Please let me know if there are any glaring errors that I have over looked.
Just a quick note before we get started.... there are a couple of things that I assume here.  One is that you are familiar with your shell.  Be sure that you don't just blindly cut and paste this into a window... look at the command and think about what they are doing.  When you see cat > /some/file <<EOF  make sure you cut to the next EOF...
 YMMV and use at your own risk.
 #Install barebones Debian Sarge using the "linux26" command from the initial boot screen.
 boot:linux26
# update all packages and make sure we are current
 apt-get update
apt-get upgrade
 # install and configure etherconf for static IP
# specify the hostname and assign a static ip for later
 apt-get install etherconf
#install sshd so that you can do the rest of the install remotely without the need for a mouse/kb/monitor.  It is also handy for doing the cut and paste thing which Windows users know and love.
apt-get install ssh
# get needed software and dependencies
apt-get install vim libasound2 libgsm1 libltdl3 libpq3 libspeex1 libsqlite0 libtonezone1 odbcinst1 unixodbc openssl libssl0.9.7 libssl-dev libreadline4 libreadline4-dev libeditline0 libeditline-dev libedit-dev libedit2 libncurses5 libncurses5-dev zlib1g-dev bison libnet-telnet-perl mime-construct libipc-signal-perl libmime-types-perl libproc-waitstat-perl subversion libipc-signal-perl libproc-waitstat-perl apache2 mysql-server php4 php4-cli php4-mysql php4-pear libapache2-mod-php4 php4-curl libmysqlclient14-dev libmysqlclient14 php4-gd make gcc g++ fxload
# don't forget the kernel headers
apt-get install kernel-headers-`uname -r`
# get the latest asterisk  from cvs
cd /usr/src
svn checkout http://svn.digium.com/svn/asterisk/branches/1.2 asterisk-1.2
svn checkout http://svn.digium.com/svn/zaptel/branches/1.2 zaptel-1.2
svn checkout http://svn.digium.com/svn/libpri/branches/1.2 libpri-1.2
svn checkout http://svn.digium.com/svn/asterisk-addons/branches/1.2 asterisk-addons-1.2
svn checkout http://svn.digium.com/svn/asterisk-sounds/trunk asterisk-sounds
# build zaptel drivers for 2.6 kernel
cd zaptel-1.2
make clean; make linux26; make install
# if you need pri support
cd ../libpri-1.2
make clean; make install
#NOTE: In asterisk 1.2.x and above you no longer need the mpg123 player so the installation procedure has been removed from this document.  You DO need to install the asterisk-addons package in order to use the built in MOH.
cd ../asterisk-1.2
make clean; make install
# build asterisk addons with mysql patch to makefile
cd ../asterisk-addons-1.2
perl -p -i.bak -e 's/CFLAGS.*D_GNU_SOURCE/CFLAGS+=-D_GNU_SOURCE\nCFLAGS+=-DMYSQL_LOGUNIQUEID/' Makefile
make clean; make install
# build asterisk-sounds
cd ../asterisk-sounds
make clean; make install
# install lame for mp3 resample
cd /usr/src
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.96.1.tar.gz
tar -xvzf lame-3.96.1.tar.gz
cd lame-3.96.1
./configure --prefix=/usr --sysconfdir=/etc
make && make install
# use xorcoms handy zaptel toolset
cd /usr/src
wget http://rapid.sunsite.dk/rapid/pool/main/z/zaptel/zaptel_1.2.5-3_i386.deb
dpkg -i zaptel_1.2.5-3_i386.deb
# If it asks you whether to keep the existing package or install the new one 
go with the default by hitting 'ENTER' or typing 'N'
# auto detect zaptel hardware
genzaptelconf -ds
# install asterisk perl
cd /usr/src
wget http://asterisk.gnuinter.net/files/asterisk-perl-0.08.tar.gz
tar zxf asterisk-perl-0.08.tar.gz
cd asterisk-perl-0.08
perl Makefile.PL
make install
# get freepbx
cd /usr/src
wget http://ufpr.dl.sourceforge.net/sourceforge/amportal/freepbx-2.1.1.tar.gz
tar -xvzf freepbx-2.1.1.tar.gz
cd freepbx-2.1.1

# create the databases and tables
mysqladmin create asteriskcdrdb
mysql asteriskcdrdb < /usr/src/freepbx-2.1.1/SQL/cdr_mysql_table.sql
mysqladmin create asterisk
mysql asterisk < /usr/src/freepbx-2.1.1/SQL/newinstall.sql
#grant access to asterisk user.  The usernames and passwords here MUST be the same as those configured during the freepbx install.  Freepbx defaults (username 'asteriskuser' and password 'amp109') are used here.  If you change them here you MUST also change them to the same during the freepbx install.
 echo "GRANT ALL ON  asterisk.* to asteriskuser@localhost identified by 'amp109'" | mysql
 echo "GRANT ALL ON  asteriskcdrdb.* to asteriskuser@localhost identified by 'amp109'" | mysql
 # add the asterisk user and group
 groupadd asterisk
useradd -g asterisk -d /var/lib/asterisk -s /bin/bash asterisk
# make the directory for the virtual host and for recordings.
mkdir -p /var/www/`uname -n`/cgi-bin
mkdir -p /var/www/`uname -n`/htdocs
mkdir -p /var/lib/asterisk/sounds/custom
# build the default zapata.conf
 cat > /etc/asterisk/zapata.conf << EOF
[channels]
language=en
language=en
context=from-pstn
signalling=fxs_ks
rxwink=300              ; Atlas seems to use long (250ms) winks
;
; Whether or not to do distinctive ring detection on FXO lines
;
;usedistinctiveringdetection=yes

usecallerid=yes
hidecallerid=no
callwaiting=yes
usecallingpres=yes
callwaitingcallerid=yes
threewaycalling=yes
transfer=yes
cancallforward=yes
callreturn=yes
echocancel=yes
echocancelwhenbridged=no
echotraining=800
rxgain=0.0
txgain=0.0
group=0
callgroup=1
pickupgroup=1
immediate=no
;faxdetect=both
relaxdtmf=yes
faxdetect=incoming
;faxdetect=outgoing
;faxdetect=no

; include zap extensions defined in AMP
#include zapata_additional.conf
#include zapata-channels.conf
EOF
# don't forget the run directory
mkdir /var/run/asterisk
# Now install freepbx.  During this install, it will ask for changes to the defaults.  If you hit ENTER the default will be used.  You MUST pay close attention to these defaults as they need to be changed to the defaults used earlier and in the next step after this one.  There is nothing preventing you from using different usernames, passwords, and directories as long as they are the same in the freepbx setup as they are through out the rest of this document which I have/will point out.
uname -n
#Change the defaults during the install to the following.  Substitute "uname -n" to whatever was returned when you typed in "uname -n" above:
#Enter the path to use for your AMP web root:[/var/www/"uname -n"/htdocs]
#Enter the path to use for your FOP web root:[/var/www/"uname -n"/htdocs/panel]
#Enter the path to your Apache cgi-bin:[/var/www/"uname -n"/cgi-bin]
#Enter the IP ADDRESS or hostname used to access the AMP web-admin:[xx.xx.xx.xx] The IP Address of your #Asterisk Machine

cd /usr/src/freepbx-2.1.1
./install_amp
# create the virtual host file with good defaults.  These original defaults MUST have been changed manually during the automated freepbx install above.
cat > /etc/apache2/sites-available/pbx.conf << EOF

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName `uname -n`
DocumentRoot /var/www/`uname -n`/htdocs
<Directory />

Options FollowSymLinks
AllowOverride None
</Directory>

<Directory /var/www/`uname -n`/htdocs>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

</Directory>
ScriptAlias /cgi-bin/ /var/www/`uname -n`
<Directory "/var/www/`uname -n`/cgi-bin">
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined
ServerSignature On

</VirtualHost>
EOF
# make apache run as user asterisk and enable the virtual host
ln -s /etc/apache2/sites-available/pbx.conf  /etc/apache2/sites-enabled
perl -p -i.bak -e 's/User www-data/User asterisk/' /etc/apache2/apache2.conf
perl -p -i.bak -e 's/Group www-data/Group asterisk/' /etc/apache2/apache2.conf
# make tweeks for php to allow for file uploads
perl -p -i.bak -e 's/upload_max_filesize.*$/upload_max_filesize = 20M/' /etc/php4/apache2/php.ini
perl -p -i.bak -e 's#AddType application/x-httpd-php-source .phps#AddType application/x-httpd-php-source .phps\nLimitRequestBody 20000000#' /etc/apache2/mods-available/php4.conf
# restart to get changes
/etc/init.d/apache2 restart
# change the security to database authentication.  The username and password must be the same as those used during the freepbx install earlier in this document.  The freepbx defaults (username=admin, password=amp111) are used
perl -p -i.bak -e 's/AUTHTYPE=none/AUTHTYPE=database/' /etc/amportal.conf
echo "insert into ampusers values ('admin','amp111','','','','*');" | mysql asterisk
# You will probably get an error/warning here.  Something about "duplicate entry 'admin' for  key 1".  Just ignore it.
# install astmanproxy for astapi dialing
cd /usr/src/
svn checkout http://svncommunity.digium.com/svn/astmanproxy/tags/1.20
cd 1.20
make && make install
# modify /etc/asterisk/astmanproxy.conf and assign username/password
eg: host = localhost, 5038, proxy, 1234, on
# modify /etc/asterisk/manager_custom.conf to add the following
[proxy]
secret = 1234
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.255
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user

[astapi]
secret = 1234
deny=0.0.0.0/0.0.0.0
permit=10.0.0.0/255.255.255.0
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user
# build an rc.local startup script
echo '#!/bin/bash' > /etc/init.d/local
chmod +x /etc/init.d/local
update-rc.d local defaults 80
echo '/usr/local/sbin/astmanproxy' >> /etc/init.d/local
# change the user that astmanproxy runs as
perl -p -i -e 's/proc_user.*$/proc_user = asterisk/' /etc/asterisk/astmanproxy.conf
perl -p -i -e 's/proc_group.*$/proc_group = asterisk/' /etc/asterisk/astmanproxy.conf
# change permissions and start amp
amportal chown
amportal start
#If you don't have a zaptel card
modprobe ztdummy
#build a freepbx automatic start and stop script as last to start and first to stop.  I know there is a way to do it with just one script but I haven't figured out how to modify the "skeleton" file included in init.d yet.
echo '#!/bin/bash' > /etc/init.d/amportal-start
chmod +x /etc/init.d/amportal-start
update-rc.d amportal-start start 99 2 3 4 5 .
# Add this line if you do NOT have a zaptel card
echo 'modprobe ztdummy' >> /etc/init.d/amportal-start
# Now complete the start script and add the stop script
echo '/usr/sbin/amportal start' >> /etc/init.d/amportal-start
echo '#!/bin/bash' > /etc/init.d/amportal-stop
chmod +x /etc/init.d/amportal-stop
update-rc.d amportal-stop stop 10 0 1 6 .
echo '/usr/sbin/amportal stop' >> /etc/init.d/amportal-stop

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.