Installing Strapi and Deploying with Nginx Locally
Strapi is an open-source headless content management system built with JavaScript and powered by Node.js. It provides an intuitive admin panel for managing content through APIs.
Creating a New Project with Strapi
To initiate a new project, execute the following command:
npx create-strapi-app@latest my-project
You will be prompted to choose between "quickstart" and "custom" installation options.
The quickstart option configures Strapi to use its default SQLite database, which is recommended for initial setup. Proceeding with quickstart is straightforward and avoids complications during the setup process.
In contrast, using a local MySQL data base may introduce issues when transferring data between projects. Therefore, it's advisable to opt to the default database unless specific requirements demand otherwise.
Starting the Application
Launch the application using the development mode:
npm run develop
Once running, access the admin panel at http://localhost:1337/admin/.
Local Deployment Using Nginx
For managing Node.js services, consider installing PM2:
npm install pm2 -g
Basic PM2 commands include:
pm2 start <app>– Start an applicationpm2 stop <ID>– Stop a specific servicepm2 stop all– Stop all services
Create a server.js file in the project root directory to manage Strapi:
const strapi = require('@strapi/strapi');
const application = strapi({ distDir: './dist' });
application.start();
Next, configure Nginx by modifying nginx.conf:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:1337;
}
}
After saving the configuration, restart Nginx to apply changes.
Installing Strapi v5
Ensure Node.js version 18 or higheer is installed before proceeding.
Use the following command to create a new Strapi v5 project:
npx create-strapi my-strapi-project