How to install EspoCRM with Nginx on an Ubuntu VPS

espocrm logoIn this tutorial we are going to provide you with step-by-step instructions on how to install EspoCRM 3.7.2 with Nginx on an Ubuntu VPS.
EspoCRM is an open source Customer Relationship Management web application that allows you to see, enter and evaluate all your company relationships regardless of the type. It is designed to be fast, simple, and customizable.

Make sure your package list and the OS packages are up to date by running the following commands:

sudo apt-get update
sudo apt-get upgrade

To install the latest Nginx version from the official Nginx repository, edit the ‘/etc/apt/sources.list’ file:

sudo vi /etc/apt/sources.list

Add the following lines:

deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx

Stop and remove Apache service:

sudo service apache2 stop
sudo apt-get remove apache2

Install Nginx on your virtual server:

sudo apt-get update
sudo apt-get install nginx

Configure Nginx to start on boot:

sudo update-rc.d -f nginx defaults

Install PHP and PHP modules required by EspoCRM:

sudo apt-get install php5 php5-cli php5-fpm php5-mysql php5-gd php5-mcrypt php5-imap
sudo php5enmod mcrypt
php5enmod imap

Then, start with the EspoCRM installation procedure. Get the latest version of EspoCRM  available at ‘http://www.espocrm.com/downloads/’ to a directory of your virtual server and extract it using the following commands:

cd /opt/
wget http://www.espocrm.com/downloads/EspoCRM-3.7.2.zip
unzip EspoCRM-3.7.2.zip
mv EspoCRM-3.7.2/ /var/www/espocrm/

Create a new Nginx configuration file and add the following virtual block for your domain name:

vi /etc/nginx/conf.d/your-domain.com.conf

Add the following lines:

server {
listen 80;
server_name your-domain.com;

root /var/www/espocrm;
index index.php index.html;
access_log /var/log/nginx/your-domain.com-access.log;
error_log /var/log/nginx/your-domain.com-error.log;
charset en_us.UTF-8;

location /api/v1/ {
if (!-e $request_filename){
rewrite ^/api/v1/(.*)$ /api/v1/index.php last; break;
}
}

location / {
rewrite reset/?$ reset.html break;
}

location ^~ (data|api)/ {
if (-e $request_filename){
return 403;
}
}

location ^~ /data/logs/ {
return 403;
}
location ^~ /data/config.php {
return 403;
}
location ^~ /data/cache/ {
return 403;
}
location ^~ /data/upload/ {
return 403;
}
location ^~ /application/ {
return 403;
}
location ^~ /custom/ {
return 403;
}
location ^~ /vendor/ {
return 403;
}

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control “public, must-revalidate, proxy-revalidate”;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

Do not forget to replace your-domain.com with your actual domain name. Then, delete the ‘default’ Nginx configuration file:

rm /etc/nginx/conf.d/default.conf

Open the ‘/etc/php5/fpm/pool.d/www.conf’ file and change the ‘listen’ variable:

change:

listen = /var/run/php5-fpm.sock

to

listen = 127.0.0.1:9000;

Locate the PHP configuration file:

# php -i | grep -i php.ini
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini

Edit the ‘/etc/php5/apache2/php.ini’ configuration file:

vi /etc/php5/cli/php.ini

Add/modify the following settings:

max_execution_time = 300
max_input_time = 300
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 32M

The webserver user (www-data) needs to be able to write to files and directories inside the ‘/var/www/espocrm’ directory, so it can easily be accomplished by executing the following command:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
sudo chown www-data:www-data -R /var/www/espocrm/

Test the nginx configuration:

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If test is successful, restart php5-fpm and Nginx services for the changes to take effect:

sudo service php5-fpm restart
sudo service nginx restart

EspoCRM requires a database to work as this is where data is saved, so create a new MySQL database on your server:

mysql -u root -p
mysql> create database espocrmdb;
mysql> GRANT ALL PRIVILEGES ON espocrmdb.* TO 'espocrmuser'@'localhost' IDENTIFIED BY 'Y0UR-PASSW0RD';
mysql> flush privileges;
mysql> quit

Open http://your-domain.com/ using a web browser and follow the easy instructions.
Once installed, open http://your-domain.com and the first user you create will be the Admin user. Click the ‘Create Account’ button and go to the ‘Create Account’ page. Then, log in to the administrator back-end and configure EspoCRM according to your needs.

espocrm back-end

Do not forget to add this line to the crontab file to run Espo Scheduled Jobs:

* * * * * /usr/bin/php -f /var/www/espocrm/cron.php > /dev/null 2>&1

That is it. The EspoCRM installation is now complete.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install EspoCRM with Nginx for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “How to install EspoCRM with Nginx on an Ubuntu VPS”

    • Yes, there is a difference between the two. PHP-FPM can listen on Unix and TCP sockets. Unix socket is /var/run/php5-fpm.sock and TCP is 127.0.0.1:9000.
      The fundamental difference will be that the Unix sockets can only be accessed by the local machine while the TCP sockets are using the network stack and can be accessed by everyone that has access to the server.

      The Unix socket is like a file in Linux and can be accessed only by the program that has permission and ownership over it. With Unix sockets you can’t have your web server and php run on two different machines.

      Reply

Leave a Comment