Deploying a Laravel application to a production server involves more than copying files. You need to install the correct PHP version, configure Nginx, secure the server, set up the database, and enable HTTPS.
This tutorial walks through the complete process of deploying Laravel 13 on Ubuntu 24.04 using Nginx, PHP 8.3-FPM, Composer, and Let’s Encrypt SSL. Whether you’re launching a new Laravel project or deploying an existing application, these steps will help you build a reliable production environment.
Prerequisites
- Ubuntu 24.04 server
- SSH access with sudo privileges
- A registered domain name (for HTTPS setup)
- Basic familiarity with Linux terminal commands
- Laravel 13 application or source code repository
Step 1: Verify Ubuntu 24.04 and Define the Deployment Host
Connect to your server using SSH:
ssh your-user@your_server_ip

Verify the operating system and CPU architecture:
cat /etc/os-release
uname -m

Check available CPU, memory, and disk space:
nproc
free -h
df -h /

Set variables that will be used throughout the deployment:
export APP_DIR=/var/www/laravel
export APP_HOST=laravel.example.com

If your DNS records are already configured, verify that the domain resolves correctly:
dig +short A "$APP_HOST" || true
Step 2: Install Nginx, PHP 8.3-FPM, Composer, and Required PHP Extensions
Laravel 13 requires PHP 8.3 or newer, so install the required packages.
Update package repositories:
sudo apt update

Install Nginx, Composer, PHP 8.3, and commonly used Laravel extensions:
sudo apt install -y \
nginx composer curl unzip git ca-certificates dnsutils snapd \
php8.3-fpm php8.3-cli php8.3-common \
php8.3-curl php8.3-mbstring php8.3-xml \
php8.3-bcmath php8.3-zip php8.3-sqlite3 php8.3-intl

If your application uses MySQL:
sudo apt install -y php8.3-mysql

Or PostgreSQL:
sudo apt install -y php8.3-pgsql

Enable and start Nginx and PHP-FPM:
sudo systemctl enable --now nginx
sudo systemctl enable --now php8.3-fpm

Verify installed versions:
nginx -v
php -v
composer --version

Check the installed PHP-FPM package version:
dpkg-query -W -f='${Package} ${Version}\n' php8.3-fpm

Confirm required Laravel extensions are loaded:
php -m | grep -Ei 'ctype|curl|dom|fileinfo|filter|hash|mbstring|openssl|pcre|pdo|session|tokenizer|xml'
Step 3: Configure UFW Firewall Safely
Before enabling the firewall, identify the SSH port currently in use.
Check firewall status:
sudo ufw status verbose

Determine the SSH port:
SSH_PORT="$(sudo sshd -T | awk '/^port / {print $2}')"
echo "$SSH_PORT"

Allow SSH and web traffic:
sudo ufw allow "${SSH_PORT}/tcp"
sudo ufw allow 'Nginx Full'
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw status numbered

Important: Keep your current SSH session open. Open a second SSH session and confirm you can connect successfully before enabling an inactive firewall.
Enable UFW if it is not already enabled:
sudo ufw enable
Verify the rules:
sudo ufw status numbered
Warning: Do not use ufw –force enable before confirming SSH access from a second terminal session.
Here:
- SSH remains reachable.
- HTTP and HTTPS traffic are allowed.
- A second SSH session connects successfully.
Step 4: Deploy the Laravel 13 Application
Create the application directory and configure ownership:
sudo mkdir -p /var/www/laravel
sudo chown -R "$USER":www-data /var/www/laravel
cd /var/www/laravel

Option 1: Create a New Laravel 13 Project
Generate a fresh Laravel application:
composer create-project laravel/laravel . "^13.0" --prefer-dist

Option 2: Deploy an Existing Laravel Application
For an existing project, upload or clone your application and install dependencies recorded in composer.lock:
composer install \
--no-dev \
--prefer-dist \
--no-interaction \
--optimize-autoloader

Note: Avoid running composer update during production deployments. Production servers should install the exact dependency versions tested and locked in composer.lock.
Verify the installation:
php artisan --version
ls -l artisan public/index.php composer.lock

Here,
- Laravel reports version 13.x.
- artisan and public/index.php exist.
- Existing projects contain a valid composer.lock.
Step 5: Configure the Production Environment
Move into the application directory:
cd /var/www/laravel
Create the environment file if it doesn’t exist:
test -f .env || cp .env.example .env
Generate an application key only if one is not already set:
grep -q '^APP_KEY=base64:' .env || php artisan key:generate

Configure production settings:
sed -i 's/^APP_ENV=.*/APP_ENV=production/' .env
sed -i 's/^APP_DEBUG=.*/APP_DEBUG=false/' .env
sed -i 's#^APP_URL=.*#APP_URL=https://laravel.example.com#' .env
Protect the environment file:
chmod 600 .env

If DNS and SSL are not ready yet, temporarily use:
APP_URL=http://your_server_ip
Check the relevant settings:
grep -E '^APP_ENV=|^APP_DEBUG=|^APP_URL=' .env

Verify file permissions:
stat -c '%a %n' .env

Warning: Do not replace an existing production APP_KEY. Changing it can invalidate encrypted data, cookies, and sessions.
Step 6: Configure the Database and Storage Permissions
For this tutorial, SQLite is used for simplicity.
Configure Laravel to use SQLite:
cd /var/www/laravel
sed -i 's/^DB_CONNECTION=.*/DB_CONNECTION=sqlite/' .env
touch database/database.sqlite

If you’re deploying a production application, configure the appropriate MySQL or PostgreSQL database connection instead.
Run database migrations:
php artisan migrate --force

Set recommended permissions for Laravel’s writable directories:
sudo chown -R "$USER":www-data /var/www/laravel
sudo chmod -R ug+rwX storage bootstrap/cache
sudo find storage bootstrap/cache -type d -exec chmod g+s {} \;

For SQLite, allow PHP-FPM access to the database file:
sudo chgrp www-data database database/database.sqlite
sudo chmod g+rwX database database/database.sqlite
Check migration status:
php artisan migrate:status

Warning: Never run:
chmod -R 777
on a Laravel application.
Step 7: Configure Nginx for Laravel
Laravel should be served only from the public directory. Exposing the project root may reveal sensitive files such as .env and source code.
Set the variables:
APP_HOST="your_server_ip"
APP_DIR="/var/www/laravel"
Create the Nginx site configuration:
sudo tee /etc/nginx/sites-available/laravel > /dev/null <<NGINX
server {
listen 80;
listen [::]:80;
server_name ${APP_HOST};
root ${APP_DIR}/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 ~ ^/index\.php(/|$) {
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 32k;
fastcgi_buffers 8 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_hide_header X-Powered-By;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
NGINX

Enable the site:
sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -sfn /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/laravel
Validate the configuration:
sudo nginx -t

Reload Nginx:
sudo systemctl reload nginx
Step 8: Verify the Application Over HTTP
Test the application using the server IP address:
curl -I http://your_server_ip

Laravel includes a built-in health endpoint:
curl -i http://your_server_ip/up

A healthy application returns HTTP 200. Boot failures typically return HTTP 500.
Check service status:
sudo systemctl is-active nginx
sudo systemctl is-active php8.3-fpm

Review logs if needed:
sudo tail -n 30 /var/log/nginx/error.log
sudo test -f /var/www/laravel/storage/logs/laravel.log && sudo tail -n 30 /var/www/laravel/storage/logs/laravel.log || true

Step 9: Point Your Domain and Enable HTTPS
Verify DNS resolution:
dig +short A laravel.example.com
![]()
Update the Laravel application URL:
cd /var/www/laravel
APP_HOST="laravel.example.com"
sed -i "s#^APP_URL=.*#APP_URL=https://${APP_HOST}#" .env
Clear cached configuration:
php artisan optimize:clear
Update Nginx:
sudo sed -i "s/server_name .*/server_name ${APP_HOST};/" /etc/nginx/sites-available/laravel

Validate and reload:
sudo nginx -t
sudo systemctl reload nginx

Install Certbot:
sudo snap install --classic certbot
sudo ln -sf /snap/bin/certbot /usr/local/bin/certbot

Request and install the SSL certificate:
sudo certbot --nginx -d "$APP_HOST" --redirect
Verify HTTPS:
curl -I https://laravel.example.com
Test automatic certificate renewal:
sudo certbot renew --dry-run
Step 10: Optimize Laravel for Production
Install production dependencies:
cd /var/www/laravel
composer install \
--no-dev \
--prefer-dist \
--no-interaction \
--optimize-autoloader

If the application uses Vite or another frontend build process, build frontend assets according to the project’s existing workflow before going live.
Clear stale caches:
php artisan optimize:clear
Generate production caches:
php artisan optimize

Verify the environment:
php artisan about --only=environment

Check that the health route exists:
php artisan route:list --path=up
Note: After configuration caching, application settings should be accessed through Laravel configuration files rather than directly using env() in application code.
Step 11: Configure Laravel Scheduled Tasks
If your application uses scheduled jobs, Laravel requires a cron entry that runs every minute.
View the schedule:
cd /var/www/laravel
php artisan schedule:list

Edit your crontab:
crontab -e
Add the following entry:
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1

Verify the cron job:
crontab -l | grep 'artisan schedule:run'
For deployments that use sub-minute schedules:
php artisan schedule:interrupt
Step 12: Configure Queue Workers with Supervisor
Skip this section if your application does not use Laravel queues.
Install Supervisor:
sudo apt install -y supervisor

Enable the service:
sudo systemctl enable --now supervisor
Determine the deployment user:
DEPLOY_USER="$(id -un)"
echo "$DEPLOY_USER"

Create a worker configuration:
sudo tee /etc/supervisor/conf.d/laravel-worker.conf > /dev/null <<EOF
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/laravel/artisan queue:work --sleep=3 --tries=3 --max-time=3600
directory=/var/www/laravel
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=${DEPLOY_USER}
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/laravel/storage/logs/worker.log
stopwaitsecs=3600
EOF

Start the worker:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl status

Begin with a single worker and increase concurrency only after monitoring application load and server resources.
Step 13: Reload Long-Running Laravel Services After Deployment
After deploying new code, reload long-running Laravel services:
cd /var/www/laravel
php artisan reload

For queue workers only:
php artisan queue:restart
For applications using sub-minute scheduling:
php artisan schedule:interrupt

Verify status:
sudo supervisorctl status 2>/dev/null || true
php artisan about --only=environment

Always have a tested backup and rollback plan before deploying database schema changes.
Step 14: Perform Final Production Verification
Set your final application URL:
APP_TEST_URL="https://laravel.example.com"
If HTTPS is not available yet:
APP_TEST_URL="http://your_server_ip"
Verify the application:
curl -I "$APP_TEST_URL"
curl -i "$APP_TEST_URL/up"

Check service health:
sudo systemctl is-active nginx
sudo systemctl is-active php8.3-fpm
sudo nginx -t

Review Laravel environment settings:
cd /var/www/laravel
grep -E '^APP_ENV=|^APP_DEBUG=|^APP_URL=' .env
php artisan about --only=environment

Verify permissions and document root:
namei -l /var/www/laravel/storage
namei -l /var/www/laravel/bootstrap/cache
grep -R 'root ' /etc/nginx/sites-enabled/laravel

If queues or schedules are configured:
sudo supervisorctl status 2>/dev/null || true
crontab -l | grep 'artisan schedule:run' || true

Successful deployment checklist
- Homepage loads correctly.
- /up returns a successful response.
- Nginx and PHP-FPM are active.
- APP_DEBUG=false remains enabled.
- Nginx serves only the public directory.
- Laravel storage paths are writable.
- Scheduler and queue workers are running if configured.
Cleanup and Rollback
If you need to temporarily disable the Laravel site without removing application data:
sudo rm -f /etc/nginx/sites-enabled/laravel
sudo nginx -t
sudo systemctl reload nginx

Stop Supervisor-managed queue workers:
sudo supervisorctl stop 'laravel-worker:*'
To re-enable the website:
sudo ln -sfn /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/laravel
sudo nginx -t
sudo systemctl reload nginx

Important: Do not delete your .env file, database data, uploaded files, SSL certificates, queue state, or backups until you have verified they are no longer needed.
Conclusion
You have successfully deployed Laravel 13 on Ubuntu 24.04 using Nginx, PHP 8.3-FPM, Composer, and Let’s Encrypt SSL. The deployment includes firewall protection, secure environment configuration, database setup, production optimization, health checks, scheduled task support, and queue worker management.
Following these practices helps ensure your Laravel application remains secure, maintainable, and ready for production workloads.




