Setting Up Your Environment: PHP, Composer, and Node.js
In this article, we'll walk through installing and verifying PHP, Composer, and Node.js on Windows, macOS, and Linux, so that by the end, your machine is fully ready for the next step: installing Laravel itself.
Introduction
Before you can install Laravel and start building your first application, you need to prepare your development environment. Laravel doesn't run in isolation — it depends on a few key tools working together behind the scenes: PHP (the language Laravel is built with), Composer (the dependency manager that installs Laravel and its packages), and Node.js (used for compiling frontend assets like CSS and JavaScript).
Skipping or misconfiguring any of these can lead to confusing errors down the line, so it's worth taking the time to set things up properly from the start. The good news is that this process is fairly straightforward on any major operating system, and you only need to do it once.
In this article, we'll walk through installing and verifying PHP, Composer, and Node.js on Windows, macOS, and Linux, so that by the end, your machine is fully ready for the next step: installing Laravel itself.
Why These Three Tools Matter
Before jumping into installation steps, it helps to understand what each tool actually does:
PHP is the server-side programming language that powers Laravel. Laravel is essentially a large, well-organized PHP application, so you need a compatible PHP version installed on your machine.
Composer is PHP's package manager. It handles downloading Laravel itself, along with any third-party libraries your project depends on, and keeps track of version compatibility between them.
Node.js (with its package manager, npm) is used to install and run frontend build tools like Vite, which Laravel uses by default to compile CSS and JavaScript assets.
Laravel's current versions typically require PHP 8.2 or higher, so it's important to install a recent version rather than relying on an outdated one that might already be on your system.
Installing PHP
On Windows: The easiest approach is to install a package like XAMPP or Laragon, both of which bundle PHP, a local server, and MySQL together. Alternatively, you can install PHP standalone by downloading it from windows.php.net, extracting it, and adding the folder to your system's PATH environment variable.
On macOS: The simplest method is using Homebrew:
brew install phpThis installs the latest stable PHP version and automatically configures it for command-line use.
On Linux (Ubuntu/Debian): You can install PHP along with common extensions Laravel needs:
sudo apt update
sudo apt install php php-cli php-mbstring php-xml php-bcmath php-curl unzipVerifying your PHP installation: Once installed, confirm it's working by running:
php -vThis should print the installed PHP version. If you see an error saying php is not recognized, double-check that PHP has been added to your system's PATH.
Installing Composer
Composer is required to actually download and install Laravel, so this step is essential.
On Windows: Download and run the official installer from getcomposer.org. It will automatically detect your PHP installation and set everything up.
On macOS and Linux: Run the following commands in your terminal:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composerVerifying your Composer installation:
composer -vYou should see the installed Composer version printed to your terminal, confirming it's ready to use.
Installing Node.js
Node.js isn't strictly required to run a basic Laravel backend, but it's essential if you plan to work with Laravel's default frontend tooling (Vite, Tailwind CSS, etc.), which most modern Laravel projects use.
Recommended approach (all platforms): Download the LTS (Long-Term Support) version from nodejs.org, which includes npm automatically.
Alternatively, using a version manager like nvm is a great option, especially if you work on multiple projects requiring different Node.js versions:
nvm install --lts
nvm use --ltsVerifying your Node.js installation:
node -v
npm -vBoth commands should return version numbers without errors.
Step-by-Step Environment Checklist
Follow this checklist to make sure everything is properly set up before moving on:
Install PHP 8.2 or higher using your OS's preferred method (Homebrew, apt, or an installer).
Verify PHP by running
php -vin your terminal.Install Composer using the official installer for your operating system.
Verify Composer by running
composer -v.Install Node.js LTS either directly or through a version manager like nvm.
Verify Node.js and npm by running
node -vandnpm -v.Restart your terminal if any command isn't recognized — this often resolves PATH-related issues.
Check required PHP extensions (mbstring, openssl, PDO, XML, cURL) are enabled, since Laravel depends on these.
FAQ About Setting Up Your Environment
1. Do I need to install PHP, Composer, and Node.js separately, or is there an all-in-one tool? Tools like Laragon (Windows) or Laravel Herd (macOS/Windows) bundle PHP, Composer, and a local server together, which can simplify setup. Node.js usually still needs to be installed separately.
2. What PHP version does Laravel require? This depends on the Laravel version you're using, but recent releases generally require PHP 8.2 or higher. Always check the official Laravel documentation for the exact requirement of the version you're installing.
3. Can I use Laravel without installing Node.js? Yes, technically the PHP backend runs independently of Node.js. However, you won't be able to compile frontend assets using Vite without it, which most starter kits rely on by default.
4. Why do I need Composer instead of just downloading Laravel manually? Composer manages not just Laravel itself, but all of its internal dependencies and their exact version compatibility, something that would be extremely tedious and error-prone to do manually.
5. What's the difference between installing Node.js directly and using nvm? Installing directly gives you one fixed Node.js version, while nvm (Node Version Manager) lets you install and switch between multiple versions easily, which is helpful if you work on different projects with different requirements.
6. I installed everything, but php -v still isn't recognized. What should I do? This is almost always a PATH configuration issue. Make sure the folder containing your PHP executable is added to your system's PATH environment variable, then restart your terminal or computer.
Conclusion
Setting up your environment properly is a small investment that saves you a lot of headaches later. With PHP, Composer, and Node.js installed and verified, your machine is now ready to actually install Laravel and start building.
In the next article, we'll walk through installing Laravel step by step using Composer, so you can create your very first Laravel project and see it running locally.
Found this helpful? Share it!