How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Install Laravel on Ubuntu: Step-by-Step Guide
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > Web Development > How to Install Laravel on Ubuntu: Step-by-Step Guide
Web Development

How to Install Laravel on Ubuntu: Step-by-Step Guide

how7o
By how7o
Last updated: April 16, 2026
9 Min Read
Install Laravel on Ubuntu — terminal with composer create-project command and Laravel red-pillar icon
SHARE

To install Laravel on a fresh Ubuntu server or development machine you need three things in place: PHP 8.1+ (8.2+ for Laravel 11), Composer, and a handful of PHP extensions. This guide walks through verifying each prerequisite, creating a new Laravel project with composer create-project, configuring the .env file, generating an application key, and booting the dev server so you can hit your app at http://127.0.0.1:8000 within a few minutes.

Contents
  • TL;DR
  • Prerequisites
  • Step 1 — Verify the prerequisites
  • Step 2 — Create a new Laravel project
  • Step 3 — Configure the environment
  • Step 4 — Run the initial migrations
  • Step 5 — Start the development server
  • Troubleshooting
    • “Your requirements could not be resolved to an installable set of packages”
    • “No application encryption key has been specified”
    • “SQLSTATE Connection refused” on migrate
    • Extension missing errors (ext-mbstring, ext-xml)
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-16 with Laravel 11 on Ubuntu 24.04 (PHP 8.3) and Laravel 10 on Ubuntu 22.04 (PHP 8.1). Originally published 2022-07-05, rewritten and updated 2026-04-16.

TL;DR

With PHP and Composer already installed, run composer create-project laravel/laravel your-app-name, cd into the project, copy .env.example to .env, run php artisan key:generate, then start the dev server with php artisan serve. Laravel 11 needs PHP 8.2+; Laravel 10 works with PHP 8.1+.

Prerequisites

  • PHP 8.1+ for Laravel 10, or PHP 8.2+ for Laravel 11. Install: How to Install PHP on Ubuntu.
  • Composer. Install: How to Install Composer on Ubuntu.
  • PHP extensions: mbstring, xml, curl, zip, bcmath, gd, and a database driver (mysql or sqlite3). All available as apt packages: sudo apt install php-mbstring php-xml php-curl php-zip php-bcmath php-gd php-mysql.
  • Node.js and npm (optional at install time, required to build frontend assets with Vite). sudo apt install nodejs npm.

Step 1 — Verify the prerequisites

Quick sanity checks before creating a project:

php -v          # PHP 8.1+ (or 8.2+ for Laravel 11)
composer -V     # Composer 2.x

If either command fails, finish installing the prerequisite before continuing — Laravel’s Composer plugin aborts with unclear errors when PHP is too old.

Step 2 — Create a new Laravel project

Change into the directory where you keep your projects and let Composer scaffold a fresh Laravel app. Replace your-app-name with your project’s directory name:

cd ~/code
composer create-project laravel/laravel your-app-name

Composer downloads the Laravel skeleton, resolves every dependency in composer.json, and runs php artisan key:generate as a post-install hook. By default it installs the latest stable release — currently Laravel 11 (requires PHP 8.2+). To pin to a specific version:

composer create-project laravel/laravel:^10.0 your-app-name
install laravel — create-project, configure .env, key generate, artisan serve flow

Step 3 — Configure the environment

Move into the project and set up the local .env file. The installer usually copies it for you, but doing it explicitly is safe:

cd your-app-name
cp .env.example .env
php artisan key:generate

php artisan key:generate writes a secure random string into APP_KEY. Laravel uses this key to encrypt sessions, cookies, and anything you pass through the Crypt facade — without it the framework refuses to boot with a No application encryption key has been specified error.

Open .env and adjust these defaults for your setup:

APP_NAME=YourApp
APP_URL=http://127.0.0.1:8000

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_app
DB_USERNAME=your_db_user
DB_PASSWORD=your_db_password

For a zero-dependency dev setup — no MySQL required — use SQLite instead:

touch database/database.sqlite
# in .env:
# DB_CONNECTION=sqlite
# (remove or comment out the other DB_* lines)

Step 4 — Run the initial migrations

Laravel ships with migrations for the default users, password_reset_tokens, and sessions tables. Apply them:

php artisan migrate

If you configured SQLite, Artisan will detect the empty database file and prompt to create it if missing. For MySQL, make sure the database (your_app) exists before running — need help setting up MySQL? See How to Install MySQL on Ubuntu 22.04.

Step 5 — Start the development server

php artisan serve

You’ll see Server running on [http://127.0.0.1:8000]. Open that URL in a browser and you should see the Laravel welcome page. Leave the command running — it’s a foreground process. To change the port, pass --port=8001; to bind on all interfaces in a VM, add --host=0.0.0.0.

For production, don’t use php artisan serve. Put nginx or Apache in front with PHP-FPM, or use Laravel Octane if you want persistent application state and higher throughput.

Troubleshooting

“Your requirements could not be resolved to an installable set of packages”

Usually means your PHP version is below the minimum for the Laravel major you’re installing. Composer’s error block lists the exact constraint (e.g. laravel/framework requires php ^8.2.0). Either upgrade PHP via the Ondřej PPA (see the PHP install guide) or install an older Laravel: composer create-project laravel/laravel:^10.0 your-app-name.

“No application encryption key has been specified”

.env has an empty APP_KEY. Run php artisan key:generate from the project root. If the command itself fails, confirm .env exists — a common mistake is editing .env.example and forgetting to copy it.

“SQLSTATE[HY000] [2002] Connection refused” on migrate

The database server isn’t reachable at the host/port in .env. Check that MySQL is running (sudo systemctl status mysql), that the database exists, and that the user in DB_USERNAME has privileges on it. For a quick local workaround, switch to SQLite.

Extension missing errors (ext-mbstring, ext-xml)

Install the missing extension via apt: sudo apt install php-mbstring php-xml and re-run Composer. Every extension Laravel requires is listed in the framework’s composer.json; Composer will tell you which one is missing on each run.

Frequently asked questions

What PHP version does Laravel 11 require?

Laravel 11 requires PHP 8.2 or higher. Laravel 10 supports PHP 8.1+. On Ubuntu 22.04 the default is PHP 8.1, so either use Laravel 10 or add the Ondřej Surý PPA to install PHP 8.2+. On Ubuntu 24.04 (PHP 8.3 default) you’re good to go with Laravel 11 out of the box.

Should I use composer create-project or the Laravel installer?

For a single project, composer create-project laravel/laravel your-app-name is the simplest path — no extra global install. The Laravel installer (composer global require laravel/installer) is slightly faster per project because it clones a pre-built skeleton, but it adds a global dependency to maintain. I use composer create-project for most projects.

What’s the difference between php artisan serve and a real web server?

php artisan serve runs PHP’s built-in development server — single-threaded, no HTTPS, fine for local development only. For anything reachable from outside localhost, put nginx or Apache with PHP-FPM in front, or use Laravel Octane (Swoole/RoadRunner) for production-grade concurrency.

How do I fix “No application encryption key has been specified”?

Your .env is missing APP_KEY. Run php artisan key:generate from the project root — it writes a secure random key into .env. Never commit .env to git; commit .env.example instead.

Do I need a database running before installing Laravel?

No — installation itself doesn’t touch a database. But the default .env points at a local MySQL, so the first time you run php artisan migrate you’ll need one. The quickest alternative is to set DB_CONNECTION=sqlite and touch database/database.sqlite for a zero-dependency dev setup.

Related guides

  • How to Install PHP on Ubuntu — the interpreter Laravel runs on.
  • How to Install Composer on Ubuntu — the dependency manager composer create-project needs.
  • How to Install MySQL on Ubuntu 22.04 — the default database for Laravel projects.

References

Official Laravel installation docs: laravel.com/docs/installation. Release support policy and minimum PHP versions: laravel.com/docs/releases.

TAGGED:ArtisanBashcomposerconfigurationinstallationLaravelphpUbuntu

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Install PHP on Ubuntu — terminal with apt install php command and stylized elephant icon How to Install PHP on Ubuntu (22.04 & 24.04): Step-by-Step Guide
Next Article Configure WordPress multisite with subdirectories on Nginx — nginx gear + wordpress tree with subsite branches How to Configure WordPress Multisite with Subdirectories on Nginx
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Step-by-step guide to upgrading the Linux kernel in CentOS 7 using ELRepo
How to Upgrade the Linux Kernel in CentOS 7
April 16, 2026
Install Node.js on Ubuntu — terminal with NodeSource setup_22.x curl command and Node.js hexagon icon
How to Install Node.js on Ubuntu (22.04 & 24.04): Step-by-Step
April 16, 2026
Configure WordPress multisite with subdirectories on Nginx — nginx gear + wordpress tree with subsite branches
How to Configure WordPress Multisite with Subdirectories on Nginx
April 16, 2026
Install Laravel on Ubuntu — terminal with composer create-project command and Laravel red-pillar icon
How to Install Laravel on Ubuntu: Step-by-Step Guide
April 16, 2026
Install PHP on Ubuntu — terminal with apt install php command and stylized elephant icon
How to Install PHP on Ubuntu (22.04 & 24.04): Step-by-Step Guide
April 16, 2026

You Might Also Like

CSS page break for printing shown in a print preview layout
Web Development

CSS Page Break for Printing: How to Split a Web Page Into Multiple Printed Pages

6 Min Read
How to force quit frozen apps in Ubuntu
OS

Force Close an App in Ubuntu (xkill, System Monitor, kill -9)

4 Min Read
Display only the current date in Laravel using Carbon
Web Development

How to Display Only the Current Date in Laravel (Carbon Examples)

4 Min Read
Create a Directory in Ubuntu
Server Management

Create a Directory in Ubuntu (mkdir Command + Examples)

4 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?