Website Vidya
Cloud & DevOpsStep-by-Step Guide

How to Install Laravel on Ubuntu 24.04

Step-by-step guide on how to install Laravel on Ubuntu 24.04 LTS with PHP 8.3, Composer, Nginx or Apache, and MariaDB. Build modern PHP web applications.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install Laravel on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Step-by-step guide on how to install Laravel on Ubuntu 24.04 LTS with PHP 8.3, Composer, Nginx or Apache, and MariaDB. Build modern PHP web applications.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Updating System Repositories and Installing PHP 8.3
  • Step 2: Installing Composer Globally on Ubuntu
Grounded in full engineering runbookWebsiteVidya AI Engine

Interactive Builder for this Guide

Build your custom nginx syntax (How to Install Laravel on Ubuntu 24.04)

Generated Config Output
server {
    listen 80;
    listen [::]:80;
    server_name app.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name app.example.com;

    ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;

    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript application/xml;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
Production Nginx reverse proxy -> 127.0.0.1:3000 for app.example.com.
Flag-by-Flag Breakdown
server_nameBinds this virtual host to app.example.com
return 301 https://...Redirects all plain HTTP requests permanently to TLS/HTTPS
proxy_pass http://127.0.0.1:3000Forwards HTTP + WebSocket requests to local application server
X-Content-Type-Options / X-Frame-OptionsProtects users against MIME sniffing and clickjacking

Laravel is the world's most popular open-source PHP web framework, celebrated for its elegant syntax, developer ergonomics, and comprehensive ecosystem. Designed to eliminate the repetitive boilerplate of web development, Laravel includes first-class routing, database abstraction via Eloquent ORM, automated schema migrations, queue workers, job dispatchers, integrated authentication scaffolds, and full-stack testing utilities out of the box.

Pairing Ubuntu 24.04 LTS with Laravel gives software engineers a high-performance production environment powered by the latest PHP 8.3 engine, fast opcache bytecode acceleration, and robust process managers. Learning how to install laravel on ubuntu 24.04 provides developers with an expressive, modern PHP application stack featuring elegant database migrations, Eloquent ORM, and integrated routing.

In this step-by-step tutorial, we demonstrate how to install Laravel on Ubuntu 24.04 LTS (Noble Numbat). We cover installing PHP 8.3 and all required extensions, deploying Composer globally, setting up a MariaDB database and dedicated user, scaffolding a fresh Laravel project in /var/www/laravel, configuring environment parameters in .env, configuring an Nginx web server block with PHP-FPM, and running Artisan database migrations.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A cloud instance, VPS, or local workstation running Ubuntu 24.04 LTS.
  • A non-root user account configured with administrative sudo privileges.
  • A domain name or local development IP address pointed to your server.
  • At least 2 GB of RAM (4 GB recommended for compiling frontend assets with Vite and Node.js).

Step 1: Updating System Repositories and Installing PHP 8.3

Laravel 11 requires PHP 8.2 or PHP 8.3 along with a suite of essential extensions for cryptographic hashing, string manipulation, XML parsing, and database communication. Ubuntu 24.04 features PHP 8.3 in its main repository.

First, refresh your APT repository index and install PHP 8.3, php8.3-fpm, and the required module extensions.

Advertisement

Verify that the PHP CLI runtime reports version 8.3 or higher.

# Refresh repository lists and upgrade packages
sudo apt update && sudo apt upgrade -y

# Install PHP 8.3, PHP-FPM, and essential Laravel extensions
sudo apt install -y php8.3 php8.3-fpm php8.3-mysql php8.3-mbstring php8.3-xml php8.3-bcmath php8.3-curl php8.3-zip php8.3-intl php8.3-sqlite3 unzip git curl

# Verify PHP version
php -v

Step 2: Installing Composer Globally on Ubuntu

Composer is the official dependency manager for PHP, responsible for managing Laravel's core packages, third-party libraries, and autoloading classes.

Download the official Composer installer script directly from getcomposer.org.

Execute the installer and move the generated composer.phar binary into /usr/local/bin/composer to enable system-wide execution.

Advertisement

Verify the installed Composer version.

# Download Composer installer script
cd /tmp
curl -sS https://getcomposer.org/installer -o composer-setup.php

# Install Composer to /usr/local/bin
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

# Verify Composer version
composer --version

# Clean up installer script
rm -f composer-setup.php

Step 3: Installing and Configuring MariaDB Database Server

Laravel supports multiple relational databases, including MySQL, MariaDB, PostgreSQL, and SQLite. MariaDB is the recommended open-source database engine for production deployments on Ubuntu.

Install mariadb-server using APT.

Enable and verify that the database service is running.

Execute the automated security script to secure root access and remove default test databases.

# Install MariaDB database server
sudo apt install -y mariadb-server mariadb-client

# Enable and start MariaDB daemon
sudo systemctl enable --now mariadb

# Verify database status
sudo systemctl status mariadb --no-pager

Step 4: Creating Dedicated Database and User for Laravel

Create a dedicated, isolated database and user account for your Laravel project inside MariaDB.

Log into the MariaDB root command prompt.

Create a database named laravel_db with utf8mb4 encoding, create the user laravel_user, grant full privileges on the database, and flush privileges.

Replace StrongLaravelPass123! with a strong, randomized password.

-- Access MariaDB root prompt
sudo mariadb

-- Create database with utf8mb4 encoding
CREATE DATABASE laravel_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create dedicated user account
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'StrongLaravelPass123!';

-- Grant privileges on Laravel database
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';

-- Flush privilege tables and exit
FLUSH PRIVILEGES;
EXIT;

Step 5: Creating a Fresh Laravel Application via Composer

Create your project root directory inside /var/www/laravel.

Use the composer create-project command to scaffold a fresh Laravel application.

Assign directory ownership to the www-data web server user so that PHP-FPM can write to storage and cache paths.

Set strict write permissions on the storage and bootstrap/cache directories.

# Navigate to web root and create Laravel project
cd /var/www
sudo composer create-project --prefer-dist laravel/laravel laravel

# Set ownership to web server user
sudo chown -R www-data:www-data /var/www/laravel

# Set permissions on storage and bootstrap cache directories
sudo chmod -R 775 /var/www/laravel/storage /var/www/laravel/bootstrap/cache

Step 6: Configuring Environment Variables and Generating Application Key

Laravel stores its environment-specific configuration parameters inside the .env file in your project root.

Open /var/www/laravel/.env and configure your application URL (APP_URL) and database connection settings (DB_DATABASE, DB_USERNAME, and DB_PASSWORD).

Ensure that the unique application encryption key (APP_KEY) is generated; if missing, generate it using the php artisan key:generate command.

# Change into Laravel project directory
cd /var/www/laravel

# Configure database credentials in .env
sudo sed -i 's/DB_DATABASE=.*/DB_DATABASE=laravel_db/' .env
sudo sed -i 's/DB_USERNAME=.*/DB_USERNAME=laravel_user/' .env
sudo sed -i 's/DB_PASSWORD=.*/DB_PASSWORD=StrongLaravelPass123!/' .env
sudo sed -i 's|APP_URL=.*|APP_URL=http://example.com|' .env

# Ensure application key is generated
sudo -u www-data php artisan key:generate

Step 7: Configuring Nginx Server Block with PHP-FPM

In production, Nginx serves as an ultra-fast reverse proxy and web server for Laravel applications.

Install Nginx using APT.

Create a new server block at /etc/nginx/sites-available/laravel.conf.

Crucially, set the root directive strictly to /var/www/laravel/public, route all dynamic requests to index.php via try_files, and pass PHP execution to the php8.3-fpm.sock Unix socket.

# Install Nginx
sudo apt install -y nginx

# Create Nginx virtual host configuration
sudo bash -c 'cat <<EOF > /etc/nginx/sites-available/laravel.conf
server {
    listen 80;
    server_name example.com;
    root /var/www/laravel/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;
    charset utf-8;

    location / {
        try_files \$uri \$uri/ /index.php?\$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_hide_header X-Powered-By;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
EOF'

# Enable site and reload Nginx
sudo ln -sf /etc/nginx/sites-available/laravel.conf /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl restart nginx

Step 8: Executing Database Migrations and Testing Web Access

Run Laravel's built-in database migrations to verify database connectivity and create the default user and cache tables.

Execute the php artisan migrate command as the www-data user.

Open your web browser and navigate to http://example.com.

You will be greeted by the iconic Laravel landing page, confirming your application is active and ready for development.

# Run database migrations
cd /var/www/laravel
sudo -u www-data php artisan migrate

# Clear and cache application configuration
sudo -u www-data php artisan config:cache
sudo -u www-data php artisan route:cache
sudo -u www-data php artisan view:cache

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Browser displays '500 Server Error' or 'The stream or file storage/logs/laravel.log could not be opened'

Resolution: This indicates incorrect filesystem permissions on the storage directory. Run: sudo chown -R www-data:www-data /var/www/laravel/storage /var/www/laravel/bootstrap/cache followed by sudo chmod -R 775 /var/www/laravel/storage /var/www/laravel/bootstrap/cache.

Database connection refused: SQLSTATE[HY000] [2002] Connection refused

Resolution: Ensure MariaDB is running (sudo systemctl status mariadb). Verify that the database credentials in /var/www/laravel/.env match the user and password granted in Step 4. Run php artisan config:clear to reload settings.

All routes return 404 Not Found except the home page

Resolution: Ensure your Nginx configuration contains try_files \$uri \$uri/ /index.php?\$query_string; in the location / block, and reload Nginx.

Security Best Practices and Hardening

Always set the web server DocumentRoot strictly to /var/www/laravel/public; never point the server to the root /var/www/laravel directory, as this exposes .env credentials.

Ensure APP_DEBUG is set to false in your production .env file to prevent sensitive stack traces and database credentials from leaking to visitors.

Generate and protect a unique 32-character APP_KEY in your .env file to secure session cookies and encrypted database payloads.

Never commit your .env file to public Git repositories; always use .env.example as a template.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Yes. Laravel 11 includes Vite out of the box. Install Node.js and npm, then run npm install && npm run build inside your Laravel directory to compile JavaScript, React, Vue, or Tailwind CSS assets.
In production, configure a systemd service unit or use Supervisor to keep php /var/www/laravel/artisan queue:work --sleep=3 --tries=3 running continuously in the background.
Navigate to your project directory and execute composer update to update your PHP dependencies according to the version rules defined in composer.json.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Cloud & DevOps•

How to Close File Descriptors Above 9 in Dash Shell

Attempting to close a file descriptor above 9 in Dash using exec 10<&- results in a 10: not found error because Dash's POSIX lexer only recognizes single-digit file descriptors (0–9) in redirection operators. This guide explains the exact parser limitation, why FDs 10+ are reserved for internal shell state, and how to safely close inherited file descriptors using close_range, Python, or Perl wrappers.

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout