Laravel 12 is the latest major release of the popular PHP framework, featuring a streamlined directory structure, improved performance, and modern PHP 8.4 syntax support. This guide installs Laravel 12 on a LEMP stack (Linux, Nginx, MySQL, PHP 8.4) on Ubuntu 26.04 LTS.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS with Nginx, MySQL 9, and PHP 8.4 installed
- Composer installed globally
- A domain name or server IP
Step 1 – Install Required PHP Extensions
sudo apt install php8.4-fpm php8.4-mysql php8.4-mbstring php8.4-xml
php8.4-curl php8.4-zip php8.4-bcmath -y
Step 2 – Create a New Laravel 12 Application
cd /var/www
sudo composer create-project laravel/laravel myapp
sudo chown -R www-data:www-data /var/www/myapp
sudo chmod -R 755 /var/www/myapp/storage /var/www/myapp/bootstrap/cache
Step 3 – Create the Database
sudo mysql
CREATE DATABASE laraveldb;
CREATE USER 'laraveluser'@'localhost' IDENTIFIED BY 'LaravelPass2026!';
GRANT ALL PRIVILEGES ON laraveldb.* TO 'laraveluser'@'localhost';
FLUSH PRIVILEGES;
exit
Step 4 – Configure the .env File
sudo nano /var/www/myapp/.env
Update these settings:
APP_NAME=MyApp
APP_ENV=production
APP_KEY= # will generate next
APP_DEBUG=false
APP_URL=https://example.com
DB_CONNECTION=mysql
DB_DATABASE=laraveldb
DB_USERNAME=laraveluser
DB_PASSWORD=LaravelPass2026!
cd /var/www/myapp && sudo php artisan key:generate
Step 5 – Create the Nginx Server Block
sudo nano /etc/nginx/sites-available/myapp
Add:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/myapp/public;
index index.php index.html;
location / { try_files $uri $uri/ /index.php?$query_string; }
location ~ .php$ {
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht { deny all; }
}
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Step 6 – Run Migrations
cd /var/www/myapp
sudo php artisan migrate
Step 7 – Optimize for Production
sudo php artisan config:cache
sudo php artisan route:cache
sudo php artisan view:cache
Conclusion
Laravel 12 is now running on Ubuntu 26.04 LTS with Nginx and MySQL. Secure the site with a Let’s Encrypt certificate, configure queues with Redis, and use Laravel Horizon for job monitoring in production.