Learn how to install Laravel on Ubuntu 24.04 VPS using Nginx, PHP-FPM, MySQL and Composer. This guide covers Laravel server setup, SSL configuration with Certbot.
Introduction
Laravel is one of the most widely used PHP frameworks for modern web applications. Running Laravel on a VPS provides full control over performance, security, and scalability. In this guide we configure a production-ready Laravel environment on Ubuntu 24.04, including Nginx, PHP-FPM, MySQL, Composer, and SSL with Certbot.
The process follows the same type of environment used by many professional hosting providers and cloud platforms.
Prerequisites
Before we begin, ensure we have the following:
- An Ubuntu 24.04 on dedicated server or KVM VPS.
- Basic Linux Command Line Knowledge.
- A domain name pointing A DNS record to server IP.
Learn how to install Laravel on Ubuntu 24.04 VPS using Nginx, PHP-FPM, MySQL and Composer.
Update the Server
Before installing anything, we ensure the system packages are up to date.
sudo apt update && sudo apt upgrade -y
Install some essential utilities used during deployment.
sudo apt install curl unzip git software-properties-common -y
Keeping the system updated ensures security patches and stable dependencies.
Install Nginx Web Server
Laravel performs best when paired with Nginx and PHP-FPM.
Install Nginx:
sudo apt install nginx -y
Start and enable the service:
sudo systemctl start nginx
sudo systemctl enable nginx
Verify the installation:
sudo systemctl status nginx
Open the server IP in a browser. The default Nginx page confirms the server is running correctly.
Install MySQL Database Server
Most Laravel applications require a database backend.
Install MySQL:
sudo apt install mysql-server -y
Secure the installation:
sudo mysql_secure_installation
Create a database and user for Laravel.
sudo mysql
CREATE DATABASE laravel_app;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON laravel_app.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
This isolates the application database and improves security.
Install PHP 8.3 and Required Extensions
Ubuntu 24.04 includes PHP 8.3, which is fully compatible with modern Laravel versions.
Install PHP with required extensions:
sudo apt install php8.3 php8.3-fpm php8.3-mysql php8.3-cli php8.3-curl php8.3-mbstring php8.3-xml php8.3-bcmath php8.3-zip php8.3-gd php8.3-intl -y
Verify installation:
php -v
Start and enable PHP-FPM:
sudo systemctl start php8.3-fpm
sudo systemctl enable php8.3-fpm
Install Composer (PHP Package Manager)
Laravel relies on Composer for dependency management.
Download and install Composer:
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
Verify installation:
composer --version
Install Laravel Application
Navigate to the web root directory.
cd /var/www
Create a new Laravel project:
composer create-project laravel/laravel laravel-app
Set proper ownership for the web server.
sudo chown -R www-data:www-data /var/www/laravel-app
sudo chmod -R 775 /var/www/laravel-app/storage
sudo chmod -R 775 /var/www/laravel-app/bootstrap/cache
These permissions allow Laravel to write cache and session files.
Configure Laravel Environment
Navigate to the project directory.
cd /var/www/laravel-app
Create the environment file:
cp .env.example .env
Generate the application key:
php artisan key:generate
Edit the environment configuration:
nano .env
Update the database section:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_app
DB_USERNAME=laravel_user
DB_PASSWORD=StrongPasswordHere
Run migrations if the application uses them:
php artisan migrate
Configure Nginx for Laravel
Create a new Nginx configuration.
sudo nano /etc/nginx/sites-available/laravel
Add the configuration:
server {
listen 80;
server_name example.com;
root /var/www/laravel-app/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
Test the configuration:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx
Opening the domain now should display the Laravel welcome page.
Configure Firewall
Ubuntu includes the UFW firewall.
Allow essential services:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
Enable the firewall:
sudo ufw enable
Check status:
sudo ufw status
Install SSL with Certbot
HTTPS is essential for security and SEO.
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Generate SSL certificate:
sudo certbot --nginx -d example.com -d www.example.com
Certbot automatically configures HTTPS and reloads Nginx.
Verify auto-renewal:
sudo certbot renew --dry-run
Certificates renew automatically every 60 days.
Navigate to your browser and access the URL:
https://exampel.com

Configure Queue Worker (Optional for Production)
Many Laravel applications rely on background jobs.
Install Supervisor:
sudo apt install supervisor -y
Create a worker configuration:
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
Example configuration:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel-app/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=3
user=www-data
redirect_stderr=true
stdout_logfile=/var/www/laravel-app/worker.log
Reload Supervisor:
sudo supervisorctl reread
sudo supervisorctl update
Optimize Laravel for Production
Laravel includes several performance optimizations.
Run the following commands inside the project directory:
php artisan config:cache
php artisan route:cache
php artisan view:cache
These commands reduce runtime overhead and improve response speed.
Basic Performance Tips
Production servers should include several tuning improvements.
Increase PHP memory limit
Edit PHP configuration:
sudo nano /etc/php/8.3/fpm/php.ini
Example:
memory_limit = 256M
Restart PHP:
sudo systemctl restart php8.3-fpm
Enable OPcache
Ubuntu usually enables it by default, but confirm:
opcache.enable=1
OPcache significantly improves PHP execution speed.
Maintenance and Updates
Regular maintenance keeps the server secure and stable.
Update system packages:
sudo apt update && sudo apt upgrade
Update Laravel dependencies:
composer update
Restart services after updates if necessary.
Summary
In this tutorial, we have seen how to install Laravel on Ubuntu 24.04 with Nginx, PHP-FPM and MySQL. A properly configured Laravel server includes several layers working together: Nginx, PHP-FPM, database services, Composer dependencies, and SSL security. Once these components are configured correctly, Laravel applications can scale reliably on VPS infrastructure.
This setup provides a strong foundation for running production Laravel applications while maintaining performance, security, and flexibility.

