How To Install Live Help on a Cloud Server

For the purpose of this tutorial we are going to be walking through the setup of Live Help within a cloud server at DigitalOcean. Live Help can be setup on shared hosting, a virtual private server (VPS), cloud server or bare metal dedicated servers. The size of your business and your web site traffic will determine the size of the cloud server that you require. Remember you can always scale the server to a smaller or larger size at a later stage.

Why a cloud server?

Even if you have your web site hosted with another hosting company or within shared hosting, you can setup the cloud server to point to a sub-domain like chat.yourdomain.com. You can configure a sub-domain DNS record to point to the cloud server’s IP address. By setting up Live Help with its own cloud server you can easily scale the server as your business grows.

Digital Ocean

The server we will be using is a 2GB cloud server running Ubuntu 14.04 with a configuration of Linux, nginx, MySQL, PHP (also referred to as LEMP) for $20 / month. DigitalOcean offers simple, affordable cloud servers with SSD storage so we have spun up a server using one of their Droplets. You could also use other providers such as Amazon Web Services (AWS) or Rackspace Cloud.

Preparing your cloud server

Before getting started we recommend that you complete the following tutorial over at DigitalOcean for your initial server setup with Ubuntu 14.04. Additionally for the purpose of securing the server, I would recommend completing the additional checklist over on the DigitalOcean blog.

Install the nginx web server

nginx is a fast, modern and efficient web server and is our preferred web server when setting up Live Help on your own cloud server.

sudo apt-get update
sudo apt-get install nginx

nginx should start running after it is installed in Ubuntu and you should be able to view the nginx text web page for your cloud server using your web browser.

Install the MySQL database server

Now that you have the web server installed you can prepare to install MySQL. MySQL is the database server that we use for Live Help.

During the MySQL installation you will be prompted to set the MySQL root user password. You can install MySQL by typing:

sudo apt-get install mysql-server
sudo mysql_install_db

Once you have MySQL installed, you will need to secure MySQL by typing the following. Note that during this process you should remove the anonymous users, disallow the root login remotely, remove the test database and reload the privilege tables.

sudo mysql_secure_installation

Install PHP for nginx

We now have nginx setup to serve pages and the MySQL database setup to store our Live Help data we can setup nginx to work with PHP. nginx doesn’t include PHP support by default so we need to install php-fpm which stands for “fastCGI process manager”. We need to set this up so that nginx knows how to process the *.php files used within Live Help. You can install PHP by typing:

sudo apt-get install php5-fpm php5-mysql php5-mcrypt php5-sqlite

Live Help requires some extra PHP extensions so we are also installing those at the same time i.e. php5-mysql php5-gd2 and php5-xml. Once those are installed we can proceed with editing the php-fpm configuration files. You can open the php-fpm configuration file using root permissions with the following command.

sudo nano /etc/php5/fpm/php.ini

You then need to search for the line containing cgi.fix_pathinfo and change the line to the following. Please note you must remove the semi-colon (;) at the start of this line and also change it from 1 to 0.

cgi.fix_pathinfo=0

Now save and close the file and then restart the php-fpm service by running:

sudo service php5-fpm restart

Configure nginx with php-fpm

We need to make some changes to the nginx configuration files so that nginx will process the *.php files correctly. You can edit this file by typing:

sudo nano /etc/nginx/sites-available/default

Within this file there is a server block that contains the following lines that are commented out.

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
#       root /usr/share/nginx/html;
#}

# pass the PHP scripts to FastCGI server
#
#location ~ \.php$ {
#    fastcgi_split_path_info ^(.+\.php)(/.+)$;
#    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
#    # With php5-cgi alone:
#    fastcgi_pass 127.0.0.1:9000;
#    # With php5-fpm:
#    fastcgi_pass unix:/var/run/php5-fpm.sock;
#    fastcgi_index index.php;
#    include fastcgi_params;
#}

This should be replaced with the following lines to enable the php-fpm configuration.

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
  root /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server
location ~ \.php$ {
  try_files $uri =404;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

You also need to change the following section of he nginx configuration file. Replace localhost with your actual domain name and add index.php for the default file list.

index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

The above lines should then look something like below, where example.com is your actual domain name that the cloud server is setup as.

index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name example.com;

Once the above changes have been saved you will need to restart nginx by typing:

sudo service nginx restart

Create a test PHP file

Your LEMP stack should now be configured correctly for Live Help. You can test the PHP is working correctly with nginx by creating a test phpinfo.php page.

sudo nano /usr/share/nginx/html/phpinfo.php

Type the following and save the file.

<?php
phpinfo();
?>

Once this is saved you can view phpinfo.php in your web browser and should should see a list of the PHP configuration that is setup. After you have confirmed that PHP is working, delete the phpinfo.php file as you don’t want to leave that on the server. You can delete the file by typing the following:

sudo rm /usr/share/nginx/html/phpinfo.php

Uploading the Live Help files

To upload the files to your cloud server you can use the same login details that you used to connect via SSH in the previous step, however to upload the files you will use the SFTP option. We recommend Filezilla client for uploading files as it is free and supports SFTP file transfer using a GUI. If you are using Mac you might like to consider Transmit which is a paid app.

Before uploading you would need to create the livehelp folder. You can do this with the following command.

sudo mkdir /usr/share/nginx/html/livehelp/

You can then use your chosen SFTP app to upload the Live Help files to /usr/share/nginx/html/livehelp/

Prepare the Live Help MySQL user

During the MySQL server installation we setup the root user, it is highly recommended that you setup a separate MySQL user for use with just Live Help. Setting up a database user for Live Help will have less permissions than the root user and your server will be more secure.

To setup the MySQL user we need to login to the mysql client as the root user. Type the following and then enter your MySQL root password that you setup earlier.

mysql -u root -p

Firstly we need to setup the database for Live Help to use, you can do this by typing.

CREATE DATABASE livehelp;

You can setup the database user by typing the following. You should pick a different username than newuser and also use a different password to the one shown in the first line.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX ON livehelp.* TO 'newuser'@'localhost';

You then need to reload the MySQL user privileges and then quit the MySQL client by typing the following.

FLUSH PRIVILEGES;
quit

Installing Live Help

Before starting the Live Help installation you will need to change some permissions and create the database configuration file. You can do this by typing:

sudo chown -R www-data:www-data /usr/share/nginx/
sudo touch /usr/share/nginx/html/livehelp/include/database.php
sudo chmod 775 /usr/share/nginx/html/livehelp/include/database.php

You are now ready to install Live Help by following our installation instructions. You can begin the installation at /livehelp/install/index.php

If you experience any issues with configuring your cloud server then the following links are a great reference for getting started with DigitalOcean.

Recommended external reading

Stardevelop