OrbitHost
Development

Host Laravel on Ubuntu 24.04 VPS (Nginx, PHP-FPM, MySQL)

Deploy a Laravel app on Ubuntu 24.04 with Nginx, PHP 8.3-FPM, Composer, MySQL/MariaDB, queues, and scheduler — practical production checklist.

By Noah Keller · Developer Advocate11 min read
Author
Noah Keller
Developer Advocate

Noah writes practical guides for Next.js deploys, AI self-hosting (Ollama, n8n), and PaaS panels like Coolify and Dokploy. His focus is getting apps from git clone to HTTPS with the fewest moving parts.

Stack overview

Nginx terminates TLS and passes PHP to php-fpm. MySQL/MariaDB stores application data. Redis is optional but recommended for cache, sessions, and queues.

An OrbitHost Core VPS in Frankfurt is enough for many SaaS MVPs. Scale vertically or split the database when growth demands it.

Install Nginx, PHP 8.3, and Composer

Install the PHP extensions Laravel commonly needs: ctype, curl, dom, fileinfo, mbstring, openssl, pdo_mysql, tokenizer, xml, bcmath, intl, redis.

sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx mysql-server redis-server \
  php8.3-fpm php8.3-{cli,mysql,xml,mbstring,curl,zip,bcmath,intl,gd,redis} \
  unzip git curl
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Database and deploy user

Create an application database and a least-privilege MySQL user. Deploy code as a dedicated user with write access only to `storage` and `bootstrap/cache`.

sudo mysql -e "CREATE DATABASE laravel;"
sudo mysql -e "CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';"
sudo mysql -e "GRANT ALL ON laravel.* TO 'laravel'@'localhost'; FLUSH PRIVILEGES;"

sudo useradd -m -s /bin/bash deploy
sudo mkdir -p /var/www/app
sudo chown deploy:deploy /var/www/app

Install the application

Clone your repo, `composer install --no-dev`, copy `.env`, generate the key, run migrations, and build frontend assets if you use Vite.

sudo -u deploy -i
cd /var/www/app
git clone https://github.com/your-org/your-laravel-app.git .
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
# edit .env: DB_*, APP_URL, QUEUE_CONNECTION=redis
php artisan migrate --force
npm ci && npm run build

Nginx site for Laravel’s public/

Document root must be `public/`. Deny access to `.env`. Enable HTTPS after DNS points at the VPS.

server {
    listen 80;
    server_name api.example.com;
    root /var/www/app/public;
    index index.php;
    client_max_body_size 32M;

    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 ~ /\. {
        deny all;
    }
}

Permissions, scheduler, and queues

www-data must write to storage and cache. Add the artisan schedule cron and a systemd/supervisor worker for `queue:work`.

sudo chown -R deploy:www-data /var/www/app
sudo find /var/www/app/storage /var/www/app/bootstrap/cache -type d -exec chmod 775 {} \;

# crontab -e as deploy:
* * * * * php /var/www/app/artisan schedule:run >> /dev/null 2>&1

sudo apt install -y supervisor
# create /etc/supervisor/conf.d/laravel-worker.conf with artisan queue:work
sudo supervisorctl reread && sudo supervisorctl update

TLS and post-deploy checklist

Run Certbot, set `APP_ENV=production` and `APP_DEBUG=false`, configure mail, and test a real queue job. Enable OPcache in php.ini for production.

For zero-SSH deploys later, containerize and use Coolify on `/vps-for-coolify` sized boxes — same Ubuntu habits, less manual Nginx editing.

  • php artisan config:cache && route:cache && view:cache
  • Rotate DB passwords out of chat logs
  • Back up MySQL + storage/app
  • Monitor php-fpm slowlog under load

FAQ

Shared hosting or VPS for Laravel?

Queues, websockets, and custom PHP extensions are happier on a VPS. Shared hosting works for simple sites; use VPS when you need supervisor, Redis, and SSH.

Which PHP version?

Laravel’s current versions target PHP 8.2+. On Ubuntu 24.04, PHP 8.3 from the default repos is a clean fit for new projects.

Octane?

Octane (Swoole/RoadRunner) is optional. Master classic PHP-FPM first; add Octane when request latency and concurrency need it.

Can Coolify deploy Laravel?

Yes — many teams containerize Laravel and let Coolify/Dokploy handle TLS and deploys. This guide is the classic bare-metal LEMP path.

Ready to Launch?

Create your server today.