Getting Started with Laravel: Setting Up a Laravel Development Environment
Backend • 5 min read

Getting Started with Laravel: Setting Up a Laravel Development Environment

Julius Fasema

Author

Learn how to set up Laravel from scratch with PHP, Composer, Node.js, npm, Laravel Installer, and frontend asset tools in this practical guide.

Laravel is a popular PHP framework for building modern web applications. Before creating a Laravel application, however, the development environment needs to be properly configured.

In this practical guide, we will walk through the process of setting up Laravel from scratch, including PHP, Composer, Node.js and npm, creating a new Laravel application, installing its dependencies, compiling frontend assets, and starting the development server.

The steps below are based on the actual setup process encountered while preparing a Laravel development environment.

What We Need

Before creating the Laravel application, we need the following tools:

  • PHP
  • Composer
  • Node.js and npm, or Bun
  • Laravel Installer
  • A code editor such as Visual Studio Code
  • A terminal or command prompt

The basic workflow looks like this:

1. Install Composer

Laravel uses Composer to manage its PHP dependencies.

The first step is to install Composer.

Visit the official Composer website:

https://getcomposer.org

Select Download and choose the installation instructions appropriate for your operating system.

Composer provides installation instructions for platforms including:

  • Windows
  • macOS
  • Linux
  • Unix-based systems

After installation, open a new terminal and verify that Composer is available:

composer --version

A successful installation should return the installed Composer version.

For example:

Composer version 2.x.x

If the terminal reports that composer is not recognized, the Composer executable has probably not been added correctly to the system PATH.

2. Install PHP

Laravel is a PHP framework, so PHP must be installed before Laravel can run.

Verify the PHP installation:

php --version

The command should display the installed PHP version.

For example:

PHP 8.x.x

It is important that the PHP executable is accessible from the terminal.

If this command fails with a message such as:

'php' is not recognized as an internal or external command

the PHP installation directory needs to be added to the system PATH.

Why PATH Matters

The operating system needs to know where commands such as php and composer are located.

For example, on Windows, the PHP directory might look similar to:

C:\php

or, if PHP is installed through a local development package:

C:\xampp\php

The exact location depends on how PHP was installed.

After changing the PATH, open a new terminal window and test the command again.

3. Install Node.js and npm

Laravel applications commonly use JavaScript tooling to compile frontend assets.

Install either:

  • Node.js and npm, or
  • Bun

For Node.js, verify the installation with:

node --version

Then check npm:

npm --version

Both commands should return their respective versions.

For example:

node --version

v22.x.x

npm --version

10.x.x

The exact versions will depend on when the development environment is created.

4. Install the Laravel Installer

Once Composer is working, install the Laravel installer globally:

composer global require laravel/installer

Composer downloads the Laravel installer and makes it available globally for the current user.

After installation, verify that the Laravel command is available:

laravel --version

You should see the installed Laravel Installer version.

If laravel is not recognized, Composer's global binary directory may not be included in the system PATH.

This is another common environment configuration issue.

5. Create a New Laravel Application

With the Laravel installer available, we can create our first application.

Run:

laravel new example-app

Here, example-app is the name of the application.

You can replace it with the name of your own project:

laravel new inventory-app

Laravel will create the project directory and generate the application's initial structure.

A newly created Laravel project contains directories and files similar to:

The exact structure can vary between Laravel versions.

6. Move Into the Application Directory

After Laravel creates the application, change into the project directory:

cd example-app

From this point onward, commands such as php artisan, composer, and npm are normally executed from inside the project directory.

For example:

php artisan

should display Laravel's Artisan command list.

7. Install Frontend Dependencies

Laravel applications can contain frontend assets that need to be processed before the application is ready for development.

Install the project's JavaScript dependencies:

npm install

This command reads the project's package.json file and installs the required packages.

The resulting dependencies are normally placed inside:

node_modules/

The node_modules directory should generally not be committed to Git because it can be recreated from package.json.

8. Build the Frontend Assets

After installing the JavaScript dependencies, build the application's frontend assets:

npm run build

This executes the build script defined in the project's package.json.

Laravel projects commonly use Vite for frontend asset development and production builds.

For development, you may also encounter:

npm run dev

The development command starts the frontend asset development process and watches for changes.

9. Start the Laravel Application

Laravel provides a convenient development command for starting the application's local development environment:

composer run dev or php artisan serve

Depending on the Laravel project configuration, this command can start the different development processes required by the application.

Once the development environment is running, Laravel will provide a local address that can be opened in a web browser.

A typical Laravel development address is:

http://localhost:8000

Open the displayed address in a browser.

If everything is correctly configured, the Laravel application should load.

10. Understanding What Happened

At this point, we have gone through several different tools.

It is useful to understand the role of each one.

PHP

PHP is the programming language that Laravel runs on.

PHP → Runs Laravel

Composer

Composer manages PHP packages and dependencies.

Composer → Manages PHP dependencies

Laravel Installer

The Laravel installer provides a convenient command for creating Laravel applications.

Laravel Installer → Creates Laravel projects

Node.js and npm

Node.js provides the JavaScript runtime used by the frontend tooling, while npm manages JavaScript packages.

Node.js → JavaScript runtime

npm → JavaScript package manager

Vite

Vite handles the development and compilation of frontend assets in modern Laravel applications.

Vite → Builds frontend assets

Artisan

Artisan is Laravel's command-line interface.

For example:

php artisan

It provides commands for tasks such as:

  • Creating controllers
  • Creating models
  • Running database migrations
  • Clearing caches
  • Starting development services
  • Inspecting application configuration

Common Setup Problems

Setting up Laravel is straightforward once the required tools are correctly configured. However, environment configuration can cause problems.

php Is Not Recognized

If:

php --version

does not work, verify that PHP is installed and that its installation directory has been added to the system PATH.

After changing PATH, restart the terminal.

composer Is Not Recognized

If:

composer --version

fails, verify the Composer installation and PATH configuration.

Again, open a new terminal after modifying environment variables.

laravel Is Not Recognized

The Laravel installer may have been installed successfully while its executable directory is not available through PATH.

First verify that Composer installed the package:

composer global show laravel/installer

If it is installed, check Composer's global binary directory:

composer global config bin-dir --absolute

The returned directory needs to be accessible through the system PATH.

npm Is Not Recognized

If:

npm --version

fails, Node.js may not be installed correctly or its installation directory may not be available through PATH.

Verify:

node --version

npm --version

Both commands should work before attempting:

npm install

The Complete Setup in One Sequence

Once the environment is configured correctly, the process becomes relatively simple.

composer global require laravel/installer

laravel new example-app

cd example-app

npm install

npm run build

composer run dev

The important point is that these commands depend on the underlying development environment being correctly configured.

PHP must be available for Laravel.

Composer must be available for PHP dependency management.

The Laravel installer must be available for creating the project.

Node.js and npm must be available for frontend asset management.

Once those pieces are in place, creating and running a Laravel application becomes a repeatable process.

Conclusion

Setting up Laravel involves more than installing the Laravel framework itself. A functional development environment requires PHP, Composer, Laravel's installer, and a JavaScript runtime and package manager such as Node.js and npm.

Understanding this setup process is useful because many problems encountered when starting a Laravel project are not actually Laravel problems. They are often related to PHP, Composer, Node.js, npm, or environment PATH configuration.

Once the environment is correctly configured, we can move from installation into the more interesting part of Laravel development: building the application itself.

Tags

Laravel, PHP, Composer, Laravel Installer, Node.js, npm, Vite, Web Development, PHP Framework, Laravel Tutorial, Laravel Setup, Laravel Installation, Backend Development, Frontend Development, Full Stack Development