From 1c7fb19d76d1cf451d1b69a18aa54e669a86f6c7 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Wed, 15 May 2019 15:13:26 +0200 Subject: [PATCH 1/9] Initial commit for new Digital Ocean Deployment Docs --- docs/3.x.x/guides/deployment.md | 63 +++++++++++++++++++++++++-------- docs/package-lock.json | 41 +++++++++++++++------ 2 files changed, 79 insertions(+), 25 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index 6838b50048..35d0bb3527 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -2,15 +2,15 @@ Strapi gives you many possible deployment options for your project or application. Strapi can be deployed on traditional hosting servers or services such as Heroku, AWS, Azure and others. The following documentation covers how to develop locally with Strapi and deploy Strapi with various hosting options. - - (Deploying **databases** along with Strapi is covered in the [Databases Guide](/3.x.x/guides/databases.html).) **Table of contents:** - [Configuration](#configuration) +- [Digital Ocean](#digital-ocean) - [Heroku](#heroku) - [Docker](#docker) + --- ## Configuration @@ -20,6 +20,7 @@ Strapi gives you many possible deployment options for your project or applicatio Update the `production` settings with the IP and domain name where the project will be running. **Path —** `./config/environments/production/server.json`. + ```js { "host": "domain.io", // IP or domain @@ -33,12 +34,13 @@ Update the `production` settings with the IP and domain name where the project w } ``` -In case your database is not running on the same server, make sure that the environment of your production +In case your database is not running on the same server, make sure that the environment of your production database (`./config/environments/production/database.json`) is set properly. If you are passing a number of configuration item values via environment variables which is always encouraged for production environment to keep application stateless, checkout the section for [Dynamic Configuration](../configurations/configurations.md#dynamic-configurations). Here is a hint on how to do it for production, for the configuration mentioned above: - - **Path —** `./config/environments/production/server.json`. + +**Path —** `./config/environments/production/server.json`. + ```js { "host": "${process.env.APP_HOST || '127.0.0.1'}" @@ -52,7 +54,7 @@ If you are passing a number of configuration item values via environment variabl } ``` -**⚠️ If you changed the path to access to the administration, the step #2 is required.** +**⚠️ If you changed the path to access to the administration, the step #2 is required.** #### #2 - Setup (optional) @@ -83,9 +85,38 @@ We highly recommend to use [pm2](https://github.com/Unitech/pm2/) to manage your If you want to host the administration on another server than the API, [please take a look at this dedicated section](../advanced/customize-admin.md#deployment). +## Digital Ocean + +This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be used locally on the server or hosted externally as a service. + +### Digital Ocean Install Requirements + +- You must have a [Digital Ocean account](https://cloud.digitalocean.com/registrations/new) before doing these steps. + +### Create a Droplet + +Digital Ocean calls a virtual private server, a **Droplet**. You need to create a new `Droplet` to host your Strapi project. + +1. Log in to your [Digital Ocean account](https://cloud.digitalocean.com/login). +2. `Create a Droplet` by clicking on `New Droplet`. Choose these options: + +- Ubuntu 18.04 x64 +- STARTER `Standard` +- Pricing: \$5/mo _(Scroll to the left)_ +- Choose a datacenter region nearest your audience, for example, `Frankfurt`. +- Select additional options:`[x] IPv6` +- Add your SSH key **NOTE:** We recommend adding your SSH key + - Copy to your clipboard, your existing SSH public key with `pbcopy < ~/.ssh/id_rsa.pub`. + - Click on `New SSH Key` and paste in your `SSH Key`. Name this key and Save. + Additional instructions on creating and using SSH Keys can be found [here](https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-openssh/). +- `Choose a hostname` or leave as-is. +- Click the green `Create` button. + +You may continue after **Digital Ocean** has finished created your **Droplet** as indicated by the progress bar. + ## Heroku -This is a step-by-step guide for deploying a Strapi project on [Heroku](https://www.heroku.com/). Databases that work well with Strapi and Heroku are provided instructions on how to get started. +This is a step-by-step guide for deploying a Strapi project to [Heroku](https://www.heroku.com/). Databases that work well with Strapi and Heroku are provided instructions on how to get started. ### Heroku Install Requirements @@ -108,6 +139,7 @@ Also available via Homebrew: ```bash brew tap heroku/brew && brew install heroku ``` + ::: ::: tab "Ubuntu" @@ -116,6 +148,7 @@ Run the following from your terminal: ```bash sudo snap install --classic heroku ``` + ::: ::: tab "Windows" @@ -135,7 +168,7 @@ Next, you need to login to Heroku from your computer. heroku login ``` -Follow the instructions and return to your command line. +Follow the instructions and return to your command line. ### 3. Create a new project (or use an existing one) @@ -177,7 +210,7 @@ Init the Git repository and commit yoru project. cd my-project git init git add . -git commit -am "Initial Commit" +git commit -am "Initial Commit" ``` ### 6. Create a Heroku project @@ -190,7 +223,7 @@ Create a new Heroku project. heroku create ``` -(You can use `heroku create custom-project-name`, to have Heroku create a `custom-project-name.heroku.com` URL. Otherwise, Heroku will automatically generating a random project name (and URL) for you.) +(You can use `heroku create custom-project-name`, to have Heroku create a `custom-project-name.heroku.com` URL. Otherwise, Heroku will automatically generating a random project name (and URL) for you.) ::: warning NOTE If you have a Heroku project app already created. You would use the following step to initialize your local project folder: @@ -200,13 +233,14 @@ If you have a Heroku project app already created. You would use the following st ```bash heroku git:remote -a your-heroku-app-name ``` + ::: Your local development environment is now set-up and configured to work with Heroku. You have a new Strapi project and a new Heroku app ready to be configured to work with a database and with each other. ### 7. Heroku Database set-up -Below you will find database options when working with Heroku. Please choose the correct database (e.g. PostgreSQL, MongoDB, etc.) and follow those instructions. +Below you will find database options when working with Heroku. Please choose the correct database (e.g. PostgreSQL, MongoDB, etc.) and follow those instructions. :::: tabs cache-lifetime="10" :options="{ useUrlFragment: false }" @@ -238,7 +272,7 @@ heroku config This should print something like this: `DATABASE_URL: postgres://ebitxebvixeeqd:dc59b16dedb3a1eef84d4999sb4baf@ec2-50-37-231-192.compute-2.amazonaws.com: 5432/d516fp1u21ph7b`. -(This url is read like so: *postgres:// **USERNAME** : **PASSWORD** @ **HOST** : **PORT** : **DATABASE_NAME***) +(This url is read like so: \*postgres:// **USERNAME** : **PASSWORD** @ **HOST** : **PORT** : **DATABASE_NAME\***) ##### 3. Set environment variables @@ -286,6 +320,7 @@ Replace the contents of `database.json` with the following: Unless you originally installed Strapi with PostgreSQL, you need to install the [pg](https://www.npmjs.com/package/pg) node module. `Path: ./my-project/` + ```bash npm install pg --save ``` @@ -302,11 +337,10 @@ Please follow these steps the **deploy a Strapi app with MongoDB on Heroku**. You must have completed the [steps to use Strapi with MongoDB Atlas in production](/3.x.x/guides/databases.html#install-on-atlas-mongodb-atlas). - ##### 1. Set environment variables When you [set-up your MongoDB Atlas database](/3.x.x/guides/databases.html#install-on-atlas-mongodb-atlas) you created and noted the five key/value pairs that correspond to your **MongoDB Atlas** database. These five keys are: `DATABASE_NAME`, `DATABASE_USERNAME`, `DATABASE_PASSWORD`, `DATABASE PORT`, and `DATABASE_HOST`. - + Strapi expects a variable for each database connection detail (host, username, etc.). So, from **MongoDB Atlas**, you have to set the environment variables in the Heroku config (for **DATABASE_HOST** you need to surround the URL with **""**, and set **DATABASE_PORT** to nothing): ```bash @@ -316,6 +350,7 @@ heroku config:set DATABASE_HOST="stapi-mongo-heroku-shard-00-00-fty6c.mongodb.ne heroku config:set DATABASE_PORT= heroku config:set DATABASE_NAME=strapi-mongo-heroku ``` + **Note:** Please replace these above values with the your actual values. ##### 2. Update your database config file diff --git a/docs/package-lock.json b/docs/package-lock.json index 3e309c9cf8..c865333884 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -4220,7 +4220,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -4238,11 +4239,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4255,15 +4258,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -4366,7 +4372,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -4376,6 +4383,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4388,17 +4396,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4415,6 +4426,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4487,7 +4499,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4497,6 +4510,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4572,7 +4586,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4602,6 +4617,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4619,6 +4635,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4657,11 +4674,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.3", - "bundled": true + "bundled": true, + "optional": true } } }, From c06e974ddbe352298dad87f4dc350cc7eeae5329 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Wed, 15 May 2019 16:02:43 +0200 Subject: [PATCH 2/9] Setup production server instructions added --- docs/3.x.x/guides/deployment.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index 35d0bb3527..bb26ca24b3 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -114,6 +114,18 @@ Digital Ocean calls a virtual private server, a **Droplet**. You need to create You may continue after **Digital Ocean** has finished created your **Droplet** as indicated by the progress bar. +### Setup production server and install Node.js + +These next steps involved setting up a production server and user access for development. Continue these steps after you [the create an initial Droplet](/3.x.x/guides/deployment.html#create-a-droplet) steps. + +Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These steps will have you complete the following steps: + +1. Logging and set up root user access to your server with SSH. +2. Creating a new user. +3. Granting Administrative Privileges to the new user. +4. Setting up a basic firewall. +5. Allowing your regular user access to the server **with SSH key authentication**. + ## Heroku This is a step-by-step guide for deploying a Strapi project to [Heroku](https://www.heroku.com/). Databases that work well with Strapi and Heroku are provided instructions on how to get started. From 740a3536c915dd13ff931bb973e9abdcd6774839 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Wed, 15 May 2019 16:40:13 +0200 Subject: [PATCH 3/9] a few additional steps through installing Strapi --- docs/3.x.x/guides/deployment.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index bb26ca24b3..46febb8d99 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -118,7 +118,7 @@ You may continue after **Digital Ocean** has finished created your **Droplet** a These next steps involved setting up a production server and user access for development. Continue these steps after you [the create an initial Droplet](/3.x.x/guides/deployment.html#create-a-droplet) steps. -Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These steps will have you complete the following steps: +Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These steps will have you complete the following actions: 1. Logging and set up root user access to your server with SSH. 2. Creating a new user. @@ -126,6 +126,29 @@ Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 1 4. Setting up a basic firewall. 5. Allowing your regular user access to the server **with SSH key authentication**. +Next, you should follow the official [Digital Ocean docs for installed a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04). + +You need to jump to section to `Install Node using a PPA`. Strapi works best on **Node.js v10+**. After completing the steps to **install Node.js and NPM**, you may continue to the next section. + +### Install the database for your project + +Digital Ocean has excellent documentation regarding the installation and use of the major databases that work with Strapi. The previous steps above should all be complete prior to continuing. You can find links to each database guide below: + +1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04). Ensure that you create a new `Postgres user and database`. After you have created your database, you may continue to [Strapi installation](#install-and-configure-strapi-globally). +2. + +### Install and Configure Strapi globally + +The next steps will install Strapi globally onto your server. + +Log into your server with your non-root user. + +1. Install Strapi globally: + +```bash +sudo npm install -g strapi@alpha +``` + ## Heroku This is a step-by-step guide for deploying a Strapi project to [Heroku](https://www.heroku.com/). Databases that work well with Strapi and Heroku are provided instructions on how to get started. From 8b46ad66e84840ddb11035c56e0b18845b860b94 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Wed, 15 May 2019 19:00:34 +0200 Subject: [PATCH 4/9] installation through using git updated --- docs/3.x.x/guides/deployment.md | 58 +++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index 46febb8d99..7ca1d59439 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -130,25 +130,63 @@ Next, you should follow the official [Digital Ocean docs for installed a product You need to jump to section to `Install Node using a PPA`. Strapi works best on **Node.js v10+**. After completing the steps to **install Node.js and NPM**, you may continue to the next section. +### Install Git versioning + ### Install the database for your project Digital Ocean has excellent documentation regarding the installation and use of the major databases that work with Strapi. The previous steps above should all be complete prior to continuing. You can find links to each database guide below: -1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04). Ensure that you create a new `Postgres user and database`. After you have created your database, you may continue to [Strapi installation](#install-and-configure-strapi-globally). -2. +1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04). Ensure that you create a new `Postgres user and database` (Through Step 4 - Creating a New Database). -### Install and Configure Strapi globally - -The next steps will install Strapi globally onto your server. - -Log into your server with your non-root user. - -1. Install Strapi globally: +In order for Strapi connect with a PostgreSQL database it needs either to have a password, or to have specifically stated there is no password. From your server terminal as your `sudo user`, you will `alter` the user you created and `add a password`: ```bash -sudo npm install -g strapi@alpha +sudo -u postgres psql +[sudo] password for your-name: +psql (10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)) +Type "help" for help. +postgres=# ALTER USER your-name PASSWORD 'password'; +ALTER ROLE +postgres=# \q ``` +You will need the database name, username and password in order to continue to [configure that database.json file](#local-development-configuration). + +Your server is now set-up and ready to pull your Strapi Project from your GitHub repository. There are just a few more steps, in development, to complete prior to continuing. + +2. Install MongoDB + +### Local Development Configuration + +- You must have [Git installed and set-up locally](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup). +- You must have created a repository for your Strapi Project and have your development project initilized to this repository. + +In your code editor, you will need to edit a file called `database.json`. Replace the contents of the file with the following, but change the `username`, `password` and `database` to match your installation. + +`Path: ./config/environments/production` + +```json +{ + "defaultConnection": "default", + "connections": { + "postgres": { + "connector": "strapi-hook-bookshelf", + "settings": { + "client": "postgres", + "host": "localhost", + "port": 5432, + "username": "david", + "password": "password", + "database": "strapi" + }, + "options": {} + } + } +} +``` + +`npm install pg` + ## Heroku This is a step-by-step guide for deploying a Strapi project to [Heroku](https://www.heroku.com/). Databases that work well with Strapi and Heroku are provided instructions on how to get started. From b49752ea28b5e31648921ccf2a78e7c7cdb88778 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Thu, 16 May 2019 19:13:32 +0200 Subject: [PATCH 5/9] all basic steps to install on digital ocean complete --- docs/3.x.x/guides/deployment.md | 115 +++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 16 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index 7ca1d59439..b35500a736 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -87,15 +87,15 @@ If you want to host the administration on another server than the API, [please t ## Digital Ocean -This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be used locally on the server or hosted externally as a service. +This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be used locally on the server or hosted externally as a service. Prior to starting this guide, you should have created a [Strapi project for development](/3.x.x/getting-started/quick-start.html) that can be pushed to the Digital Ocean server. ### Digital Ocean Install Requirements - You must have a [Digital Ocean account](https://cloud.digitalocean.com/registrations/new) before doing these steps. -### Create a Droplet +### Create a "Droplet" -Digital Ocean calls a virtual private server, a **Droplet**. You need to create a new `Droplet` to host your Strapi project. +Digital Ocean calls a virtual private server, a [Droplet](https://www.digitalocean.com/docs/droplets/). You need to create a new `Droplet` to host your Strapi project. 1. Log in to your [Digital Ocean account](https://cloud.digitalocean.com/login). 2. `Create a Droplet` by clicking on `New Droplet`. Choose these options: @@ -112,11 +112,11 @@ Digital Ocean calls a virtual private server, a **Droplet**. You need to create - `Choose a hostname` or leave as-is. - Click the green `Create` button. -You may continue after **Digital Ocean** has finished created your **Droplet** as indicated by the progress bar. +You may continue after **Digital Ocean** has finished creating your **Droplet** as indicated by the progress bar. ### Setup production server and install Node.js -These next steps involved setting up a production server and user access for development. Continue these steps after you [the create an initial Droplet](/3.x.x/guides/deployment.html#create-a-droplet) steps. +These next steps involved setting up a production server and user access for development. Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These steps will have you complete the following actions: @@ -124,35 +124,67 @@ Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 1 2. Creating a new user. 3. Granting Administrative Privileges to the new user. 4. Setting up a basic firewall. -5. Allowing your regular user access to the server **with SSH key authentication**. +5. Giving your regular user access to the server **with SSH key authentication**. -Next, you should follow the official [Digital Ocean docs for installed a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04). +After completing these steps: -You need to jump to section to `Install Node using a PPA`. Strapi works best on **Node.js v10+**. After completing the steps to **install Node.js and NPM**, you may continue to the next section. +6. You will install `Node.js` using the instructions in section `Install Node using a PPA`. Strapi works best on **Node.js v10+**. Follow the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04). -### Install Git versioning +After completing the steps to **install Node.js, NPM and the build-essential package**, you may continue to the next section. + +### Install Git versioning on your server + +A convenient way to maintain your Strapi application and update it during and after initial development is to use [Git Versioning](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control). In order to use Git Versioning, you will need to have Git installed on your Droplet. Droplets should have Git installed by default, so you will check and if not installed, you will need to install it. + +1. Check to see if `Git` is installed, if you see a `git version 2.x.x` then you have get installed. Check with the following command: + +```bash +git --version +``` + +2. There are two parts to this step: + +- Installing Git - **NOTE:** Only do if not installed, as above. +- [Setting up Git](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04#setting-up-git) + +Please follow these directions on [how to install Git on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04). + +After installing and configuring Git on your Droplet. Please continue to the next step, [installing the database](#install-the-database-for-your-project). ### Install the database for your project -Digital Ocean has excellent documentation regarding the installation and use of the major databases that work with Strapi. The previous steps above should all be complete prior to continuing. You can find links to each database guide below: +Digital Ocean has excellent documentation regarding the installation and use of the major databases that work with Strapi. The previous steps above should all be completed prior to continuing. You can find links, and any further instructions, to each database guide below: -1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04). Ensure that you create a new `Postgres user and database` (Through Step 4 - Creating a New Database). +1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04). -In order for Strapi connect with a PostgreSQL database it needs either to have a password, or to have specifically stated there is no password. From your server terminal as your `sudo user`, you will `alter` the user you created and `add a password`: +- Create a new `Postgres user and database` (Through Step 4 - Creating a New Database). + +- In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically to have stated there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: ```bash -sudo -u postgres psql +sudo -u postgres psql //only necessary if you switched away from the postgres@ user [sudo] password for your-name: psql (10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)) Type "help" for help. + postgres=# ALTER USER your-name PASSWORD 'password'; ALTER ROLE postgres=# \q ``` -You will need the database name, username and password in order to continue to [configure that database.json file](#local-development-configuration). +- **Optional:** If your **Development** Strapi project is using **SQLite**, you will need to install a dependency package called `pg`: -Your server is now set-up and ready to pull your Strapi Project from your GitHub repository. There are just a few more steps, in development, to complete prior to continuing. + - On your **Development** project: + + `Path: ./my-project/` + + ```bash + npm install pg --save + ``` + + **Note:** The `pg` package is automatically installed locally if you choose `PostgreSQL` as the initial database choice when you first set-up Strapi. + +You will need the **database name**, **username** and **password** to continue to the next step of [configuring that database.json file](#local-development-configuration). 2. Install MongoDB @@ -185,7 +217,58 @@ In your code editor, you will need to edit a file called `database.json`. Replac } ``` -`npm install pg` +You are now ready to push these changes to Github: + +```bash +git add . +git commit -m "Configured production/database.json" +git push +``` + +Please continue to the next section, [Deploy from GitHub](#deploy-from-github). + +### Deploy from Github + +You will next deploy your Strapi project to your Droplet by `cloning it from GitHub`. + +From your terminal, `logged in as your non-root user` to your Droplet: + +```bash +cd ~ +sudo git clone https://github.com/your-name/your-project-repo.git +``` + +Next, navigate to the `my-project` folder, the root for Strapi. You will now need to run `sudo npm install` to install the packages for your project, and then `sudo npm run postinstall`. This last command runs scripts that build out your Strapi installation. + +`Path: ./my-project/` + +```bash +sudo npm install && sudo npm run postinstall +``` + +Strapi uses `Port: 1337` by default. You will need to configure your `ufw firewall` to allow access to this port: + +```bash +sudo ufw allow 1337/tcp +``` + +Your Strapi project is now installed on your **Droplet**. You will next need to [install and configure PM2 Runtime](#install-and-configure-pm2-runtime). + +### Install and configure PM2 Runtime + +[PM2 Runtime](https://pm2.io/doc/en/runtime/overview/?utm_source=pm2&utm_medium=website&utm_campaign=rebranding) allows you to keep your Strapi project alive and to reload it without downtime. You will want to install it globally: + +```bash +sudo npm install pm2@latest -g +``` + +Use the following command to set the environment variable to production and start `pm2`: + +```bash +sudo NODE_ENV=production pm2 start --name="strapi" server.js -i max +``` + +Your `Strapi` project is now accessible at: `your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more effecient and to set-up a few additional aspects of your server.  ## Heroku From deb36da5c7af8d2853ad0dd4a509f733ac1254b7 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Fri, 17 May 2019 21:19:37 +0200 Subject: [PATCH 6/9] added full steps and tested the instructions. Now working A to Z. --- docs/3.x.x/guides/deployment.md | 236 +++++++++++++++++++++++++++++--- 1 file changed, 214 insertions(+), 22 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index b35500a736..ef02c444bf 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -120,15 +120,15 @@ These next steps involved setting up a production server and user access for dev Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These steps will have you complete the following actions: -1. Logging and set up root user access to your server with SSH. -2. Creating a new user. -3. Granting Administrative Privileges to the new user. -4. Setting up a basic firewall. -5. Giving your regular user access to the server **with SSH key authentication**. +1. [Logging and set up root user access to your server with SSH](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-1-%E2%80%94-logging-in-as-root). +2. [Creating a new user](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-2-%E2%80%94-creating-a-new-user). +3. [Granting Administrative Privileges to the new user](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-3-%E2%80%94-granting-administrative-privileges). +4. [Setting up a basic firewall](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-4-%E2%80%94-setting-up-a-basic-firewall). +5. [Giving your regular user access to the server](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-5-%E2%80%94-enabling-external-access-for-your-regular-user) **with SSH key authentication**. -After completing these steps: +Next, install `Node.js`: -6. You will install `Node.js` using the instructions in section `Install Node using a PPA`. Strapi works best on **Node.js v10+**. Follow the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04). +6. You will install `Node.js` using the instructions in section `Install Node using a PPA`. Strapi works best on **Node.js v10+**. Follow the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). After completing the steps to **install Node.js, NPM and the build-essential package**, you may continue to the next section. @@ -142,12 +142,9 @@ A convenient way to maintain your Strapi application and update it during and af git --version ``` -2. There are two parts to this step: +2. **OPTIONAL:** Install Git. **NOTE:** Only do if _not installed_, as above. Please follow these directions on [how to install Git on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04). -- Installing Git - **NOTE:** Only do if not installed, as above. -- [Setting up Git](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04#setting-up-git) - -Please follow these directions on [how to install Git on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04). +3. Complete the globel **username** and **GitHub** settings: [Setting up Git](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04#setting-up-git) After installing and configuring Git on your Droplet. Please continue to the next step, [installing the database](#install-the-database-for-your-project). @@ -155,11 +152,11 @@ After installing and configuring Git on your Droplet. Please continue to the nex Digital Ocean has excellent documentation regarding the installation and use of the major databases that work with Strapi. The previous steps above should all be completed prior to continuing. You can find links, and any further instructions, to each database guide below: -1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04). +1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04)(Through **Step 4** - Creating a New Database). -- Create a new `Postgres user and database` (Through Step 4 - Creating a New Database). +Complete the steps to [install PostgreSQL](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-1-%E2%80%94-installing-postgresql), [add a user](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-3-%E2%80%94-creating-a-new-role) and [create a database](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-4-%E2%80%94-creating-a-new-database). -- In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically to have stated there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: +2. In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically to have stated there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: ```bash sudo -u postgres psql //only necessary if you switched away from the postgres@ user @@ -167,14 +164,16 @@ sudo -u postgres psql //only necessary if you switched away from the postgre psql (10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)) Type "help" for help. +psql postgres=# ALTER USER your-name PASSWORD 'password'; ALTER ROLE postgres=# \q +exit ``` - **Optional:** If your **Development** Strapi project is using **SQLite**, you will need to install a dependency package called `pg`: - - On your **Development** project: + - On your **Development** computer: `Path: ./my-project/` @@ -235,20 +234,22 @@ From your terminal, `logged in as your non-root user` to your Droplet: ```bash cd ~ -sudo git clone https://github.com/your-name/your-project-repo.git +git clone https://github.com/your-name/your-project-repo.git ``` -Next, navigate to the `my-project` folder, the root for Strapi. You will now need to run `sudo npm install` to install the packages for your project, and then `sudo npm run postinstall`. This last command runs scripts that build out your Strapi installation. +Next, navigate to the `my-project` folder, the root for Strapi. You will now need to run `npm install` to install the packages for your project, and then `npm run postinstall`. This last command runs scripts that build out your Strapi installation. `Path: ./my-project/` ```bash -sudo npm install && sudo npm run postinstall +cd ./path-to-strapi-root-folder/ +npm install ``` Strapi uses `Port: 1337` by default. You will need to configure your `ufw firewall` to allow access to this port: ```bash +cd ~ sudo ufw allow 1337/tcp ``` @@ -256,19 +257,210 @@ Your Strapi project is now installed on your **Droplet**. You will next need to ### Install and configure PM2 Runtime -[PM2 Runtime](https://pm2.io/doc/en/runtime/overview/?utm_source=pm2&utm_medium=website&utm_campaign=rebranding) allows you to keep your Strapi project alive and to reload it without downtime. You will want to install it globally: +[PM2 Runtime](https://pm2.io/doc/en/runtime/overview/?utm_source=pm2&utm_medium=website&utm_campaign=rebranding) allows you to keep your Strapi project alive and to reload it without downtime. + +Ensure you are logged in as a **non-root** user. You will install **PM2** globally: ```bash sudo npm install pm2@latest -g ``` -Use the following command to set the environment variable to production and start `pm2`: +Navigate to your **Strapi Project folder** and use the following command to set the environment variable to production and start `pm2`: + +`Path: ./my-project/` ```bash sudo NODE_ENV=production pm2 start --name="strapi" server.js -i max ``` -Your `Strapi` project is now accessible at: `your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more effecient and to set-up a few additional aspects of your server.  +Follow these steps to have your app launch on system startup. (**NOTE:** These steps follow the Digital Ocean [documentation for setting up PM2](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04#step-3-%E2%80%94-installing-pm2).) + +- Generate and configure a startup script to launch PM2, it will generate a Startup Script to copy/paste, do so: + +```bash +$ cd ~ +$ sudo pm2 startup systemd + +[PM2] Init System found: systemd +[PM2] To setup the Startup Script, copy/paste the following command: +sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u your-name --hp /home/your-name + +$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u your-name --hp /home/your-name + +[PM2] Init System found: systemd +Platform systemd + +. . . + + +[PM2] [v] Command successfully executed. ++---------------------------------------+ +[PM2] Freeze a process list on reboot via: + $ pm2 save + +[PM2] Remove init script via: + $ pm2 unstartup systemd +``` + +- Next, `Save` the new PM2 process list and environment. Then `Start` the service with `systemctl`: + +```bash +sudo pm2 save + +[PM2] Saving current process list... +[PM2] Successfully saved in /home/your-name/.pm2/dump.pm2 + +``` + +- **OPTIONAL**: You can test to see if the script above works whenever your system reboots with the `sudo reboot` command. You will need to login again with your **non-root user** and then run `pm2 list` and `systemctl status pm2-your-name` to verify everything is working. + +Your `Strapi` project is now accessible at: `your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more efficient and to set-up a few additional aspects of your server.  + +- Lastly, you will need to configure a `ecosystem.config.js` file. It will establish a `watch` for `pm2` and restarts your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/). + + - You will need to open your `nano` editor and then `copy/paste` the following: + +```bash +cd ~ +sudo pm2 init +sudo nano ecosystem.config.js +``` + +- Next, replace the boilerplate content in the file, with the following: + +```js +module.exports = { + apps: [ + { + name: 'your-app-name', + script: '.path-to/your-strapi-app/server.js', + watch: './root-folder/', + }, + ], +}; +``` + +`pm2` is now set-up to watch for any file changes in your project, and will restart the service. + +### Set up a webhook + +Providing that your project is set-up on GitHub, you will need to configure your **Strapi Project Repository** with a webhook. The following articles provide additional information to the steps below: [GitHub Creating Webhooks Guide](https://developer.github.com/webhooks/creating/) and [Digital Ocean Guide to GitHub WebHooks](https://www.digitalocean.com/community/tutorials/how-to-use-node-js-and-github-webhooks-to-keep-remote-projects-in-sync). + +- You will need to access the `Settings` tab for your `Strapi Project Repository`: + + 1. Navigate and click to `Settings` for your repository. + 2. Click on `Webhooks`, then click `Add Webhook`. + 3. The fields are filled out like this: + - Payload URL: Enter `http://your-ip-address:8080` + - Content type: Select `application/json` + - Which events would you like to trigger this webhook: Select `Just the push event` + - Secret: Enter `YourSecret` + - Active: Select the checkbox + 4. Review the fields and click `Add Webhook`. + +- Next, you need to create a `Webhook Script` on your server. These commands create a new file called `webhook.js` which will hold two variables: + +```bash +cd ~ +mkdir NodeWebHooks +cd NodeWebHooks +sudo nano webhook.js +``` + +- In the `nano` editor, copy/paste the following script, but make sure to replace `your_secret_key` and `repo` with the values that correspond to your project, then save and exit: + +```js +var secret = 'your_secret_key'; +var repo = '~/path-to-your-repo/'; + +const http = require('http'); +const crypto = require('crypto'); +const exec = require('child_process').exec; + +http + .createServer(function(req, res) { + req.on('data', function(chunk) { + let sig = + 'sha1=' + + crypto + .createHmac('sha1', secret) + .update(chunk.toString()) + .digest('hex'); + + if (req.headers['x-hub-signature'] == sig) { + exec('cd ' + repo + ' && git pull', (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); + }); + } + }); + + res.end(); + }) + .listen(8080); +``` + +- Allow the port to communicate with outside web traffic for `port 8080`: + +```bash +sudo ufw allow 8080/tcp +``` + +- You may test your **webhook** by following the instructions [here](https://www.digitalocean.com/community/tutorials/how-to-use-node-js-and-github-webhooks-to-keep-remote-projects-in-sync#step-4-testing-the-webhook). + +Earlier you setup `pm2` to start the services (your **Strapi project**) whenever the **Droplet** reboots or is started. You will now do the same for the `webhook` script. + +- Install the webhook as a `Systemd` service + + - Create a `webhook.service` file: + +```bash +cd ~ +sudo nano /etc/systemd/system/webhook.service +``` + +- In the `nano` editor, copy/paste the following script, but make sure to replace `your-name` **in two places** with your username, then save and exit: + +```bash +[Unit] +Description=Github webhook +After=network.target + +[Service] +Environment=NODE_PORT=8080 +Type=simple +User=your-name +ExecStart=/usr/bin/nodejs /home/your-name/NodeWebHooks/webhook.js +Restart=on-failure + +[Install] +WantedBy=multi-user.target +``` + +- Enable and start the new service so it starts when the system boots: + +```bash +sudo systemctl enable webhook.service +sudo systemctl start webhook +``` + +- Check the status of the webhook: + +```bash +sudo systemctl status webhook +``` + +### Further steps to take + +- You can **add a domain name** or **use a subdomain name** for your Strapi project, you will need to [install NGINX and configure it](https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04). +- To **install SSL**, you will need to [install and run Certbot by Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04). +- Set-up [Nginx with HTTP/2 Support](https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-with-http-2-support-on-ubuntu-18-04) for Ubuntu 18.04. + +Your `Strapi` project has been installed on a **Digital Ocean Droplet** using **Ubuntu 18.04**. ## Heroku From b0d4c4a19edd6aa1d56d8ecca851a10b84be17a0 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Mon, 20 May 2019 19:18:03 +0200 Subject: [PATCH 7/9] revisions and QC --- docs/3.x.x/guides/deployment.md | 106 ++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 27 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index ef02c444bf..29ddda3da6 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -87,7 +87,7 @@ If you want to host the administration on another server than the API, [please t ## Digital Ocean -This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be used locally on the server or hosted externally as a service. Prior to starting this guide, you should have created a [Strapi project for development](/3.x.x/getting-started/quick-start.html) that can be pushed to the Digital Ocean server. +This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be on a [Digital Ocean Droplet](https://www.digitalocean.com/docs/droplets/) or hosted externally as a service. Prior to starting this guide, you should have created a [Strapi project for development](/3.x.x/getting-started/quick-start.html). ### Digital Ocean Install Requirements @@ -102,17 +102,17 @@ Digital Ocean calls a virtual private server, a [Droplet](https://www.digitaloce - Ubuntu 18.04 x64 - STARTER `Standard` -- Pricing: \$5/mo _(Scroll to the left)_ -- Choose a datacenter region nearest your audience, for example, `Frankfurt`. -- Select additional options:`[x] IPv6` -- Add your SSH key **NOTE:** We recommend adding your SSH key - - Copy to your clipboard, your existing SSH public key with `pbcopy < ~/.ssh/id_rsa.pub`. - - Click on `New SSH Key` and paste in your `SSH Key`. Name this key and Save. - Additional instructions on creating and using SSH Keys can be found [here](https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-openssh/). -- `Choose a hostname` or leave as-is. +- Choose an appropriate pricing plan. For example, pricing: `$5/mo` _(Scroll to the left)_ +- Choose a `datacenter` region nearest your audience, for example, `Frankfurt`. +- **OPTIONAL:** Select additional options, for example, `[x] IPv6`. +- Add your SSH key **NOTE:** We recommend you `add your SSH key` for better security. + - In your terminal, use `pbcopy < ~/.ssh/id_rsa.pub` to copy your existing SSH public key, on your development computer, to the clipboard. + - Click on `New SSH Key` and paste in your `SSH Key`. `Name` this SSH key and then `Save`. + (Additional instructions on creating and using SSH Keys can be found [here](https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-openssh/).) +- **OPTIONAL:** `Choose a hostname` or leave as-is. - Click the green `Create` button. -You may continue after **Digital Ocean** has finished creating your **Droplet** as indicated by the progress bar. +**Digital Ocean** will create your **Droplet** and indicate the progress with a percentage bar. You may continue to the next steps, once this is complete. ### Setup production server and install Node.js @@ -128,15 +128,15 @@ Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 1 Next, install `Node.js`: -6. You will install `Node.js` using the instructions in section `Install Node using a PPA`. Strapi works best on **Node.js v10+**. Follow the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). +6. You will install `Node.js` using the instructions in section **Install Node using a PPA`** from the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). Strapi works best on **Node.js v10+**. -After completing the steps to **install Node.js, NPM and the build-essential package**, you may continue to the next section. +After completing the steps to **install Node.js, NPM and the "build-essential package"**, you may continue to the next section. ### Install Git versioning on your server A convenient way to maintain your Strapi application and update it during and after initial development is to use [Git Versioning](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control). In order to use Git Versioning, you will need to have Git installed on your Droplet. Droplets should have Git installed by default, so you will check and if not installed, you will need to install it. -1. Check to see if `Git` is installed, if you see a `git version 2.x.x` then you have get installed. Check with the following command: +1. Check to see if `Git` is installed, if you see a `git version 2.x.x` then you do have `Git` installed. Check with the following command: ```bash git --version @@ -146,12 +146,16 @@ git --version 3. Complete the globel **username** and **GitHub** settings: [Setting up Git](https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-18-04#setting-up-git) -After installing and configuring Git on your Droplet. Please continue to the next step, [installing the database](#install-the-database-for-your-project). +After installing and configuring Git on your Droplet. Please continue to the next step, [installing a database](#install-the-database-for-your-project). ### Install the database for your project Digital Ocean has excellent documentation regarding the installation and use of the major databases that work with Strapi. The previous steps above should all be completed prior to continuing. You can find links, and any further instructions, to each database guide below: +:::: tabs cache-lifetime="10" :options="{ useUrlFragment: false }" + +::: tab "PostgreSQL" id="postgreSQL-ubuntu" + 1. [Install PostgresSQL on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04)(Through **Step 4** - Creating a New Database). Complete the steps to [install PostgreSQL](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-1-%E2%80%94-installing-postgresql), [add a user](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-3-%E2%80%94-creating-a-new-role) and [create a database](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-4-%E2%80%94-creating-a-new-database). @@ -185,12 +189,10 @@ exit You will need the **database name**, **username** and **password** to continue to the next step of [configuring that database.json file](#local-development-configuration). -2. Install MongoDB - ### Local Development Configuration - You must have [Git installed and set-up locally](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup). -- You must have created a repository for your Strapi Project and have your development project initilized to this repository. +- You must have created a repository for your Strapi project and have your development project initilized to this repository. In your code editor, you will need to edit a file called `database.json`. Replace the contents of the file with the following, but change the `username`, `password` and `database` to match your installation. @@ -200,7 +202,7 @@ In your code editor, you will need to edit a file called `database.json`. Replac { "defaultConnection": "default", "connections": { - "postgres": { + "default": { "connector": "strapi-hook-bookshelf", "settings": { "client": "postgres", @@ -226,6 +228,16 @@ git push Please continue to the next section, [Deploy from GitHub](#deploy-from-github). +::: + +::: tab "MongoDB" id="mongodb-ubuntu" + +2. Install MongoDB + +::: + +:::: + ### Deploy from Github You will next deploy your Strapi project to your Droplet by `cloning it from GitHub`. @@ -237,7 +249,7 @@ cd ~ git clone https://github.com/your-name/your-project-repo.git ``` -Next, navigate to the `my-project` folder, the root for Strapi. You will now need to run `npm install` to install the packages for your project, and then `npm run postinstall`. This last command runs scripts that build out your Strapi installation. +Next, navigate to the `my-project` folder, the root for Strapi. You will now need to run `npm install` to install the packages for your project. `Path: ./my-project/` @@ -251,9 +263,41 @@ Strapi uses `Port: 1337` by default. You will need to configure your `ufw firew ```bash cd ~ sudo ufw allow 1337/tcp +sudo ufw enable + +Command may disrupt existing ssh connections. Proceed with operation (y|n)? y +Firewall is active and enabled on system startup ``` -Your Strapi project is now installed on your **Droplet**. You will next need to [install and configure PM2 Runtime](#install-and-configure-pm2-runtime). +Your Strapi project is now installed on your **Droplet**. + +**OPTIONAL:** You may see your project and set-up your first administrator user, by doing the following: + +- Navigate to the Strapi project folder. `Path: ./my-project/`. Run the follow command from within the Strapi project root: + +`Path: ./my-project/` + +```bash +npm run start + +> my-project@0.1.0 start /home/path-to-your-project-folder/my-project +> node server.js + +[2019-05-20T14:06:01.553Z] info Time: Mon May 20 2019 14:06:01 GMT+0000 (Coordinated Universal Time) +[2019-05-20T14:06:01.555Z] info Launched in: 2623 ms +[2019-05-20T14:06:01.555Z] info Environment: development +[2019-05-20T14:06:01.555Z] info Process PID: 13221 +[2019-05-20T14:06:01.556Z] info Version: 3.0.0-alpha.25.2 (node v10.15.3) +[2019-05-20T14:06:01.556Z] info To shut down your server, press + C at any time + +[2019-05-20T14:06:01.557Z] info ☄️ Admin panel: http://localhost:1337/admin +[2019-05-20T14:06:01.557Z] info ⚡️ Server: http://localhost:1337 + +``` + +Minimumly, [create an admin user](http://localhost:8080/documentation/3.x.x/getting-started/quick-start.html#_3-create-an-admin-user). + +You will next need to [install and configure PM2 Runtime](#install-and-configure-pm2-runtime). ### Install and configure PM2 Runtime @@ -262,7 +306,7 @@ Your Strapi project is now installed on your **Droplet**. You will next need to Ensure you are logged in as a **non-root** user. You will install **PM2** globally: ```bash -sudo npm install pm2@latest -g +npm install pm2@latest -g ``` Navigate to your **Strapi Project folder** and use the following command to set the environment variable to production and start `pm2`: @@ -270,21 +314,25 @@ Navigate to your **Strapi Project folder** and use the following command to set `Path: ./my-project/` ```bash -sudo NODE_ENV=production pm2 start --name="strapi" server.js -i max +NODE_ENV=production pm2 start --name="strapi" server.js -i max ``` -Follow these steps to have your app launch on system startup. (**NOTE:** These steps follow the Digital Ocean [documentation for setting up PM2](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04#step-3-%E2%80%94-installing-pm2).) +Follow the steps below to have your app launch on system startup. (**NOTE:** These steps are based on the Digital Ocean [documentation for setting up PM2](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04#step-3-%E2%80%94-installing-pm2).) - Generate and configure a startup script to launch PM2, it will generate a Startup Script to copy/paste, do so: ```bash $ cd ~ -$ sudo pm2 startup systemd +$ pm2 startup systemd [PM2] Init System found: systemd [PM2] To setup the Startup Script, copy/paste the following command: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u your-name --hp /home/your-name +``` +- Copy/paste the generated command: + +```bash $ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u your-name --hp /home/your-name [PM2] Init System found: systemd @@ -305,7 +353,7 @@ Platform systemd - Next, `Save` the new PM2 process list and environment. Then `Start` the service with `systemctl`: ```bash -sudo pm2 save +pm2 save [PM2] Saving current process list... [PM2] Successfully saved in /home/your-name/.pm2/dump.pm2 @@ -316,13 +364,13 @@ sudo pm2 save Your `Strapi` project is now accessible at: `your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more efficient and to set-up a few additional aspects of your server.  -- Lastly, you will need to configure a `ecosystem.config.js` file. It will establish a `watch` for `pm2` and restarts your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/). +- Lastly, you will need to configure a `ecosystem.config.js` file. It will establish a `watch` for `pm2` and restart your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/). - You will need to open your `nano` editor and then `copy/paste` the following: ```bash cd ~ -sudo pm2 init +pm2 init sudo nano ecosystem.config.js ``` @@ -408,6 +456,10 @@ http ```bash sudo ufw allow 8080/tcp +sudo ufw enable + +Command may disrupt existing ssh connections. Proceed with operation (y|n)? y +Firewall is active and enabled on system startup ``` - You may test your **webhook** by following the instructions [here](https://www.digitalocean.com/community/tutorials/how-to-use-node-js-and-github-webhooks-to-keep-remote-projects-in-sync#step-4-testing-the-webhook). From 42aa73be7ddda800bd7aa35163fb25ab1b55fc21 Mon Sep 17 00:00:00 2001 From: davidkartuzinski Date: Tue, 21 May 2019 16:36:16 +0200 Subject: [PATCH 8/9] fully tested docs --- docs/3.x.x/guides/deployment.md | 34 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index 29ddda3da6..70cf05a61a 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -87,11 +87,11 @@ If you want to host the administration on another server than the API, [please t ## Digital Ocean -This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be on a [Digital Ocean Droplet](https://www.digitalocean.com/docs/droplets/) or hosted externally as a service. Prior to starting this guide, you should have created a [Strapi project for development](/3.x.x/getting-started/quick-start.html). +This is a step-by-step guide for deploying a Strapi project to [Digital Ocean](https://www.digitalocean.com/). Databases can be on a [Digital Ocean Droplet](https://www.digitalocean.com/docs/droplets/) or hosted externally as a service. Prior to starting this guide, you should have created a [Strapi project](/3.x.x/getting-started/quick-start.html). ### Digital Ocean Install Requirements -- You must have a [Digital Ocean account](https://cloud.digitalocean.com/registrations/new) before doing these steps. +- You must have a free [Digital Ocean account](https://cloud.digitalocean.com/registrations/new) before doing these steps. ### Create a "Droplet" @@ -112,13 +112,13 @@ Digital Ocean calls a virtual private server, a [Droplet](https://www.digitaloce - **OPTIONAL:** `Choose a hostname` or leave as-is. - Click the green `Create` button. -**Digital Ocean** will create your **Droplet** and indicate the progress with a percentage bar. You may continue to the next steps, once this is complete. +**Digital Ocean** will create your **Droplet** and indicate the progress with a percentage bar. Once this is complete, you may continue to the next steps. ### Setup production server and install Node.js -These next steps involved setting up a production server and user access for development. +These next steps will help you to _set up a production server_ and _set up a non-root user_ for managing your server. -Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These steps will have you complete the following actions: +Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04). These docs will have you complete the following actions: 1. [Logging and set up root user access to your server with SSH](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-1-%E2%80%94-logging-in-as-root). 2. [Creating a new user](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04#step-2-%E2%80%94-creating-a-new-user). @@ -128,13 +128,15 @@ Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 1 Next, install `Node.js`: -6. You will install `Node.js` using the instructions in section **Install Node using a PPA`** from the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). Strapi works best on **Node.js v10+**. +6. You will install `Node.js` using the instructions in section **Install Node using a PPA** from the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). After completing the steps to **install Node.js, NPM and the "build-essential package"**, you may continue to the next section. -### Install Git versioning on your server +### Install and Configure Git versioning on your server -A convenient way to maintain your Strapi application and update it during and after initial development is to use [Git Versioning](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control). In order to use Git Versioning, you will need to have Git installed on your Droplet. Droplets should have Git installed by default, so you will check and if not installed, you will need to install it. +A convenient way to maintain your Strapi application and update it during and after initial development is to use [Git](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control). In order to use Git, you will need to have it installed on your Droplet. Droplets should have Git installed by default, so you will first check if it is instqlled and if it is not installed, you will need to install it. + +The last step is to configure Git on your server. 1. Check to see if `Git` is installed, if you see a `git version 2.x.x` then you do have `Git` installed. Check with the following command: @@ -160,7 +162,7 @@ Digital Ocean has excellent documentation regarding the installation and use of Complete the steps to [install PostgreSQL](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-1-%E2%80%94-installing-postgresql), [add a user](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-3-%E2%80%94-creating-a-new-role) and [create a database](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-4-%E2%80%94-creating-a-new-database). -2. In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically to have stated there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: +2. In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically state there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: ```bash sudo -u postgres psql //only necessary if you switched away from the postgres@ user @@ -175,7 +177,7 @@ postgres=# \q exit ``` -- **Optional:** If your **Development** Strapi project is using **SQLite**, you will need to install a dependency package called `pg`: +- **Optional:** If in **Development**, your Strapi project is uses **SQLite**, you will need to install a dependency package called `pg`: - On your **Development** computer: @@ -230,12 +232,6 @@ Please continue to the next section, [Deploy from GitHub](#deploy-from-github). ::: -::: tab "MongoDB" id="mongodb-ubuntu" - -2. Install MongoDB - -::: - :::: ### Deploy from Github @@ -314,7 +310,7 @@ Navigate to your **Strapi Project folder** and use the following command to set `Path: ./my-project/` ```bash -NODE_ENV=production pm2 start --name="strapi" server.js -i max +NODE_ENV=production pm2 start --name="strapi" server.js --watch -i max ``` Follow the steps below to have your app launch on system startup. (**NOTE:** These steps are based on the Digital Ocean [documentation for setting up PM2](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04#step-3-%E2%80%94-installing-pm2).) @@ -362,7 +358,7 @@ pm2 save - **OPTIONAL**: You can test to see if the script above works whenever your system reboots with the `sudo reboot` command. You will need to login again with your **non-root user** and then run `pm2 list` and `systemctl status pm2-your-name` to verify everything is working. -Your `Strapi` project is now accessible at: `your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more efficient and to set-up a few additional aspects of your server.  +Your `Strapi` project is now accessible at: `http://your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more efficient and to set-up a few additional aspects of your server.  - Lastly, you will need to configure a `ecosystem.config.js` file. It will establish a `watch` for `pm2` and restart your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/). @@ -382,7 +378,7 @@ module.exports = { { name: 'your-app-name', script: '.path-to/your-strapi-app/server.js', - watch: './root-folder/', + watch: './strapi-project-root/', }, ], }; From d4ea5dc63d4350880115cbdbe27e2f58c949125d Mon Sep 17 00:00:00 2001 From: David Kartuzinski Date: Wed, 22 May 2019 11:16:15 +0200 Subject: [PATCH 9/9] Fixed feedback after review --- docs/3.x.x/guides/deployment.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/3.x.x/guides/deployment.md b/docs/3.x.x/guides/deployment.md index 70cf05a61a..be68b0d77a 100644 --- a/docs/3.x.x/guides/deployment.md +++ b/docs/3.x.x/guides/deployment.md @@ -101,13 +101,13 @@ Digital Ocean calls a virtual private server, a [Droplet](https://www.digitaloce 2. `Create a Droplet` by clicking on `New Droplet`. Choose these options: - Ubuntu 18.04 x64 -- STARTER `Standard` -- Choose an appropriate pricing plan. For example, pricing: `$5/mo` _(Scroll to the left)_ -- Choose a `datacenter` region nearest your audience, for example, `Frankfurt`. -- **OPTIONAL:** Select additional options, for example, `[x] IPv6`. +- STARTER `Standard` +- Choose an appropriate pricing plan. For example, pricing: `$5/mo` _(Scroll to the left)_ +- Choose a `datacenter` region nearest your audience, for example, `New York`. +- **OPTIONAL:** Select additional options, for example, `[x] IPv6`. - Add your SSH key **NOTE:** We recommend you `add your SSH key` for better security. - - In your terminal, use `pbcopy < ~/.ssh/id_rsa.pub` to copy your existing SSH public key, on your development computer, to the clipboard. - - Click on `New SSH Key` and paste in your `SSH Key`. `Name` this SSH key and then `Save`. + - In your terminal, use `pbcopy < ~/.ssh/id_rsa.pub` to copy your existing SSH public key, on your development computer, to the clipboard. + - Click on `New SSH Key` and paste in your `SSH Key`. `Name` this SSH key and then `Save`. (Additional instructions on creating and using SSH Keys can be found [here](https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-openssh/).) - **OPTIONAL:** `Choose a hostname` or leave as-is. - Click the green `Create` button. @@ -128,7 +128,7 @@ Follow the official [Digital Ocean docs for initial server set-up using Ubuntu 1 Next, install `Node.js`: -6. You will install `Node.js` using the instructions in section **Install Node using a PPA** from the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). +6. You will install `Node.js` using the instructions in section **Install Node using a PPA** from the official [Digital Ocean docs for installing a production ready Node.js server](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-18-04#installing-using-a-ppa). After completing the steps to **install Node.js, NPM and the "build-essential package"**, you may continue to the next section. @@ -162,7 +162,7 @@ Digital Ocean has excellent documentation regarding the installation and use of Complete the steps to [install PostgreSQL](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-1-%E2%80%94-installing-postgresql), [add a user](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-3-%E2%80%94-creating-a-new-role) and [create a database](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04#step-4-%E2%80%94-creating-a-new-database). -2. In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically state there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: +2. In order to connect to a PostgreSQL database with Strapi, it needs either to have a password, or specifically state there is no password by noting a empty string. Follow these commands from your terminal to `alter` the `user` you created and `add a password`: ```bash sudo -u postgres psql //only necessary if you switched away from the postgres@ user @@ -177,7 +177,7 @@ postgres=# \q exit ``` -- **Optional:** If in **Development**, your Strapi project is uses **SQLite**, you will need to install a dependency package called `pg`: +- **Optional:** If in **Development**, your Strapi project is uses **SQLite**, you will need to install a dependency package called `pg`: - On your **Development** computer: @@ -254,7 +254,7 @@ cd ./path-to-strapi-root-folder/ npm install ``` -Strapi uses `Port: 1337` by default. You will need to configure your `ufw firewall` to allow access to this port: +Strapi uses `Port: 1337` by default. You will need to configure your `ufw firewall` to allow access to this port: ```bash cd ~ @@ -358,9 +358,9 @@ pm2 save - **OPTIONAL**: You can test to see if the script above works whenever your system reboots with the `sudo reboot` command. You will need to login again with your **non-root user** and then run `pm2 list` and `systemctl status pm2-your-name` to verify everything is working. -Your `Strapi` project is now accessible at: `http://your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more efficient and to set-up a few additional aspects of your server.  +Your `Strapi` project is now accessible at: `http://your-ip-address:1337/admin`, in the sections to follow, are a few recommended additional actions to make developing your project more efficient and to set-up a few additional aspects of your server. -- Lastly, you will need to configure a `ecosystem.config.js` file. It will establish a `watch` for `pm2` and restart your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/). +- Lastly, you will need to configure a `ecosystem.config.js` file. It will establish a `watch` for `pm2` and restart your project whenever any changes are made to files within the Strapi file system itself (such as when an update arrives from GitHub). You can read more about this file [here](https://pm2.io/doc/en/runtime/guide/development-tools/). - You will need to open your `nano` editor and then `copy/paste` the following: @@ -379,6 +379,8 @@ module.exports = { name: 'your-app-name', script: '.path-to/your-strapi-app/server.js', watch: './strapi-project-root/', + ignore_watch : ["node_modules", "public"], + watch_delay: 1000, }, ], };