Here is how to get sugarcrm working on Nginx Server. Nginx is a great apache alternative and is much faster in certain terms. It serves php pages with php-fpm and this makes thing much lighter and faster.
We will get this thing installed in a Centos or Redhat Box, because that is where I had tried it. This will also allow you to learn the basics to create a LEMP (Linux + 'e'Nginx + Mysql + Php) server, contrary to the LAMP (Linux + Apache + Mysql + Php) ones you have been doing all these days. You can use this to host your other php applications also. So lets get started.
Creating the LEMP Instance:
Launch a clean CentOS / Redhat box and start with instaling Nginx.
CentOS does not offer the latest version of Nginx in its default YUM
repository. To install it, you need to add the EPEL (Extra Packages for
Enterprise Linux) repository, which is part of the Fedora Project.
1. Install the EPEL repository:
# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm
(Note: This url may change depending upon the Redhat/CentOS version you may be using please do the neccessary corrections accordingly. In case you are stuck ask me via the comments and I'll help you out)
2. Install nginx
# yum install nginx
3. You will be asked to install the gpg-key for EPEL. Answer yes
4. Start Nginx
# /etc/init.d/nginx start
5. Check the installation by going to your web server’s default site, either using your ip address or domain name. And you will see a "Welcome to Nginx" page.
- Default config file: /etc/nginx/nginx.conf
- Default SSL config file: /etc/nginx/conf.d/ssl.conf
- Default virtual hosting config file: /etc/nginx/conf.d/virtual.conf
- Default documentroot: /usr/share/nginx/html
Configure PHP As FastCGI
To install php5 with other modules we will first have to add the correct php repository:
I tried this php 5.2.10 which is available in the Cent-OS Testing repository.
1. To add the CentOS-Testing repository create a file c5-Testing.repo in /etc/yum.repos.d/ and add the following lines in it
[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
Install php and all other required extensions via this command:
#
yum install php-pear-Net-Socket php-pear php-common php-gd php-devel
php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml
php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql
If some things fail to install use the --enablerepo=c5-Testing switch with yum and you can also exclude php-readline extension by using the switch --exclude with yum because this too causes dependency issues at times.
<?php
phpinfo();
?>
Now that the webserver is ready we will go ahead and install the Mysql database. And I must say that Mysql installation is pretty easy with yum and we will use these steps:
- Install MySQL
yum install mysql-server mysql php-mysql
Configuring MySQL
- Set the MySQL service to start on boot
chkconfig --levels 235 mysqld on - Start the MySQL service
service mysqld start - Log into MySQL
mysql -u root - Set the root user password for all local domains
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password') ;
SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('new-password');
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new-password'); - Drop the Any user (for security)
DROP USER ''@'localhost';
DROP USER ''@'localhost.localdomain';
- Exit MySQL
exit
Before installting sugarcrm we will need to make certain changes in the nginx configuration file.
A sample Nginx configuration for Sugarcrm :-
Step 1: Open the file :
/etc/nginx/nginx.conf
and enter the following configuration (I just replaced the default nginx.conf with this after backing up the original one):server {
listen 0.0.0.0:80;
server_name testsugarcrm.com;
gzip off;
set $root_path /usr/share/nginx/html/sugarcrm;
location / {
root $root_path;
index index.php;
error_page 404 = /index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
break;
}
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $root_path$fastcgi_script_name;
}
}
Step 2: Execute the command
/etc/init.d/nginx restart
in shell.Step 3: Add the following entry in
/etc/hosts
file:-127.0.0.1 testsugarcrm.com
Step 4: Download suagarcrm comminity edition from here.
Now unzip the package in nginx webroot (/usr/share/nginx/html or whatever it may be in your case) and rename the folder 'sugarcrm'
I tried this exercise with sugarcrm 5.2.0 which I had with me. However, I believe this would work with other versions also.
Now, check the url
http://testsugarcrm.com
in your browser. This will give you the sugarcrm installer page. Thereafter, the installation is pretty self-explanatory will complete without hiccups :) However you can visit the sugardocs in case you need help.One last thing I would like to mention here is, some instances which I installed had a strange error of the page going blank after I would press 'Next' in the sugarcrm installation wizard. To resolve this issue, just put the 'display_errors' 'On' in your php.ini file and restart Nginx and rerun the wizard. Now you will see a fatal error about the "Session directory" not getting enough "Permissions" with the directory path mentioned there. You can just go ahead and set the permissions to that directory by the following command:
# chmod -R 777 /usr/share/sessions (your directory will be differrent, I have just mentioned an arbitrary directory path).
That is it now your sugar is being served by Nginx !
Kudos.. this worked for me. Had a problem with sugarcrm installation wizard (got a white page halfway) and solved it by giving 777 permission to the sessions directory.
ReplyDelete