Add heroku documentation

This commit is contained in:
davidkartuzinski 2019-04-08 10:42:48 +02:00
parent 196fa038bd
commit 241b1a2884
7 changed files with 983 additions and 356 deletions

View File

@ -48,6 +48,8 @@ module.exports = {
.use(...createContainer('ubuntu'))
.use(...createContainer('mac'))
.use(...createContainer('note'));
const vuepressTabs = require('vuepress-tabs')
vuepressTabs(md)
},
},
title,
@ -58,8 +60,6 @@ module.exports = {
versions: [['Version 3.x.x', '/3.x.x/'], ['Version 1.x.x', '/1.x.x/']],
repo: 'strapi/strapi',
website: 'https://strapi.io',
slack: 'https://slack.strapi.io',
blog: 'https://blog.strapi.io',
docsDir: 'docs',
editLinks: true,
editLinkText: 'Improve this page',
@ -86,6 +86,7 @@ module.exports = {
'/3.x.x/guides/authentication',
'/3.x.x/configurations/configurations',
'/3.x.x/guides/controllers',
'/3.x.x/guides/database',
'/3.x.x/guides/deployment',
'/3.x.x/guides/email',
'/3.x.x/guides/upload',

View File

@ -0,0 +1,12 @@
import Tabs from 'vue-tabs-component'
export default (({
Vue, // the version of Vue being used in the VuePress app
options, // the options for the root Vue instance
router, // the router instance for the app
siteData // site metadata
}) => {
//...
Vue.use(Tabs)
//...
})

View File

@ -5,6 +5,7 @@
@require './arrow'
@require './wrapper'
@require './toc'
@require '~vuepress-tabs/dist/themes/default.styl'
html, body
padding 0

View File

@ -0,0 +1,296 @@
# Database
Strapi gives you options in which database you can use. Strapi currently supports the **PostgreSQL**, **MongoDB**, **SQLite**, **MySQL** and
**MariaDB** databases. The following documentation covers how to install these databases locally (for development purposes) and on various hosted or cloud server solutions (for staging or production purposes).
(Deploying **Strapi** itself is covered in the [Deployment Guide](/3.x.x/guides/deployment.html).)
**Table of contents:**
- [SQLite Installation](#sqlite-installation)
- [MongoDB Installation](#mongodb-installation)
---
## SQLite Installation
SQLite is the default [Quick Start](/3.x.x/getting-started/quick-start.html) database and recommended to quickly deploy an app locally.
### Install SQLite locally
Simply use the `strapi new my-project --quickstart` command.
```bash
strapi new my-project --quickstart
```
This will create a new project and launch your project in the browser. (The [Quick Start Guide](/3.x.x/getting-started/quick-start.html) is a complete step-by-step tutorial.)
## MongoDB Installation
### Install MongoDB locally
In order to use Strapi with [MongoDB](https://www.mongodb.com/) in production, you must have and use MongoDB on your local development environment. These instructions show how to install a Strapi project locally with a MongoDB database.
- You must have [Strapi installed globally](/3.x.x/getting-started/quick-start-tutorial.html#_1-install-strapi-globally).
### 1. Install MongoDB on your development environment
If you already have MongoDB installed locally and running as a background service, you may skip to [Install Strapi locally with MongoDB](#install-strapi-locally-with-mongodb). (If you have additional questions, please see the official [MongoDB documentation](https://docs.mongodb.com/manual/installation/#tutorial-installation). )
Please complete the installation steps appropriate to your operating system.
:::: tabs cache-lifetime="10" :options="{ useUrlFragment: false }"
::: tab "Windows 10" id="windows-mongodb"
### Install MongoDB on Windows 10
Follow these steps to [install MongoDB onto your Windows 10](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/) environment (The Windows Sub-System for Linux (WSL) is unsupported by MongoDB):
1. Download the `MongoDB Community Edition Server` for Windows [here](https://www.mongodb.com/download-center/community?jmp=docs). Select `MongoDB Community Server` and verify the options that match your computer. Then `Download` the package and follow the installation instructions to complete the process.
2. After successfully installing MongoDB, the MongoDB service is started. To begin using MongoDB, connect a mongo.exe shell to the running MongoDB instance.
```bash
"C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe"
```
You can exit the MongoDB shell with `CTRL + C`.
You have now installed MongoDB for _Windows 10_. You are now ready to [install Strapi with MongoDB locally](#install-strapi-with-mongodb).
:::
::: tab "Mac O/S 10.14 Mojave" id="mac-mongodb"
### Install MongoDB on Mac
Follow these steps to [install MongoDB onto your Mac](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/) developer environment:
1. Use `brew` to tap the official MongoDB formula repository and add it to the formula list:
```bash
brew tap mongodb/brew
```
2. Now install MongoDB
```bash
brew install mongodb-community@4.0
```
3. Get the mongod process running in order to connect and use MongoDB:
```bash
mongod --config /usr/local/etc/mongod.conf
```
You have now installed MongoDB for _Mac_. You are now ready to [install Strapi with MongoDB locally](#install-strapi-with-mongodb).
:::
::: tab "Ubuntu 18.04" id="ubuntu-mongodb"
### Install MongoDB on Ubuntu
Follow these steps to [install MongoDB onto your Ubuntu](https://docs.mongodb.com/manual/administration/install-on-linux/) environment:
1. Import a public key to ensure your MongoDB is authentic:
```bash
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
```
2. Next, add the repository for 18.04. Repositories for other versions of Ubuntu are found [here](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/).
```bash
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
```
3. Reload the local package database:
```bash
sudo apt-get update
```
4. Install the stable release MongoDB package
```bash
sudo apt-get install -y mongodb-org
```
5. Get the `mongod` process running in order to connect and use MongoDB:
```bash
sudo service mongod start
```
6. Confirm the MongoDB status:
```bash
service mongod status
```
7. The last step is to enable automatically starting MongoDB when your computer boots:
```bash
sudo systemctl enable mongod
```
You have now installed MongoDB for _Linux_. You are now ready to [install Strapi with MongoDB locally](#install-strapi-with-mongodb).
:::
::::
### 2. Install Strapi locally with MongoDB
Follow these steps to create a Strapi project locally using the MongoDB database.
**Note:** MongoDB must already be running in the background.
1. Create a new Strapi project
`Path: ./`
```bash
strapi new my-project
```
- Use your `down arrow` key and select `Custom (manual settings)` and press `enter`:
```bash
? Choose your installation type
Quickstart (recommended)
Custom (manual settings)
```
- Select `MongoDB` and press `enter`:
```bash
? Choose your installation type Custom (manual settings)
? Choose your main database:
SQLite
MongoDB
MySQL
Postgres
```
- Press `enter` to select the remaining default options. It will look something like this:
```bash
? Choose your installation type Custom (manual settings)
? Choose your main database: MongoDB
? Database name: my-project
? Host: 127.0.0.1
? +srv connection: false
? Port (It will be ignored if you enable +srv): 27017
? Username:
? Password:
? Authentication database (Maybe "admin" or blank):
? Enable SSL connection: false
⏳ Testing database connection...
The app has been connected to the database successfully!
🏗 Application generation:
✔ Copy dashboard
✔ Install plugin settings-manager.
✔ Install plugin content-type-builder.
✔ Install plugin content-manager.
✔ Install plugin users-permissions.
✔ Install plugin email.
✔ Install plugin upload.
✔ Link strapi dependency to the project.
👌 Your new application my-project is ready at /Users/david/Desktop/Projects/my-project.
⚡️ Change directory:
$ cd my-project
⚡️ Start application:
$ strapi start
```
You have successfully installed Strapi with MongoDB on your local development environment. You are now ready to [create your first user](/3.x.x/getting-started/quick-start.html#_3-create-an-admin-user).
---
### Install on Atlas: MongoDB Atlas
Follow these steps to configure a local Strapi project to use a [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) free 512 MB account in production. (Please see [MongoDB Atlas Documentation](https://docs.atlas.mongodb.com/getting-started/) if you have any questions.)
- You must have already [installed Strapi localled with MongoDB](http://localhost:8080/documentation/3.x.x/guides/database.html#install-strapi-locally-with-mongodb).
- You must have already created a [free MongoDB Atlas account](https://www.mongodb.com/cloud/atlas).
1. Log in to your account to create a **Project** and a **Cluster**
- First you need to `Create a new Project`.
- Then click `Build a Cluster`, from the options page:
- Choose **AWS** as your **Cloud Provider & Region**.
- Select a **Region**. (Note: some **Regions** do not have a _free tier_.)
- In **Cluster Tier**, select **Shared Sandbox**, _Tier_ `MO`.
- In **Cluster Name**, name your cluster.
- Click the green `Create Cluster` button. You will get a message that says, "*Your cluster is being created...*"
2. Next, click on the `Security` tab (next to `Overview`):
- Click the green `+ ADD NEW USER` button:
- Enter a `username`.
- Enter a `password`.
- Under `User Privileges` ensure **`Read and write to any database`** is selected. Then click `Add User` to save.
3. Then `whitelist` your IP address. Under `Security`, click to `IP Whitelist`
- Click the green `+ ADD IP ADDRESS`
- Next click `ALLOW ACCESS FROM ANYWHERE`. **Note:** In permanent projects you would configure this with the appropriate IP addresses.
- Click `Confirm`. Then wait until the status turns from `Pending` to `Active`.
4. Retrieve database credentials
MongoDB Atlas automatically exposes the database credentials into a single environment variable accessible by your app. To locate it, follow these steps:
- Under the `Overview` tab, click `CONNECT` and then `Connect Your Application`.
- Under `1. Choose your driver version`, select **DRIVER** as `Node.js` and **VERSION** as `2.2.12 or later`.
- This should show a **Connection String Only** similar to this:
`mongodb://paulbocuse:<password>@strapi-heroku-shard-00-00-o777o.mongodb.net:27017,strapi-heroku-shard-00-01-o606o.mongodb.net:27017,strapi-heroku-shard-00-02-o606o.mongodb.net:27017/test?ssl=true&replicaSet=Strapi-Heroku-shard-0&authSource=admin&retryWrites=true`
- You are interested in everything **AFTER** the **@** symbol. This is your **Database Host** variable. So in this case,
`strapi-heroku-shard-00-00-o777o.mongodb.net:27017,strapi-heroku-shard-00-01-o606o.mongodb.net:27017,strapi-heroku-shard-00-02-o606o.mongodb.net:27017/test?ssl=true&replicaSet=Strapi-Heroku-shard-0&authSource=admin&retryWrites=true`_
- You created earlier a `cluster name`, `username` and `password`. These are the other variables needed to configure your project to connect to MongoDB Atlas.
Keep these five MongoDB Atlas database variables from your MongoDB Atlas account ready and available.
5. Update your database config file
Replace the contents of `database.json` with the following:
`Path: ./config/environments/(development|production)/database.json`.
```json
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"host": "cluster0-shard-00-00-y8imj.mongodb.net:27017,cluster0-shard-00-01-y8imj.mongodb.net:27017,cluster0-shard-00-02-y8imj.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true",
"port": 27017,
"database": "test",
"username": "john",
"password": "doe"
},
"options": {
"ssl": true
}
}
}
}
```
You are now ready use Strapi locally or to deploy your project to an external hosting provider and use MongoDB Atlas as your database server.

View File

@ -1,12 +1,20 @@
# Deployment
### Docker
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.
::: tip
You can also deploy using [Docker](https://hub.docker.com/r/strapi/strapi)
:::
(Deploying **databases** along with Strapi is covered in the [Database Guide](/3.x.x/guides/database.html).)
The method below describes regular deployment using the built-in mechanisms.
**Table of contents:**
- [Configuration](#configuration)
- [Heroku](#heroku)
- [AWS](#aws)
- [Digital Ocean](#digital-ocean)
- [Azure](#azure)
- [Docker](#docker)
---
## Configuration
#### #1 - Configure
@ -75,3 +83,317 @@ We highly recommend to use [pm2](https://github.com/Unitech/pm2/) to manage your
### Advanced configurations
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).
## 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 below for connecting to them.
### Heroku Install Requirements
- 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 a [free Heroku account](https://signup.heroku.com/) before doing these steps.
If you already have the Heroku CLI installed locally on your computer. Skip to [Login to Heroku](#_2-login-to-heroku-from-your-cli).
### 1. Heroku CLI Installation
Download and install the `Heroku CLI` for your operating system:
:::: tabs cache-lifetime="10" :options="{ useUrlFragment: false }"
::: tab "macOS"
[Download the installer](https://cli-assets.heroku.com/heroku.pkg)
Also available via Homebrew:
```bash
brew tap heroku/brew && brew install heroku
```
:::
::: tab "Ubuntu"
Run the following from your terminal:
```bash
sudo snap install --classic heroku
```
:::
::: tab "Windows"
Download the appropriate installer for your Windows installation:
[64-bit installer](https://cli-assets.heroku.com/heroku-x64.exe)
[32-bit installer](https://cli-assets.heroku.com/heroku-x86.exe)
:::
::::
### 2. Login to Heroku from your CLI
Next, you need to login to Heroku from your computer.
```bash
heroku login
```
Follow the instructions and return to your command line.
### 3. Create a new project (or use an existing one)
Create a [new Strapi project](/3.x.x/getting-started/quick-start.html) (if you want to deploy an existing project go to step 4).
::: warning NOTE
If you will use a **MongoDB database** with your project, [create a Strapi project with MongoDB set-up locally](/3.x.x/guides/database.html#install-mongodb-locally) and go to step 4.
:::
`Path: ./`
```bash
strapi new my-project --quickstart
```
### 4. Init a Git repository and commit your project
`Path: ./my-project/`
```bash
cd my-project
git init
git add .
git commit -am "Initial Commit"
```
### 5. Create a Heroku project
Create a new Heroku project.
`Path: ./my-project/`
```bash
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.)
::: warning NOTE
If you have a Heroku project app already created. You would use the following step to initialize your local project folder:
`Path: ./my-project/`
```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 and a new Heroku app ready to be configured to work with a database and with each other.
### 6. Complete the Strapi project and 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.
:::: tabs cache-lifetime="10" :options="{ useUrlFragment: false }"
::: tab "PostgreSQL" id="heroku-postgresql"
#### Heroku Postgres
Follow these steps to deploy your Strapi app to Heroku using **PostgreSQL**:
##### 1. Install the [Heroku Postgres addon](https://elements.heroku.com/addons/heroku-postgresql) for using Postgres.
To make things even easier, Heroku provides a powerful addon system. In this section, you are going to use the Heroku Postgres addon, which provides a free "Hobby Dev" plan. If you plan to deploy your app in production, it is highly recommended to switch to a paid plan.
`Path: ./my-project/`
```bash
heroku addons:create heroku-postgresql:hobby-dev
```
##### 2. Retrieve database credentials
The add-on automatically exposes the database credentials into a single environment variable accessible by your app. To retrieve it, type:
`Path: ./my-project/`
```bash
heroku config
```
This should print something like this: `DATABASE_URL: postgres://ebitxebvixeeqd:dc59b16dedb3a1eef84d4999a0be041bd419c474cd4a0973efc7c9339afb4baf@ec2-50-37-231-192.compute-2.amazonaws.com:5432/d516fp1u21ph7b`.
(This url is read like so: *postgres:// **USERNAME** : **PASSWORD** @ **HOST** : **PORT** : **DATABASE_NAME***)
##### 3. Set environment variables
Strapi expects a variable for each database connection detail (host, username, etc.). So, from the url above, you have to set several environment variables in the Heroku config:
```bash
heroku config:set DATABASE_USERNAME=ebitxebvixeeqd
heroku config:set DATABASE_PASSWORD=dc59b16dedb3a1eef84d4999a0be041bd419c474cd4a0973efc7c9339afb4baf
heroku config:set DATABASE_HOST=ec2-50-37-231-192.compute-2.amazonaws.com
heroku config:set DATABASE_PORT=5432
heroku config:set DATABASE_NAME=d516fp1u21ph7b
```
**Note:** Please replace these above values with the your actual values.
##### 4. Update your database config file
Replace the contents of `database.json` with the following:
`Path: ./config/environments/production/database.json`.
```json
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-hook-bookshelf",
"settings": {
"client": "postgres",
"host": "${process.env.DATABASE_HOST}",
"port": "${process.env.DATABASE_PORT}",
"database": "${process.env.DATABASE_NAME}",
"username": "${process.env.DATABASE_USERNAME}",
"password": "${process.env.DATABASE_PASSWORD}",
"ssl": true
},
"options": {}
}
}
}
```
##### 5. Install the `pg` node module
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
```
:::
::: tab "MongoDB" id="heroku-mongodb"
#### MongoDB Atlas
(Using Strapi and MongoDB requires different set-up and different configuration steps. You cannot use `--quickstart` to develop a `MongoDB` Strapi project.)
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/database.html#install-on-atlas-mongodb-atlas).
##### 1. Set environment variables
When you [set-up your MongoDB Atlas database](/3.x.x/guides/database.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
heroku config:set DATABASE_USERNAME=paulbocuse
heroku config:set DATABASE_PASSWORD=mySecretPassword
heroku config:set DATABASE_HOST="stapi-mongo-heroku-shard-00-00-fty6c.mongodb.net:27017,strapi-mongo-heroku-shard-00-01-fty6c.mongodb.net:27017,strapi-mongo-heroku-shard-00-02-fty6c.mongodb.net:27017/test?ssl=true&replicaSet=strapi-mongo-heroku-shard-0&authSource=admin&retryWrites=true"
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
Replace the contents of `database.json` with the following:
`Path: ./config/environments/production/database.json`.
```json
{
"defaultConnection": "default",
"connections": {
"default": {
"connector": "strapi-hook-mongoose",
"settings": {
"client": "mongo",
"host": "${process.env.DATABASE_HOST}",
"port": "${process.env.DATABASE_PORT}",
"database": "${process.env.DATABASE_NAME}",
"username": "${process.env.DATABASE_USERNAME}",
"password": "${process.env.DATABASE_PASSWORD}"
},
"options": {
"ssl": true
}
}
}
}
```
::::
### 6. Commit your changes
`Path: ./my-project/`
```bash
git commit -am "Update database config"
```
### 7. Deploy
`Path: ./my-project/`
```bash
git push heroku master
```
The deployment may take a few minutes. At the end, logs will display the url of your project (e.g. `https://mighty-taiga-80884.herokuapp.com`). You can also open your project using the command line:
`Path: ./my-project/`
```bash
heroku open
```
If you see the Strapi Welcome page, you have correctly set-up, configured and deployed your Strapi project on Heroku. You will now need to set-up your `admin user` as the production database is brand-new (and empty).
You can now continue with the [Tutorial - Creating an Admin User](/3.x.x/getting-started/quick-start-tutorial.html#_3-create-an-admin-user), if you have any questions on how to proceed.
::: warning NOTE
For security reasons, the Content Type Builder plugin is disabled in production. To update content structure, please make your changes locally and deploy again.
:::
---
### Project updates
You can continue developing your application with Strapi and Heroku by making changes on your computer and then using Git to commit and push those changes. After Heroku applies your changes, you can open your app.
`Path: ./my-project/`
```bash
git add .
git commit -am "Changes to my-project noted"
git push heroku master
heroku open
```
## AWS
TBD.
## Digital Ocean
TBD.
## Azure
TBD.
## Docker
::: tip
You can also deploy using [Docker](https://hub.docker.com/r/strapi/strapi)
:::
The method below describes regular deployment using the built-in mechanisms.

689
docs/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,10 +10,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"cache-loader": "1.2.2",
"directory-tree": "^2.1.0",
"markdown-it-decorate": "^1.2.2",
"vue-tabs-component": "^1.5.0",
"vuepress": "^0.14.2",
"cache-loader": "1.2.2"
"vuepress-tabs": "^0.1.6"
},
"devDependencies": {
"markdown-it-container": "^2.0.0"