strapi安装和开始
笔者部署在vagrant上的,有需要的同学可以了解一下用Vagrant部署开发环境,个人还是很喜欢vagrant的,每次要测(chang)试(xian)新的开源项目都会用全新的纯净的系统部署开发环境会更有利于排除错误和增长使用熟练度。
安装strapi前的准备工作
安装strapi的环境依赖
- Node.js >=
10.x
: Node.js is a server platform which runs JavaScript. Installation guide here. - NPM >=
6.x
: NPM is the package manager for Javascript. Installation guide here. (Make sure the database that you are using meets the requirement.) - Strapi支持一下数据库,选一即可:
- MongoDB >= 3.x: MongoDB is a powerful document store. Installation guide here.
- MySQL >= 5.6: MySQL is an open-source relational database management system. Installation guide here.
- MariaDB >= 10.1: MarialDB is a fork of MySQL and is guaranteed to stay open source. Installation guide here.
- PostgreSQL >= 10: PostgreSQL is an open-source object-relational database management system. Installation guide here
开始安装Strapi
npm install strapi@alpha -g
安装完成后检查版本
strapi -v
输出
3.0.0-alpha.14.5
20200312更新
为了您首次strapi的安装和项目的创建更加方便简单,strapi最新版本使用yarn或npm命令将两者合并到一起了,下面两种方法择一即可:
#使用yarn安装
yarn create strapi-app my-project --quickstart
#使用npx安装
npx create-strapi-app my-project --quickstart
因为strapi版本的问题如果遇到error strapi.start is not a function
的错误可以使用yarn develop
来启动strapi.
这里记录一下连接Mongodb数据库的配置过程
� Start creating your Strapi application.
? Choose your installation type Custom (manual settings)
? Choose your main database: MongoDB
? Database name: blog
? Host: 127.0.0.1
? +srv connection: false
? Port (It will be ignored if you enable +srv): 27017
? Username: blog
? Password: ********
? Authentication database (Maybe "admin" or blank): blog
? Enable SSL connection: false
⏳ Testing database connection...
It might take a minute, please have a coffee ☕️
(node:3108) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
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 gatsby-blog is ready at D:\WorkSpace\gatsby\strapi-gatsby-starter\gatsby-blog.
⚡️ Change directory:
$ cd gatsby-blog
⚡️ Start application:
$ strapi start
创建第一个应用
strapi new project-name
注意,笔者在这里遇到了在vagrant中映射目录创建失败的问题,详细链接:Vagrant中strapi无法连接MongoDB的一个Bug
运行应用
cd my-project
strapi start
这时候你访问 http;//localhost:1337/
就可以访问你的应用地址了.