Getting Started
Tech Stack
- NextJS version ^15.0.0 (App Router)
- PayloadCMS version ^3.0.0
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
-
Go to your existing NextJS project folder and run the following command on your terminal:
Terminal window npx create-payload-app -
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└ -
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└ -
Payload requires some environment variables to run. You can create a
.envfile on the root of your project and add the following environment variables:Terminal window PAYLOAD_SECRET=your_secret_keyDATABASE_URI=libsql:./test-payloadcms.dbYou 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'))" -
Once everything set, you can run the project with the following command:
Terminal window npm run devTerminal window yarn dev -
You can access the PayloadCMS dashboard by visiting
http://localhost:3000/adminon your browser.
A fresh NextJS project with PayloadCMS
-
Go to your desired folder and run the following command on your terminal
Terminal window npx create-payload-app -
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
blanktemplate. -
Then, choose
sqliteas 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└ -
Wait until the installation is finished.
-
After the installation is finished, you can run the project with the following command:
Terminal window npm run devTerminal window yarn dev -
You can access the PayloadCMS dashboard by visiting
http://localhost:3000/adminon your browser.