The Ultimate Step-by-Step Guide to Installing Strapi.js on Your Local Machine

Facebook
LinkedIn
Table of Contents

1. Introduction

Strapi.js is a powerful open-source, headless content management system that provides the developers a chance to create and manage their own API with customizability. Strapi separates the backend from the frontend, which means you can use any tool or framework you want, such as React, Next.js, or anything else. Ensuring a proper setup is the key to unlocking all functionalities of Strapi.

A well-set-up environment in Strapi leads to the development of seamless applications, reduces downtime, and ultimately the way towards scalable and secure applications. A seasoned developer or a newcomer, it is necessary to follow the right steps from the very beginning to save time and prevent headaches later.

Thumbnail Kvy (1)

2. Prerequisites

Installation of Strapi should be done only after ensuring that your system is prepped and ready. It is like laying first a solid foundation before building a house. Here, the prerequisites for a seamless installation are listed. At the end of it, you’ll have everything you need to start your Strapi journey.

2.1. Node.js

Node.js Requirements

Node.js is the linchpin of the Strapi.js which is a server-side JavaScript-based application. Ensure that you are using one of the Active LTS or Maintenance LTS versions to guarantee stability and compatibility.

Supported Versions

  • v18
  • v20

Note: Odd-numbered “current” releases (e.g., v19, v21) are not supported. 

Installation

If Node.js isn’t installed, download the latest LTS version from the official Node.js website and follow the installation instructions for your OS. 

curotec nodejs

Verify Installation

Open your terminal and run: 

node -v

Ensure the version is within the supported range (v18 to v20). 

Keep Node.js updated to the latest LTS for security and performance improvements. 

2.2. npm and Yarn

npm and Yarn – There are two well known package managers npm (Node Package Manager) and yarn which handles all your dependencies in an awesome way. Although they are all reliable, Yarn is often recommended primarily because it much faster and more stable.

Yarn is smarter when it comes to bulk package install, and has better cache capabilities.

To install Strapi you can execute yarn create yarn create strapi-app my-project --quickstart, or you can opt for npm with npx create-strapi-app my-project --quickstart. In either case, however both will work and function properly; Yarn just might leave you a little less jaded. 

Yarn 950x600 1

2.3. System Requirements

Strapi.js is versatile and can run on various operating systems. Here are the recommended options for optimal performance: 

Recommended Operating Systems: 

  • Ubuntu LTS
  • Debian 9.x
  • CentOS/RHEL 8
  • macOS Mojave
  • Windows 10
  • Docker (for containerized environments)

Ensure your system has at least one of these supported databases: 

Supported Databases: 

  • MongoDB
  • MySQL
  • MariaDB
  • PostgreSQL
  • SQLite

3. Installation Options

When comparing different installation methods for Strapi, each has its own unique advantages and steps for setup. Here’s a closer look:  

3.1. Local installation

Installation MethodDetailsGuide
CLI InstallationRequirements: Node.js and a package manager (Yarn/npm) Command: Run yarn create strapi-app my-project --quickstart or npx create-strapi-app my-project --quickstart Outcome: Creates a new Strapi project with a pre-configured SQLite database and launches the local development serverOfficial CLI Installation Guide
DockerRequirements: Docker installation Steps: Create a Dockerfile at the root of your Strapi project Build Docker image: docker build -t my-strapi-app . Run the container: docker run -p 1337:1337 my-strapi-appDocker Installation Documentation

3.2. Remote server installation

Deploying Strapi on a remote server offers the advantage of accessibility from anywhere and better performance for production environments. 

Remote Server Setup 

  • Select a hosting provider (e.g., AWS, Digital Ocean, Heroku).
  • Set up a virtual server with a recommended OS (e.g., Ubuntu).
Computer technology isometric icon, server room, digital device set, element for design, pc laptop, mobile phone with smartwatch, cloud storage, flat vector

Install Prerequisites 

  • Install Node.js (Active LTS version recommended).
  • Install PostgreSQL or your preferred database.

Create or Clone Strapi Project 

  • Clone your existing Strapi project repository.
  • Or create a new Strapi project using Strapi CLI commands.

Configure the Server 

  • Set up a reverse proxy using Nginx.
  • Configure your server to handle requests.

For detailed instructions specific to each hosting provider, refer to the Strapi documentation.

4. Step-by-Step Installation

Ready to dive into the world of Strapi? Installing Strapi.js on your local machine is a breeze when you follow the right steps. Whether you’re setting up a new project for local development or preparing your application for a self-hosted environment, we’ve got you covered. Let’s break it down step-by-step so you can get your Strapi project up and running in no time!

4.1. Step 1: Local installation

Step 1.1: Install Node.js and npm/yarn.

Ensure you have Node.js version 16 or later installed on your machine. You can download it from the official Node.js website. During the installation, npm will also be installed. If you prefer using Yarn, you can install it with the command npm install --global yarn.

Step 1.2: Use the CLI to create a new Strapi project.
Open your terminal and run the following command to create a new Strapi project: npx create-strapi-app my-project --quickstart or yarn create strapi-app my-project --quickstart. This will automatically set up the project with the default configuration.

Step 1.3: Configure project settings (database, authentication, etc.).
After installation, you can adjust your project settings as needed. For instance, you can configure your database by editing the config/database.js file. Strapi supports various databases including MongoDB, MySQL, MariaDB, PostgreSQL, and SQLite.

Step 1.4: Start the development server.
To launch the development server, navigate to your project directory in the terminal and run yarn develop or npm run develop. This starts Strapi in development mode, allowing you to make changes and see them immediately.

4.2. Step 2. Docker installation

Step 2.1: Set up Docker.
If you haven’t already, download and install Docker from the official Docker website. Follow the instructions for your operating system to complete the installation.

Step 2.2: Create a custom Docker image for your Strapi project.
Create a Dockerfile in your project root directory with the necessary configuration to build your Strapi image. Here is a basic example:

FROM strapi/strapi
WORKDIR /srv/app
COPY . .
RUN yarn install

Step 2.3: Run the container.
Use Docker Compose or run the Docker container directly to start your Strapi project. Here is an example Docker Compose configuration:

version: '3'
services:
  strapi:
    build: .
    volumes:
      - .:/srv/app
    ports:
      - '1337:1337'
    environment:
      DATABASE_CLIENT: 'sqlite'
      DATABASE_FILENAME: './data.db'

Save this in a docker-compose.yml file and run docker-compose up to start your Strapi service.

5. Troubleshooting and Common Issues

5.1. Node.js version conflicts 

One of the most frequent issues during installation stems from using an incompatible version of Node.js. Strapi requires a specific range of Node.js versions: 16.x to 18.x for optimal performance. If you encounter a version conflict, ensure you are running a supported version. You can check your Node.js version by executing the following command in your terminal: 

node -v

If an update or downgrade is needed, it’s easiest to manage and switch between different Node.js versions using Node Version Manager (NVM). You can install NVM using: 

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

After installation, simply use: 

nvm install 16.14

to install the required Node.js version. 

5.2. Database connection issues 

Strapi supports various databases such as MongoDB, MySQL, MariaDB, PostgreSQL, and SQLite. Oftentimes, incorrect database configurations can hinder the installation process. Double-check your .env file to ensure that all database credentials are accurate. For instance, a typical PostgreSQL configuration might look like this: 

DATABASE_CLIENT=postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=strapi
DATABASE_USERNAME=your_username
DATABASE_PASSWORD=your_password

If you continue to face issues, verify that your database server is running and that your development environment has connectivity to it. You can use the following command to check the status of your PostgreSQL service: 

sudo systemctl status postgresql

5.3. Docker-related issues

Running Strapi within Docker containers can sometimes pose its own set of challenges. One common problem is container misconfiguration. Ensure that your Docker Compose file is correctly set up. A basic configuration might look like this: 


version: '3'
services:
  app:
    image: strapi/strapi
    environment:
      DATABASE_CLIENT: postgres
      DATABASE_HOST: database
      DATABASE_PORT: 5432
      DATABASE_NAME: strapi
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
    ports:
      - '1337:1337'
  database:
    image: postgres
    environment:
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi

Another frequent issue involves sufficient resource allocation. Docker needs adequate CPU and memory to run efficiently. If you receive errors related to resource allocation, ensure your Docker settings allocate ample resources. Adjust these settings via Docker Desktop by navigating to “Preferences > Resources” and modify them accordingly. 

By systematically addressing these common installation problems, you can ensure a smoother setup experience for your Strapi project.

6. Conclusion

6.1. Recap the installation process. 

Congratulations, you’ve successfully reached the end of our Strapi.js installation guide! Let’s quickly recap the process: 

  1. Prepare your environment: Ensure your system meets the prerequisites like Node.js (preferably the Active LTS or Maintenance LTS versions), npm or Yarn, and Python if you’re using a SQLite database.
  2. Choose your installation method: Decide between a local installation or using Docker, based on your project needs and expertise.
  3. Follow the step-by-step instructions: Whether installing locally or setting up via Docker, use commands like npx create-strapi-app my-project --quickstart or corresponding Docker setups to get your Strapi application up and running.
  4. Troubleshoot common issues: Refer to our troubleshooting section if you encounter Node.js version conflicts, database connection issues, or Docker-related problems.

Now that your Strapi.js server is installed, it’s time to dive deeper! 

6.2. Encourage readers to explore Strapi’s features and start building their projects. 

Strapi offers a robust and flexible platform rich with features to enhance your development experience

  • 💻 A modern and intuitive admin panel that simplifies content management.
  • 🔒 Secure default settings to keep your projects protected from common vulnerabilities.
  • 🔌 Customizable plugins that extend the functionality of your Strapi application seamlessly.
  • 🚀 Support for both SQL and NoSQL databases to suit your specific requirements.

Don’t stop here. Continue exploring Strapi’s extensive documentation, experiment with its various features, and start building powerful APIs that give you complete control over your data. Your journey with Strapi is just beginning, and the possibilities are endless! 

Happy building! 🎉

6.3. FAQs

Q1. How do I know if my system can run Strapi? 

Check the System Requirements section above. You’ll find details about necessary software and hardware.  

Q2. Can I use Strapi with databases other than MongoDB?

Yes, Strapi supports MySQL, MariaDB, PostgreSQL, and SQLite.

Q3. What if I run into issues during installation?

Refer to the Troubleshooting and Common Issues section. It covers common issues and their solutions.

Q4. Can I use Strapi to build APIs?

Absolutely! Strapi supports both GraphQL and REST APIs.

Q5. Is Strapi free to use?

Yes, Strapi is an open-source project and is free to use. However, there are paid plans available that offer additional features and support.

Q6. Do I need to install a database before setting up Strapi?

Yes, you’ll need to have a supported database like MySQL, MariaDB, PostgreSQL, or SQLite installed before setting up Strapi.

Q7. How can I keep Strapi up-to-date?

You can update Strapi by running npm update strapi or yarn upgrade strapi in your project directory. Always read the release notes before updating.

Q8. Can I deploy my Strapi project on cloud services?

Yes, Strapi can be deployed on various cloud services like AWS, Azure, Google Cloud, and DigitalOcean.

Q9. Does Strapi work with frontend frameworks?

Yes, Strapi integrates well with popular frontend frameworks like React, Vue.js, and Next.js.

6.4. References and Resources 

Here are some helpful links to get you started: