Installing Laravel & Initial Setup
In Chapter 1, we focused on understanding Laravel — what it is, why developers use it, and how it compares with Core PHP and other frameworks. Now we're moving from understanding Laravel to actually running Laravel.
In this lesson, you'll prepare your development environment, install Laravel, create your first application, and verify that everything is actually working — not just installed.
By the end of this lesson, you should be able to answer four simple questions:
- What does Laravel need to run?
- What does Composer do?
- How do I create a Laravel application?
- How do I know my environment is actually working correctly?
What Are We Actually Installing?
A Laravel application isn't one single program you download — it sits on top of a few separate tools, each with its own job:
Your Laravel Application
│
├── PHP — the language Laravel is written in
├── Composer — installs Laravel and its packages
└── A database — stores your application's data (SQLite by default, MySQL optional)
We're setting up each of these individually rather than through an all-in-one bundle. It takes a few extra steps, but it gives you a much clearer picture of what's actually happening — and it's closer to how Laravel runs on a real server anyway.
What You'll Need
- PHP (Laravel 13 requires PHP 8.3 or higher)
- Required PHP extensions
- Composer — PHP's dependency manager
- A database — Laravel 13 ships pre-configured for SQLite; MySQL is optional and covered in Step 9
- VS Code or another code editor
- A terminal — you'll use it constantly with Laravel
Step 1: Check PHP
Before installing anything, check whether PHP is already on your system:
php -v
You should see something like PHP 8.3.x (cli) .... If it's already 8.3 or higher, skip ahead to Step 2.
Check first, install second. Installing PHP when a version already exists can create confusing problems later — multiple PHP versions, PATH conflicts, or Composer silently using a different PHP than your terminal does.
If PHP isn't installed or is outdated, we've already covered this in detail for every OS in a dedicated guide: How to Install PHP on Windows, Linux, and macOS. Follow the steps there, then come back and confirm with php -v again.
Step 2: Check PHP Extensions
Laravel's core framework has a base set of required PHP extensions, but the exact list your project needs depends on which packages it uses — Composer, not this list, is the real source of truth. When you run composer install or composer create-project, Composer reads each package's composer.json and checks your installed extensions against it. If something is missing, Composer will tell you exactly which extension and which package needs it, rather than you having to guess.
Check what's currently enabled:
php -m
Extensions Laravel's framework itself requires (present in almost every standard PHP install):
- Ctype
- cURL
- DOM
- Fileinfo
- Filter
- Hash
- Mbstring
- OpenSSL
- PCRE
- PDO
- Session
- Tokenizer
- XML
BCMath and other extensions are only needed if a specific package you install depends on them (for example, some payment or math-heavy packages) — they aren't a universal Laravel requirement, so don't install them pre-emptively.
If something is missing on Linux:
sudo apt install php-mbstring php-xml
On Windows and macOS, these are usually enabled by default depending on how PHP was installed.
Useful habit: if Composer or Laravel ever complains about a missing extension, don't guess-install random packages. Run php --ini to see exactly which configuration file PHP is actually using — this is especially useful when your terminal and web server seem to be running different PHP setups. Once you know the file, you can confirm the extension is actually enabled there rather than in a php.ini Composer isn't reading.
Step 3: Install Composer
Composer downloads Laravel and every package your project depends on — the direct PHP equivalent of npm.
On Windows: Download and run the official installer from getcomposer.org — it auto-detects your PHP installation and sets up your PATH automatically.
On macOS/Linux:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
Verify it:
composer -V
At this point, both of these should work:
php -v composer -V
If either fails, fix it before moving on — everything from here depends on both working correctly.
Step 4: Install the Laravel Installer (Optional)
You can create a Laravel project through Composer alone, so this step isn't required — but the Laravel installer gives you shorter commands, a guided setup wizard (starter kit choice, testing framework, database choice), and is what this course recommends for consistency:
composer global require laravel/installer
On Linux/macOS, make sure Composer's global bin directory is in your PATH — usually ~/.composer/vendor/bin or ~/.config/composer/vendor/bin. Verify it:
laravel --version
Worth knowing: the Laravel installer is not Laravel itself — it's a convenience tool that helps you create Laravel applications. laravel new my-first-project walks you through an interactive setup wizard and produces the same underlying application as composer create-project laravel/laravel my-first-project, which skips the wizard and gives you the framework defaults with no prompts. Use the installer when you want the guided setup this course follows; use Composer directly when you're scripting project creation or automating environment setup (for example, in CI) and want to avoid interactive prompts.
Step 5: Create Your First Laravel Application
laravel new my-first-project
or, without the installer:
composer create-project laravel/laravel my-first-project
If you used laravel new, you'll be prompted with a few setup questions — which starter kit to use, which testing framework (Pest or PHPUnit), and which database to configure. For this course, accept the defaults, which sets you up with SQLite.
Once it finishes:
cd my-first-project ls
You should see folders and files like:
app/ bootstrap/ config/ database/ public/ resources/ routes/ storage/ vendor/ .env artisan composer.json
Don't worry about what each one does yet — that's the focus of the next lesson.
Step 6: A Quick Word on vendor/
One folder worth understanding immediately: vendor/ holds every package Composer installed for your project, including Laravel itself.
Never manually edit anything inside vendor/. Your own code always lives in app/, routes/, resources/, config/, and database/. If vendor/ ever gets deleted, Composer can rebuild it entirely with:
composer install
This matters more than it sounds — it's exactly why vendor/ is excluded from Git in every Laravel project.
Step 7: Basic Environment Setup
Laravel needs a couple of quick setup steps before it can run. If you used laravel new with the interactive wizard, this is usually done for you automatically. If you used composer create-project, or want to confirm it yourself, run:
macOS/Linux (bash/zsh):
cp .env.example .env php artisan key:generate
Windows (Command Prompt):
copy .env.example .env php artisan key:generate
Windows (PowerShell):
Copy-Item .env.example .env php artisan key:generate
We'll cover exactly how .env and configuration work later in this chapter.
Step 8: Understand and Configure Your Database
Since Laravel 11, a freshly created project is configured for SQLite by default — no separate database server to install, and no credentials to set up. If the installer's wizard set this up for you, your .env should already contain:
DB_CONNECTION=sqlite
and a database/database.sqlite file should already exist (the installer creates it and runs migrations for you). If it doesn't exist yet, create it and migrate:
touch database/database.sqlite php artisan migrate
(On Windows, use type nul > database\database.sqlite in Command Prompt, or New-Item database\database.sqlite in PowerShell.)
If you'd rather use MySQL instead of SQLite (this course's original default), install and run it separately:
On Windows: Download the official MySQL Installer and follow the setup wizard.
On macOS:
brew install mysql brew services start mysql
On Linux (Ubuntu/Debian):
sudo apt install mysql-server sudo systemctl start mysql sudo systemctl enable mysql
Verify MySQL is running:
mysql -u root -p
If it prompts for a password and lets you in, MySQL is installed and ready.
Then create a database:
CREATE DATABASE my_first_project;
And update every one of these values in .env to match — switching connections means replacing the whole block, not just DB_DATABASE:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=my_first_project DB_USERNAME=root DB_PASSWORD=your_password
Whichever database you choose, php artisan migrate will only succeed once Laravel can actually reach it — for SQLite that means the .sqlite file must exist and be writable; for MySQL it means the server must be running and the credentials above must be correct.
Step 9: Run the Development Server
php artisan serve INFO Server running on [http://127.0.0.1:8000].
Open http://127.0.0.1:8000 in your browser — you should see the Laravel welcome page.
Step 10: Don't Stop at the Welcome Page — Verify Properly
Seeing the welcome page is a good sign, but it's not a full check. Two commands worth running now and whenever something feels off later:
php artisan about
This prints your app's environment, PHP version, and configuration at a glance — genuinely useful for spotting what's actually running instead of guessing.
php artisan migrate
If this runs without errors, it confirms something the welcome page can't: Laravel successfully talked to your database (SQLite or MySQL). That's a real, working setup — not just a page that loaded.
Step 11: Set Up Your Code Editor
A few VS Code extensions worth installing:
- PHP Intelephense — PHP autocompletion and error checking
- Laravel Blade Snippets — syntax highlighting for Blade templates
- Laravel Extra Intellisense — smarter autocompletion for routes, views, and config keys
None of these are required — Laravel runs entirely fine from the terminal without any editor extensions.
Step 12: Linux/macOS Permissions
If you're on Linux or macOS, you may eventually see permission errors on storage/ and bootstrap/cache/ — Laravel needs these writable for logs, cache, and compiled files.
Avoid the common shortcut of running chmod -R 777 . — it grants far more access than necessary. A safer, scoped fix:
chmod -R 775 storage bootstrap/cache
This isn't needed on a typical Windows setup, since Windows doesn't enforce Unix-style permissions the same way.
Installation Checklist
Before moving on, confirm each of these works:
php -v composer -V laravel --version php artisan --version php artisan about php artisan migrate php artisan serve
If all seven run cleanly, your environment is genuinely ready — not just assumed to be.
What's Next
Your Laravel application is installed, running, and connected to a real database. In the next lesson, we'll take a deep dive into the project structure — what app/, routes/, config/, and every other folder actually does, and where your own code will go.