diff --git a/deployment/setup.sh b/deployment/setup_18.04.sh similarity index 78% rename from deployment/setup.sh rename to deployment/setup_18.04.sh index 7c19b6b40..cacd995e9 100644 --- a/deployment/setup.sh +++ b/deployment/setup_18.04.sh @@ -1,9 +1,8 @@ #!/usr/bin/env bash -#description: chatwoot installation script -#OS: Ubuntu 18.04 LTS -#script_version: 0.1 - +# Description: Chatwoot installation script +# OS: Ubuntu 18.04 LTS +# Script Version: 0.2 apt update && apt upgrade -y apt install -y curl @@ -13,14 +12,13 @@ echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.lis apt update apt install -y \ - git-core software-properties-common imagemagick libpq-dev \ + git software-properties-common imagemagick libpq-dev \ libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \ - libssl-dev libyaml-dev libreadline6-dev gnupg2 nginx redis-server \ + libssl-dev libyaml-dev libreadline-dev gnupg2 nginx redis-server \ redis-tools postgresql postgresql-contrib certbot \ - python-certbot-nginx yarn patch ruby-dev zlib1g-dev liblzma-dev \ + python-certbot-nginx nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \ libgmp-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev - adduser --disabled-login --gecos "" chatwoot sudo -i -u chatwoot bash << EOF @@ -67,7 +65,6 @@ RAILS_ENV=production bundle exec rake db:reset rake assets:precompile RAILS_ENV=production EOF - cp /home/chatwoot/chatwoot/deployment/chatwoot-web.1.service /etc/systemd/system/chatwoot-web.1.service cp /home/chatwoot/chatwoot/deployment/chatwoot-worker.1.service /etc/systemd/system/chatwoot-worker.1.service cp /home/chatwoot/chatwoot/deployment/chatwoot.target /etc/systemd/system/chatwoot.target @@ -75,7 +72,8 @@ cp /home/chatwoot/chatwoot/deployment/chatwoot.target /etc/systemd/system/chatwo systemctl enable chatwoot.target systemctl start chatwoot.target -echo "Woot! Woot!! Chatwoot installation is complete." -echo "Goto http://:3000" +echo "Woot! Woot!! Chatwoot server installation is complete" +echo "The server will be accessible at http://:3000" +echo "To configure a domain and SSL certificate, follow the guide at https://www.chatwoot.com/docs/deployment/deploy-chatwoot-in-linux-vm" -#TODO: nginx +# TODO: Auto-configure Nginx with SSL certificate diff --git a/deployment/setup_20.04.sh b/deployment/setup_20.04.sh new file mode 100644 index 000000000..6541b6a5e --- /dev/null +++ b/deployment/setup_20.04.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# Description: Chatwoot installation script +# OS: Ubuntu 20.04 LTS / Ubuntu 20.10 +# Script Version: 0.2 + +apt update && apt upgrade -y +apt install -y curl +curl -sL https://deb.nodesource.com/setup_12.x | bash - +curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +apt update + +apt install -y \ + git software-properties-common imagemagick libpq-dev \ + libxml2-dev libxslt1-dev file g++ gcc autoconf build-essential \ + libssl-dev libyaml-dev libreadline-dev gnupg2 nginx redis-server \ + redis-tools postgresql postgresql-contrib certbot \ + python3-certbot-nginx nodejs yarn patch ruby-dev zlib1g-dev liblzma-dev \ + libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev + +adduser --disabled-login --gecos "" chatwoot + +sudo -i -u chatwoot bash << EOF +gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB +curl -sSL https://get.rvm.io | bash -s stable +EOF + +pg_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 15 ; echo '') +sudo -i -u postgres psql << EOF +\set pass `echo $pg_pass` +CREATE USER chatwoot CREATEDB; +ALTER USER chatwoot PASSWORD :'pass'; +ALTER ROLE chatwoot SUPERUSER; +EOF + +systemctl enable redis-server.service +systemctl enable postgresql + +secret=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 63 ; echo '') +RAILS_ENV=production + +sudo -i -u chatwoot << EOF +rvm --version +rvm autolibs disable +rvm install "ruby-2.7.1" +rvm use 2.7.1 --default + +git clone https://github.com/chatwoot/chatwoot.git +cd chatwoot +git checkout master +bundle +yarn + +cp .env.example .env +sed -i -e "/SECRET_KEY_BASE/ s/=.*/=$secret/" .env +sed -i -e '/REDIS_URL/ s/=.*/=redis:\/\/localhost:6379/' .env +sed -i -e '/POSTGRES_HOST/ s/=.*/=localhost/' .env +sed -i -e '/POSTGRES_USERNAME/ s/=.*/=chatwoot/' .env +sed -i -e "/POSTGRES_PASSWORD/ s/=.*/=$pg_pass/" .env +sed -i -e '/RAILS_ENV/ s/=.*/=$RAILS_ENV/' .env + +RAILS_ENV=production bundle exec rake db:create +RAILS_ENV=production bundle exec rake db:reset +rake assets:precompile RAILS_ENV=production +EOF + +cp /home/chatwoot/chatwoot/deployment/chatwoot-web.1.service /etc/systemd/system/chatwoot-web.1.service +cp /home/chatwoot/chatwoot/deployment/chatwoot-worker.1.service /etc/systemd/system/chatwoot-worker.1.service +cp /home/chatwoot/chatwoot/deployment/chatwoot.target /etc/systemd/system/chatwoot.target + +systemctl enable chatwoot.target +systemctl start chatwoot.target + +echo "Woot! Woot!! Chatwoot server installation is complete" +echo "The server will be accessible at http://:3000" +echo "To configure a domain and SSL certificate, follow the guide at https://www.chatwoot.com/docs/deployment/deploy-chatwoot-in-linux-vm" + +# TODO: Auto-configure Nginx with SSL certificate diff --git a/docs/README.md b/docs/README.md index 7f2b5d20c..6bbd7194b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,7 +11,6 @@ This guide will help you get started with Chatwoot! * [Ubuntu](/docs/installation-guide-ubuntu) * [Windows](/docs/installation-guide-windows) * [Docker](/docs/installation-guide-docker) -* ### Project Setup diff --git a/docs/deployment/production/linux-vm.md b/docs/deployment/production/linux-vm.md index 3ae5da258..0aeb94b2c 100644 --- a/docs/deployment/production/linux-vm.md +++ b/docs/deployment/production/linux-vm.md @@ -1,43 +1,62 @@ --- path: "/docs/deployment/deploy-chatwoot-in-linux-vm" -title: "Linux VM Chatwoot Production deployment guide" +title: "Production deployment guide for Linux VM" --- - ### Deploying to Linux VM -We have prepared a deployment script for ubuntu 18.04. Run the script or refer the script and make changes accordingly to OS. +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. -https://github.com/chatwoot/chatwoot/blob/develop/deployment/setup.sh +For **Ubuntu 18.04**, use the following script -### After logging in to your Linux VM as the root user perform the following steps for initial set up +```bash +https://raw.githubusercontent.com/chatwoot/chatwoot/develop/deployment/setup_18.04.sh +``` -1. Create the `chatwoot.sh` file and copy the content from [deployment script](https://github.com/chatwoot/chatwoot/blob/develop/deployment/setup.sh). -2. Execute the script and it will take care of the initial Chatwoot setup -3. Chatwoot Installation will now be accessible at `http://{your_ip}:3000` +For **Ubuntu 20.04** or **Ubuntu 20.10**, use the following script. -### Configure ngix and letsencrypt +```bash +https://raw.githubusercontent.com/chatwoot/chatwoot/develop/deployment/setup_20.04.sh +``` -1. configure Nginx to serve as a frontend proxy by following steps in your shell +### Steps to install + +1. Create a **setup.sh** file and copy the content from the above link or use the following commands. + +```bash +wget -O setup.sh +chmod 755 setup.sh +./setup.sh +``` + +2. Execute the script and it will take care of the initial **Chatwoot** setup. + +3. **Chatwoot** Installation will now be accessible at `http://{your_ip_address}:3000` + +### Configure Nginx and **Let's Encrypt** + +1. Configure Nginx to serve as a frontend proxy. ```bash cd /etc/nginx/sites-enabled nano yourdomain.com.conf ``` -2. Add the required Nginx config after replacing the `yourdomain.com` in `server_name`. +2. Use the following Nginx config after replacing the `yourdomain.com` in `server_name` . ```bash server { - server_name yourdomain.com; - # where rails app is running - set $upstream 127.0.0.1:3000; - underscores_in_headers on; + server_name ; - # Here we define the web-root for our SSL proof + # Point upstream to Chatwoot App Server + set $upstream 127.0.0.1:3000; + + # 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; location /.well-known { - # Note that a request for /.well-known/test.html will be made - alias /var/www/ssl-proof/chatwoot/.well-known; + alias /var/www/ssl-proof/chatwoot/.well-known; } location / { @@ -48,11 +67,14 @@ server { proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Ssl on; # Optional + proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_http_version 1.1; proxy_set_header Connection “”; proxy_buffering off; + client_max_body_size 0; proxy_read_timeout 36000s; proxy_redirect off; @@ -63,63 +85,69 @@ server { 3. Verify and reload your Nginx config by running following command. -```sh +```bash nginx -t systemctl reload nginx ``` -4. Run Letsencrypt and configure SSL +4. Run **Let's Encrypt** and configure **SSL certificate**. -```sh +```bash mkdir -p /var/www/ssl-proof/chatwoot/.well-known -certbot --webroot -w /var/www/ssl-proof/chatwoot/ -d yourdomain.com -i nginx +certbot --webroot -w /var/www/ssl-proof/chatwoot/ -d yourdomain.com -i nginx ``` -5. You Chatwoot installation should be accessible from the `https://yourdomain.com` now. +5. Your Chatwoot installation should be accessible from the `https://yourdomain.com` now. ### Configure the required environment variables -For your chatwoot installation to properly function you would need to configure some of the essential environment variables like `FRONTEND_URL`, mailer and storage config etc. refer [environment variables](https://www.chatwoot.com/docs/environment-variables) for the full list. +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. +1. Login as **Chatwoot** and edit the .env file. + +```bash +# Login as chatwoot user -```shell -# login as chatwoot user  sudo -i -u chatwoot cd chatwoot nano .env ``` -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 Chatwoot. -```sh +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 systemctl restart chatwoot.target ``` -### Updating your Chatwoot Installation on a Linux VM +### Upgrading to newer version of Chatwoot -Run the following steps on your VM if you made use of our installation script Or making changes accordingly to your OS +Whenever a new version of Chatwoot is released, use the following steps to upgrade your instance. -``` -# login as chatwoot user  +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 sudo -i -u chatwoot -# navigate to the chatwoot directory -cd chatwoot  +# Navigate to the Chatwoot directory +cd chatwoot -# pull the latest version of the master branch -git pull +# Pull the latest version of the master branch +git checkout master && git pull -# update dependencies  +# Update dependencies bundle yarn -# recompile the assets  +# Recompile the assets rake assets:precompile RAILS_ENV=production -# migrate the database schema +# Migrate the database schema RAILS_ENV=production bundle exec rake db:migrate -#Restart the chatwoot server +# Restart the chatwoot server systemctl restart chatwoot.target + ```