Uploaded on Oct 1, 2026
Laravel is one of the most popular PHP frameworks, and Ubuntu is a great environment to run it. This guide shows you how to install Laravel on Ubuntu from scratch: update your system, install PHP 8.2+ with the required extensions, set up Composer, create a new Laravel project and start the development server. It also covers optional database and Vite setup, plus fixes for common errors. It's written for beginners and takes about 15 minutes.
How_to_Install_Laravel_on_Ubuntu
STEP-BY-STEP GUIDE
How to Install Laravel
on Ubuntu
Set up PHP, Composer and a fresh Laravel project on Ubuntu 22.04 / 24.04, and
run it in your browser.
The installation flow at a glance
What you will need: an Ubuntu machine with sudo access, an internet connection and about
15 minutes.
Introduction
Laravel is one of the most popular open-source PHP frameworks for building web applications. It
gives you routing, authentication, database migrations, queues and a clean MVC structure out
of the box. Ubuntu is a great place to run it, because the PHP ecosystem is well supported and
almost everything you need is one apt command away.
This guide walks through the full process: preparing the system, installing PHP and the required
extensions, installing Composer, creating a Laravel project and starting the development
server.
Prerequisites
• Ubuntu 22.04 LTS or 24.04 LTS (other recent versions work the same way)
• A user account with sudo privileges
• PHP 8.2 or higher. Laravel 12 needs at least PHP 8.2; Ubuntu 24.04 ships PHP 8.3 by default
• A terminal (press Ctrl + Alt + T)
Tip: The terminal screenshots in this guide are illustrative. Version numbers and package names on
your machine may differ slightly.
Step 1: Update your system
Always start by refreshing the package index and upgrading existing packages. This avoids
dependency conflicts later.
sudo apt update && sudo apt upgrade -y
Figure 1: Updating Ubuntu packages
Step 2: Install PHP and required extensions
Laravel needs PHP plus a handful of extensions. Install them all in one go, together with unzip,
curl and git, which Composer uses to download packages.
sudo apt install -y php php-cli php-mbstring php-xml \
php-curl php-zip php-sqlite3 php-mysql unzip curl git
How to Install Laravel on Ubuntu Page 2
Confirm that PHP is installed and check its version:
php -v
Figure 2: Installing PHP and verifying the version
Why these extensions?
Extension Purpose
php-mbstring Multibyte string handling (required)
php-xml XML and DOM support (required)
php-curl HTTP requests, used by many packages
php-zip Lets Composer unpack archives faster
php-sqlite3 Default database in new Laravel projects
php-mysql Needed if you use MySQL or MariaDB
If your PHP is older than 8.2 (for example on Ubuntu 22.04, which ships PHP 8.1), add the Ondřej
Surý PPA first:
sudo add-apt-repository ppa:ondrej/php
then run sudo apt update and install php8.3 with the extensions above (for example php8.3-cli
php8.3-mbstring).
Step 3: Install Composer
Composer is the dependency manager for PHP, and Laravel is installed through it. Download
and run the official installer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
How to Install Laravel on Ubuntu Page 3
Move Composer into your PATH so you can run it from anywhere, then check it works:
sudo mv composer.phar /usr/local/bin/composer
composer --version
Figure 3: Installing Composer globally
Security note: For production or shared machines, verify the installer checksum using the
instructions on getcomposer.org/download before running it.
Step 4: Create a new Laravel project
Navigate to the folder where you keep your projects and create the app. Replace example-app
with your own project name.
cd ~
composer create-project laravel/laravel example-app
cd example-app
Composer downloads the framework and its dependencies, then generates your application key
automatically.
Figure 4: Creating the project with Composer
How to Install Laravel on Ubuntu Page 4
Alternative: the Laravel installer
If you prefer the laravel new command, install the installer globally and add Composer's bin
folder to your PATH:
composer global require laravel/installer
echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
laravel new example-app
On some systems Composer's global folder is ~/.composer/vendor/bin instead. Run composer
global config bin-dir --absolute to see the exact path.
Step 5: Run the development server
From inside the project folder, start Laravel's built-in server:
php artisan serve
Figure 5: The development server is running
Open http://127.0.0.1:8000 in your browser. You should see the Laravel welcome page.
Figure 6: The Laravel welcome page (illustration)
How to Install Laravel on Ubuntu Page 5
Press Ctrl + C in the terminal to stop the server.
Step 6: Configure your database (optional)
New Laravel projects use SQLite by default, so you can run migrations straight away:
php artisan migrate
To use MySQL or MariaDB instead, install the server (sudo apt install mysql-server), create
a database and user, then edit the .env file in your project root:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_app
DB_USERNAME=laravel_user
DB_PASSWORD=your_password
Run php artisan migrate again to create the tables.
Step 7: Install front-end assets (optional)
Laravel uses Vite to compile CSS and JavaScript. Install Node.js and npm, then build or watch
your assets:
sudo apt install -y nodejs npm
npm install
npm run dev
The version of Node.js in Ubuntu's default repositories can be old. If npm install complains about
the Node version, install a current LTS release from nodejs.org or with a version manager such as
nvm.
Troubleshooting
“Your requirements could not be resolved” during install
Your PHP version or a missing extension is the usual cause. Run php -v and compare it with
the framework requirement, then install any extension named in the error.
Permission denied on storage or bootstrap/cache
Give your user write access: chmod -R ug+rw storage bootstrap/cache. On a web server,
make the web user (for example www-data) the group owner.
“Port 8000 is already in use”
Run on another port: php artisan serve --port=8080.
“composer: command not found”
Check that /usr/local/bin/composer exists and that /usr/local/bin is in your PATH.
How to Install Laravel on Ubuntu Page 6
Conclusion
You now have PHP, Composer and a working Laravel project on Ubuntu. From here, explore
routes/web.php to add your first page, create a controller with php artisan
make:controller, and read the official documentation at laravel.com/docs. When you are
ready to go live, deploy behind Nginx or Apache with PHP-FPM rather than php artisan serve,
which is meant for local development only.
Quick command reference
sudo apt update && sudo apt upgrade -y
sudo apt install -y php php-cli php-mbstring php-xml php-curl php-zip \
php-sqlite3 php-mysql unzip curl git
sudo mv composer.phar /usr/local/bin/composer
composer create-project laravel/laravel example-app
cd example-app && php artisan serve
How to Install Laravel on Ubuntu Page 7
Comments