2020-06-11 17:04:22 +00:00
---
path: "/docs/deployment/deploy-chatwoot-in-linux-vm"
2020-10-25 17:10:13 +00:00
title: "Production deployment guide for Linux VM"
2020-06-11 17:04:22 +00:00
---
2020-07-06 05:07:51 +00:00
### Deploying to Linux VM
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
This guide will help you to install **Chatwoot** on **Ubuntu 18.04 LTS / 20.04 LTS / 20.10** . We have prepared a deployment script for you to run. Refer the script and feel free to make changes accordingly to OS if you are on a non-Ubuntu system.
For **Ubuntu 18.04** , use the following script
```bash
https://raw.githubusercontent.com/chatwoot/chatwoot/develop/deployment/setup_18.04.sh
```
For **Ubuntu 20.04** or **Ubuntu 20.10** , use the following script.
```bash
https://raw.githubusercontent.com/chatwoot/chatwoot/develop/deployment/setup_20.04.sh
```
### Steps to install
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
1. Create a **setup.sh** file and copy the content from the above link or use the following commands.
```bash
wget < link-to-script > -O setup.sh
chmod 755 setup.sh
./setup.sh
```
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
2. Execute the script and it will take care of the initial **Chatwoot** setup.
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
3. **Chatwoot** Installation will now be accessible at `http://{your_ip_address}:3000`
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
### Configure Nginx and **Let's Encrypt**
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
1. Configure Nginx to serve as a frontend proxy.
2020-06-11 17:04:22 +00:00
```bash
cd /etc/nginx/sites-enabled
nano yourdomain.com.conf
```
2020-07-06 05:07:51 +00:00
2020-10-25 17:10:13 +00:00
2. Use the following Nginx config after replacing the `yourdomain.com` in `server_name` .
2020-07-06 05:07:51 +00:00
```bash
2020-06-11 17:04:22 +00:00
server {
2020-10-25 17:10:13 +00:00
server_name < yourdomain.com > ;
# Point upstream to Chatwoot App Server
2020-06-11 17:04:22 +00:00
set $upstream 127.0.0.1:3000;
2020-10-25 17:10:13 +00:00
# Nginx strips out underscore in headers by default
# Chatwoot relies on underscore in headers for API
# Make sure that the config is turned on.
underscores_in_headers on;
2020-06-11 17:04:22 +00:00
location /.well-known {
2020-10-25 17:10:13 +00:00
alias /var/www/ssl-proof/chatwoot/.well-known;
2020-06-11 17:04:22 +00:00
}
2020-07-06 05:07:51 +00:00
2020-06-11 17:04:22 +00:00
location / {
proxy_pass_header Authorization;
proxy_pass http://$upstream;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Ssl on; # Optional
2020-10-25 17:10:13 +00:00
2020-06-11 17:04:22 +00:00
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2020-10-25 17:10:13 +00:00
2020-06-11 17:04:22 +00:00
proxy_http_version 1.1;
proxy_set_header Connection “”;
proxy_buffering off;
2020-10-25 17:10:13 +00:00
2020-06-11 17:04:22 +00:00
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_redirect off;
}
listen 80;
}
```
2020-07-06 05:07:51 +00:00
2020-06-11 17:04:22 +00:00
3. Verify and reload your Nginx config by running following command.
2020-07-06 05:07:51 +00:00
2020-10-25 17:10:13 +00:00
```bash
2020-06-11 17:04:22 +00:00
nginx -t
systemctl reload nginx
```
2020-07-06 05:07:51 +00:00
2020-10-25 17:10:13 +00:00
4. Run **Let's Encrypt** and configure **SSL certificate** .
2020-07-06 05:07:51 +00:00
2020-10-25 17:10:13 +00:00
```bash
2020-06-11 17:04:22 +00:00
mkdir -p /var/www/ssl-proof/chatwoot/.well-known
2020-10-25 17:10:13 +00:00
certbot --webroot -w /var/www/ssl-proof/chatwoot/ -d yourdomain.com -i nginx
2020-06-11 17:04:22 +00:00
```
2020-10-25 17:10:13 +00:00
5. Your Chatwoot installation should be accessible from the `https://yourdomain.com` now.
2020-06-11 17:04:22 +00:00
2020-07-06 05:07:51 +00:00
### Configure the required environment variables
2020-10-25 17:10:13 +00:00
For your Chatwoot installation to properly function you would need to configure some of the essential environment variables like `FRONTEND_URL` , Mailer and a cloud storage config. Refer ** [Environment variables ](https://www.chatwoot.com/docs/environment-variables )** for the full list.
1. Login as **Chatwoot** and edit the .env file.
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
```bash
# Login as chatwoot user
2020-07-06 05:07:51 +00:00
2020-06-11 17:04:22 +00:00
sudo -i -u chatwoot
cd chatwoot
nano .env
```
2020-07-06 05:07:51 +00:00
2020-10-25 17:10:13 +00:00
2. Refer ** [Environment variables ](https://www.chatwoot.com/docs/environment-variables )** and update the required variables. Save the `.env` file.
3. Restart the **Chatwoot** server and enjoy using your self hosted Chatwoot.
```bash
2020-06-11 17:04:22 +00:00
systemctl restart chatwoot.target
```
2020-07-06 05:07:51 +00:00
2020-10-25 17:10:13 +00:00
### Upgrading to newer version of Chatwoot
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
Whenever a new version of Chatwoot is released, use the following steps to upgrade your instance.
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
Run the following steps on your VM. Make changes based o your OS if you are on a non-Ubuntu system.
```bash
# Login as Chatwoot user
2020-06-11 17:04:22 +00:00
sudo -i -u chatwoot
2020-10-25 17:10:13 +00:00
# Navigate to the Chatwoot directory
cd chatwoot
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
# Pull the latest version of the master branch
git checkout master & & git pull
2020-06-11 17:04:22 +00:00
2020-10-25 17:10:13 +00:00
# Update dependencies
2020-07-06 05:07:51 +00:00
bundle
2020-06-11 17:04:22 +00:00
yarn
2020-10-25 17:10:13 +00:00
# Recompile the assets
2020-06-11 17:04:22 +00:00
rake assets:precompile RAILS_ENV=production
2020-10-25 17:10:13 +00:00
# Migrate the database schema
2020-06-11 17:04:22 +00:00
RAILS_ENV=production bundle exec rake db:migrate
2020-10-25 17:10:13 +00:00
# Restart the chatwoot server
2020-06-11 17:04:22 +00:00
systemctl restart chatwoot.target
2020-10-25 17:10:13 +00:00
2020-06-11 17:04:22 +00:00
```