Chapter 2
Install everything you need — and learn how to use AI not just to follow instructions, but to understand what you're doing and why.
Here's a dirty secret about learning to code: getting your development environment up and running is often the hardest part. Not because it's conceptually difficult, but because it involves a lot of moving pieces, version numbers, operating system quirks, and configuration steps that nobody warned you about. Many beginners have quit before writing a single line of application code, defeated by an error message during setup.
This chapter is where AI really earns its place as your learning companion. We're going to install everything you need — PHP, Composer, Node.js, and a full Laravel project — and at every step we'll use AI not just to follow instructions, but to understand what we're actually doing and why. By the end of this chapter, you'll have a working development environment and — more importantly — the skills to troubleshoot your own setup when things go sideways.
And they will go sideways, at least a little. That's completely normal. Let's talk about that first.
Before we install a single thing, let's reframe how you think about error messages. For most beginners, an error message feels like a failure. The terminal turns red, something goes wrong, and the instinct is to panic or give up.
Professional developers feel the opposite. An error message is information. It's the computer telling you exactly what went wrong, in what file, on what line. A blank screen with no feedback is the scary thing — errors are your friends.
With AI in your toolkit, error messages become even less intimidating, because you have an expert on call who can read them with you. The skill we're building in this chapter isn't just 'follow these steps.' It's: when something doesn't work, here's how to figure out why.
The troubleshooting mindset
When you hit an error during setup (or any time), follow this sequence:
Before we open a terminal, let's understand what our development stack actually consists of. This is the kind of context that AI is great at providing — but it's worth having a clear mental map before you dive in.
PHP is the programming language we'll write our application code in. It runs on the server — meaning it executes on your computer (or eventually a web server), not in the user's browser. When someone requests a page from a PHP application, PHP processes the logic, talks to the database if needed, and sends back HTML to the browser.
Composer is PHP's package manager. Think of it as an app store for PHP code — it lets you download and manage libraries that other developers have written. Laravel itself is installed via Composer, as are most of the tools you'll add to your projects.
Even though we're building a PHP application, we need Node.js installed for Laravel's frontend asset pipeline (Vite, which compiles your CSS and JavaScript). You won't write much Node.js code yourself in this book, but it needs to be present.
Laravel is the PHP framework we'll build everything in. It's not a separate program you install globally — each project you create gets its own copy of Laravel, managed by Composer.
To see your application in a browser, you need a web server running locally on your machine. Laravel includes a simple built-in server for development, and we'll also look at Laravel Herd — a beautiful desktop application that manages your local environment with almost no configuration.
A note on operating systems
The instructions in this chapter cover macOS and Windows. The commands are slightly different between them, and we'll note where that matters.
If you're on Linux, the process is similar to macOS for most steps. Paste each command into your AI assistant with 'I'm on Ubuntu' or whatever your distribution is, and it'll adapt the instructions for you.
Regardless of your OS, the concepts are identical — only the syntax of the commands changes.
If you're on macOS or Windows and you want the fastest path to a working environment, Laravel Herd is the answer. It's a free desktop application that installs PHP, a web server, and everything else you need in one click — no terminal commands, no version conflicts, no configuration files.
We recommend this path for most beginners, because it lets you focus on actually learning Laravel rather than fighting your development environment. Here's how to get it set up.
You should see a PHP version number printed. If you do, Herd is working correctly. If not, paste the error into your AI assistant — Herd errors during installation are almost always either a permissions issue or a conflicting PHP installation, and both are easy to fix with a little guidance.
If you prefer full control over your environment, or if you're on Linux, here's how to install everything manually. This path gives you a deeper understanding of what's happening, at the cost of more terminal work upfront.
On macOS, the easiest way is via Homebrew — a package manager for macOS that works similarly to Composer but for system tools. If you don't have Homebrew installed:
Try this prompt
I'm on macOS and I need to install Homebrew. Walk me through the steps, explain what each command does, and tell me what to expect when it's running.
Once Homebrew is installed, installing PHP is a single command:
On Windows, the recommended approach is to use a tool called XAMPP or to install PHP directly via winget:
After installation, verify PHP is available by running:
You should see something like 'PHP 8.3.x' (the exact version will vary). If you see a 'command not found' error, your system doesn't know where PHP is installed — this is a PATH issue, and it's one of the most common setup problems.
Watch out
'Command not found' usually means the program was installed, but your terminal doesn't know where to find it. This is called a PATH problem. Rather than guess at the fix, paste your exact error message into your AI assistant along with your operating system and the command you ran — it will give you the specific fix for your setup.
Go to getcomposer.org and follow the download instructions for your OS — or ask AI to walk you through it:
Try this prompt
I have PHP installed on [your OS]. Walk me through installing Composer globally, explain what 'globally' means in this context, and show me how to verify the installation worked.
Once installed, running this command should print Composer's version number:
Go to nodejs.org and download the LTS (Long Term Support) version. LTS versions are more stable and better supported than the latest release — always prefer LTS for development tools unless you have a specific reason not to.
After installation, verify both Node and npm (the Node package manager, which comes bundled with Node) are available:
With PHP and Composer installed (either via Herd or manually), you're ready to create a Laravel project. This is a moment worth appreciating: with a single command, Composer will download Laravel and all its dependencies and set up a complete, ready-to-run application structure.
Open your terminal, navigate to the folder where you want to keep your projects (your home folder or a 'projects' subfolder works well), and run:
You'll see a stream of output as Composer downloads packages. This will take a minute or two. When it finishes, you'll have a new folder called my-first-app containing a complete Laravel installation.
What just happened?
Composer just downloaded Laravel and about 30 other PHP packages that Laravel depends on. These all live in a folder called vendor inside your project.
You should never edit files inside vendor directly, and you don't need to. You'll rarely even look in there. Composer manages that folder entirely — if you delete it, a single composer install command will recreate it.
This is the magic of package managers: dependencies are reproducible. Anyone can clone your project and run composer install to get an identical setup.
Let's see it in the browser. Navigate into your new project folder and start Laravel's built-in development server:
You'll see output like this:
Open your browser and go to http://127.0.0.1:8000. You should see Laravel's default welcome page — a clean screen with the Laravel logo and version number. If you see that, congratulations: you have a fully working Laravel installation.
What is Artisan?
Artisan is Laravel's command-line tool. It ships with dozens of useful commands for generating code, running database migrations, clearing caches, and much more. You'll use it constantly throughout this book.
The php artisan serve command you just ran starts a development web server. It's not suitable for production — but it's perfect for local development.
Run php artisan list to see all available commands. Don't worry about understanding them yet — we'll introduce them as we need them.
Let's open the project in a code editor and take a look at what Composer created. If you don't have a code editor installed, VS Code is the most popular choice and it's free — download it from code.visualstudio.com.
Open the my-first-app folder in your editor. You'll see something like this:
That might look overwhelming right now. Don't try to understand it all at once — you'll get familiar with each folder naturally as we build things. For now, just notice the big picture: there's a clear separation between your application code (app/), your configuration (config/), your database work (database/), your web-facing files (public/), and your templates (resources/).
This structure is intentional and consistent across all Laravel projects. One of the great benefits of using a framework is that when you look at someone else's Laravel project, you already know where to find things.
Try this prompt
I'm looking at a fresh Laravel project structure for the first time. Can you explain what the 'app' folder contains and how it relates to the 'routes' folder? Use a simple analogy if possible.
Open the file called .env in the root of your project. You'll see a collection of key-value pairs that control how your application behaves. This includes things like your database connection details, your application name, and whether you're in 'debug' mode.
Notice that DB_CONNECTION is set to 'sqlite' by default in recent Laravel versions. SQLite is a file-based database — no server required — which makes it perfect for getting started. We'll work with this in Chapter 10 when we get to databases.
The .env file is deliberately excluded from version control (you'll see it listed in .gitignore). That's because it often contains passwords and API keys that should never be shared. Every developer on a project maintains their own .env file locally.
Watch out
Never commit your .env file to a public Git repository. It contains sensitive configuration including your APP_KEY, which is used for encryption. If you accidentally expose it, rotate your keys immediately.
If you ever push a project to GitHub, double-check that .gitignore includes .env before your first commit.
Let's talk about the AI troubleshooting workflow in practical terms, because you'll use it constantly — not just during setup, but throughout your entire career.
The key insight is this: the quality of the answer you get from AI depends almost entirely on the quality of the information you give it. A vague question gets a vague answer. Here's what a good error report to an AI looks like:
How to ask AI about an error
Bad: 'My Laravel setup isn't working, what do I do?'
Good: 'I'm trying to run php artisan serve on macOS 14 with PHP 8.3.4 installed via Homebrew. When I run the command I get this error: [paste full error message here]. I've already tried [thing you tried]. What's causing this and how do I fix it?'
The good version gives the AI: your OS and version, the exact PHP version, the exact command you ran, the exact error message, and what you've already tried. With all that context, you'll get a specific, actionable answer almost every time.
One more thing worth knowing: AI tools sometimes give you a fix that works without fully explaining why. When that happens, follow up. Ask: 'That fixed it — can you explain what was causing the problem and why that fix worked?' Building understanding from fixes is one of the best learning habits you can develop.
By this point, you should have:
If any of those aren't in place yet, that's completely fine — use the AI troubleshooting workflow from this chapter to work through whatever's blocking you. The setup phase genuinely is the hardest part for many beginners, and getting through it is an achievement worth recognizing.
In the next chapter, we're going to focus on the most important skill in the AI era: reading and understanding code you didn't write. We'll take the Laravel welcome page you just saw in the browser and trace it all the way back through the framework to understand how it got there.
✦ Exercises
php artisan list in your terminal and browse through the commands. Pick three that sound interesting and ask your AI assistant to explain what each one does and when you'd use it.routes/web.php file in your editor. You'll see a small amount of code that controls what happens when you visit the homepage. Ask your AI assistant: 'Can you explain this entire file line by line, including what the Route::get method does and how it knows to show the welcome page?'routes/web.php, change the text 'welcome' to 'welcomeXYZ' and refresh your browser. You should see an error. Read the error message, identify the key phrase, and see if you can figure out what went wrong before asking AI. Then put it back.APP_ENV=local and APP_ENV=production in a Laravel .env file, and why does it matter?'Next up: Chapter 3 — Reading Code You Didn't Write