Skip to content

Getting Started

Tech Stack

Installation

If you want to start a fresh NextJS project with PayloadCMS, you can jump to this section. Otherwise, you can integrate PayloadCMS to your existing NextJS project by following the steps below.

Integrate PayloadCMS to existing NextJS project

Pre-requirement

PayloadCMS doesn’t support a root layout inside app directory. So, if your files is directly on app directory, you need to move it inside a sub-folder.

If your project structure look like this:

  • Directorypublic/
  • Directorysrc
    • Directoryapp
      • favicon.ico
      • globals.css
      • layout.tsx
      • page.tsx
  • package.json
  • next.config.ts

You need to move all the files inside app directory to a sub-folder, for example (landing) like this:

  • Directorypublic/
  • Directorysrc
    • Directoryapp
      • Directory(landing)
        • favicon.ico
        • globals.css
        • layout.tsx
        • page.tsx
        • all other files goes here
  • package.json
  • next.config.ts

These should not affect your project. Your project should still work as expected.

Install PayloadCMS

  1. Go to your existing NextJS project folder and run the following command on your terminal:

    Terminal window
    npx create-payload-app
  2. It will be automatically detected that we are have NextJS project already. Just hit Enter.

    Terminal window
    create-payload-app
    ────────────────────────────────────────────╮
    Welcome to Payload. Let's create a project! │
    │ │
    ├───────────────────────────────────────────────╯
    ◇ ▲ Next.js project detected!
    ◆ Install Payload in this project?
    │ ● Yes / ○ No
  3. On database selection step, choose SQLite.

    Terminal window
    Select a database
    MongoDB
    PostgreSQL
    SQLite
    Vercel Postgres

    You can enter the file name for the database, or just press enter to use the default name.

    Terminal window
    Enter SQLite connection string
    file:./test-payloadcms.db
  4. Payload requires some environment variables to run. You can create a .env file on the root of your project and add the following environment variables:

    Terminal window
    PAYLOAD_SECRET=your_secret_key
    DATABASE_URI=libsql:./test-payloadcms.db

    You can generate a secret key by running the following command on your terminal:

    Terminal window
    node -e "console.log(require('crypto').randomBytes(12).toString('hex'))"
  5. Once everything set, you can run the project with the following command:

    Terminal window
    npm run dev
  6. You can access the PayloadCMS dashboard by visiting http://localhost:3000/admin on your browser.

A fresh NextJS project with PayloadCMS

  1. Go to your desired folder and run the following command on your terminal

    Terminal window
    npx create-payload-app
  2. You will be prompted to enter your project name and the template you want to use.

    Terminal window
    create-payload-app
    ────────────────────────────────────────────╮
    Welcome to Payload. Let's create a project! │
    │ │
    ├───────────────────────────────────────────────╯
    ◇ Project name?
    │ test-payloadcms
    ◆ Choose project template
    │ ● blank
    │ ○ website
    │ ○ plugin

    Choose the blank template.

  3. Then, choose sqlite as database.

    Terminal window
    Select a database
    MongoDB
    PostgreSQL
    SQLite
    Vercel Postgres

    You can enter the file name for the database, or just press enter to use the default name.

    Terminal window
    Enter SQLite connection string
    file:./test-payloadcms.db
  4. Wait until the installation is finished.

  5. After the installation is finished, you can run the project with the following command:

    Terminal window
    npm run dev
  6. You can access the PayloadCMS dashboard by visiting http://localhost:3000/admin on your browser.