One issue that comes up occasionally for people hosting their own SugarCRM or SuiteCRM instance is running out of storage on their server. SugarCRM and SuiteCRM by default use a directory called ‘upload’ located in the root of your instance to store all file attachments. This tutorial will show you how to change this setting to another drive using Digital Ocean’s new block storage volumes.

Digital Ocean Droplet

 

Looking at Digital Ocean’s droplet pricing (as of October 2016) we see you get quite a bit of power with SSD speed in a $10-$40 per month VPS. For many applications, including SugarCRM and SuiteCRM, the stock storage of the VPS is sufficient. However, if your company works with large documents or uses an add-on from Sugar Outfitters to synchronize with a service like Box or Google Drive that storage can be used up quickly. While it is easy to upgrade to a higher sized droplet on Digital Ocean this can get pretty expensive quickly.

 

A new feature on Digital Ocean that solves this problem is called Block Storage where you can quickly add SSD storage to your VPS without having to upgrade to a higher sized droplet. This is a much less expensive option and allows you to quickly expand storage as requirements change. Below you can see the block storage pricing for Digital Ocean (as of October 2016). Let’s walk through the steps on how to change the storage location on your SugarCRM or SuiteCRM instance to a Digital Ocean Block Storage Volume.
Digital Ocean Block Storage Pricing

 

There are detailed instructions on how to install SugarCRM and SuiteCRM so this tutorial assumes you already have an up and running server with either SugarCRM or SuiteCRM installed. The instruction for adding block storage are identical for either platform.

Creating and attaching block storage

 

Log into your Digital Ocean account and click on the droplet you want to add storage to.

Click on Volumes from the options on the left and then click the ‘Add Volume’ button.

screen-shot-2016-10-16-at-10-19-06-pmNext you want to select the volume size you would like and name the volume. In this example we named this volume ‘crm-storage’. This is naming is completely up to you so use your own convention but remember to replace that name if you copy any commands below.

naming

Creating the volume is quick and once complete you will see a popover listing the commands to mount the volume on your VPS. Below are the commands for this example. Note I have highlighted the volume name in red. I have also chosen to keep the same name on the server as the Digital Ocean interface. This is by no means required but may help if you have multiple volumes attached to one droplet. If you want a different name you would replace the highlighted red text after /mnt.

$ sudo mkfs.ext4 -F /dev/disk/by-id/scsi-0DO_Volume_crm-storage
$ sudo mkdir -p /mnt/crm-storage
$ sudo mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_crm-storage /mnt/crm-storage
$ echo /dev/disk/by-id/scsi-0DO_Volume_crm-storage /mnt/crm-storage ext4 defaults,nofail,discard 0 0 | sudo tee -a /etc/fstab

Now your volume is ready to use on your droplet. You can test that your new storage by logging into the droplet via SSH and creating a test file and reading it.

echo 'Hello, I exist' > /mnt/crm-storage/test.txt
$ cat /mtn/crm-storage/test.txt

In this example let’s create a directory for our production instance just in case you have a test environment set up that you would like to also store documents on the added volume. You also need to make sure the webserver user has write permissions to this directory just like you would if you were using the ‘upload’ of your CRM instance.

$ mkdir /mnt/crm-storage/production
$ sudo chown -R www-data:www-data /mnt/crm-storage/production
$ sudo chmod -R 775 /mnt/crm-storage/production

Using your favorite text editor edit the file named config_override.php located in the root directory of your instance. Add the following line and save the file. Just a reminder to change the names of the drive and or directory to follow what you have set up previously.

$sugar_config['upload_dir'] = '/mnt/crm-storage/production';

 

Now let’s create a Note with an attachment in the application to test. Log into your instance and create a Note with any attachment from your computer.

 

Create Note w/ Attachment

 

To see that the file was indeed stored on the new volume instead of the ‘uploads’ directory enter the following command into your terminal window.

$ ls /mtn/crm-storage/production

If everything was successful you should see something like ’26fde971-9465-2163-2c1d-5804565c552a’. This is normal as both SugarCRM and SuiteCRM store files as their unique id on disk and associates the filename in the database.

Lastly if you already have documents on your instance’s uploads directory those need to be moved to the new volume or you won’t be able access them.

$ cd <instance directory>/upload

$ mv * /mnt/crm-storage/production

I hope this tutorial is instructive and please add a comment if you have any questions corrections.  Also feel free to contact me directly if you prefer:

Shad Mickelberry

Email: shad@jackalsoftware.com

Web: https://jackalsoftware.com

October 17th, 2016

Posted In: Digital Ocean, SugarCRM, SuiteCRM

Leave a Comment