Introduction
You've built your Laravel application locally, tested it, and everything is working.
Now comes the important part: putting your Laravel application online.
Deploying Laravel to a VPS can seem complicated when you're doing it for the first time. You need to configure the server, install PHP, configure Nginx, connect your database, set permissions, configure environment variables, and enable HTTPS.
The good news is that once you understand the process, deploying Laravel applications becomes much easier.
In this guide, we'll walk through a practical Laravel VPS deployment using:
1. Ubuntu 2. Nginx 3. PHP-FPM 4. MySQL 5. Composer 6. Git 7. Laravel 8. Let's Encrypt SSL
The same general approach can be adapted to many VPS providers.
- What You Need Before Starting
Before deploying your application, make sure you have the following:
- An Ubuntu VPS
- A domain name
- SSH access to your server
- A Laravel application stored in Git
- A database
- Your domain pointed to the VPS IP address
For a small Laravel application, a VPS with around 2 GB RAM can be a reasonable starting point, although the resources you actually need depend on traffic, database usage, queues, caching, and other workloads.
Your server should also have a supported PHP version for the Laravel release you're deploying.
- Connect to Your VPS
You normally connect to an Ubuntu VPS using SSH.
From your local terminal:
ssh your-username@your-server-ip
For example:
ssh root@123.123.123.123
If your VPS provider gives you a different username, use that username instead.
Once connected, you are working directly on your remote server.
- Update Ubuntu
Before installing anything, update the server packages.
sudo apt update sudo apt upgrade -y
Keeping your server updated is important for security and stability.
After the update completes, you can continue installing the software required by Laravel.
- Install Nginx
Nginx will act as the web server and handle incoming HTTP requests.
Install it with:
sudo apt install nginx -y
Check whether Nginx is running:
sudo systemctl status nginx
If everything is working, you should see that the service is active.
You can also visit your server IP in a browser.
If Nginx is configured correctly, you should see the default Nginx page.
- Install PHP and PHP-FPM
Laravel requires PHP and several PHP extensions.
Install PHP-FPM and commonly required extensions:
sudo apt install php-fpm php-mysql php-cli php-xml php-mbstring php-curl php-zip php-gd php-bcmath unzip git curl -y
Check your PHP version:
php -v
You should make sure the installed PHP version is compatible with the Laravel version used by your application.
PHP-FPM allows Nginx to communicate with PHP and execute your Laravel application.
- Install Composer
Composer is PHP's dependency manager and is required to install Laravel's PHP packages.
Check whether Composer is already installed:
composer --version
If it isn't installed, install Composer using the official Composer installation instructions.
After installation, verify it:
composer --version
You should see the installed Composer version.
- Install MySQL
If your Laravel application uses MySQL, install it on the server:
sudo apt install mysql-server -y
Check the service:
sudo systemctl status mysql
Then run the MySQL security configuration:
sudo mysqlsecureinstallation
Follow the prompts to configure your MySQL installation securely.
- Create the Laravel Database
Log into MySQL:
sudo mysql
Create a database:
CREATE DATABASE laravelapp;
Create a database user:
CREATE USER 'laraveluser'@'localhost' IDENTIFIED BY 'your-strong-password';
Grant permissions:
GRANT ALL PRIVILEGES ON laravelapp. TO 'laraveluser'@'localhost';
Then:
FLUSH PRIVILEGES; EXIT;
Use a strong, unique password for your production database.
- Deploy Your Laravel Application
A common approach is to store your application under /var/www.
Move into the directory:
cd /var/www
Clone your Git repository:
sudo git clone https://github.com/your-username/your-laravel-app.git
Move into your project:
cd your-laravel-app
Install production dependencies:
composer install --no-dev --optimize-autoloader
The --no-dev option prevents development-only packages from being installed in production.
- Configure the .env File
Laravel uses the .env file for environment-specific configuration.
If your project contains .env.example, create the production environment file:
cp .env.example .env
Edit it:
nano .env
Configure values such as:
*APPNAME="My Laravel App" APPENV=production APPDEBUG=false APPURL=https://example.com
DBCONNECTION=mysql DBHOST=127.0.0.1 DBPORT=3306 DBDATABASE=laravelapp DBUSERNAME=laraveluser DBPASSWORD=your-strong-password* Important
Never enable debugging on a production server:
APPDEBUG=false
Laravel's application key should also be configured securely.
If your application does not already have an encryption key, generate one:
php artisan key:generate
- Configure Laravel Storage
Laravel's public storage directory needs to be linked to the application's public directory.
Run:
php artisan storage:link
This allows files stored on the configured public disk to be accessed through the appropriate public URL.
- Configure File Permissions
Laravel needs write access to certain directories.
Typically, the web server needs access to:
storage/ bootstrap/cache/
For example:
sudo chown -R www-data:www-data /var/www/your-laravel-app
Then:
sudo chmod -R 775 /var/www/your-laravel-app/storage sudo chmod -R 775 /var/www/your-laravel-app/bootstrap/cache
Be careful with permissions.
Avoid giving your entire application unnecessarily broad permissions such as 777.
- Configure Nginx
This is one of the most important parts of a Laravel deployment.
Create an Nginx configuration file:
sudo nano /etc/nginx/sites-available/your-laravel-app
A basic configuration looks like:
*server { listen 80; listen [::]:80;
servername example.com www.example.com;
root /var/www/your-laravel-app/public;
index index.php index.html;
location / {
tryfiles $uri $uri/ /index.php?$querystring;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgipass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}* Important
The PHP-FPM socket depends on the PHP version installed on your server.
For example, it might be:
/run/php/php8.3-fpm.sock
Check your server before using a specific version.
You can inspect available PHP-FPM sockets with:
ls /run/php/
- Enable the Nginx Configuration
Create a symbolic link:
sudo ln -s /etc/nginx/sites-available/your-laravel-app
/etc/nginx/sites-enabled/your-laravel-app
Test the configuration:
sudo nginx -t
If the configuration is valid, reload Nginx:
sudo systemctl reload nginx
Your domain should now be able to reach the Laravel application.
- Configure the Firewall
Ubuntu commonly uses UFW for firewall management.
*Allow SSH:
sudo ufw allow OpenSSH
Allow HTTP and HTTPS:
sudo ufw allow 'Nginx Full'
Enable the firewall:
sudo ufw enable
Check the status:
sudo ufw status*
Make sure SSH access remains allowed before enabling the firewall, otherwise you could lock yourself out of the server.
- Run Laravel Migrations
Once the database configuration is correct, run your migrations:
php artisan migrate --force
The --force option allows migrations to run in a production environment.
If your application uses seeders and you intentionally want to seed production data:
php artisan db:seed --force
Be careful with production seeders because they can modify or replace database data.
- Optimize Laravel for Production
Once the application is working, clear and rebuild the appropriate caches.
A commonly used command is:
php artisan optimize
You can also inspect Laravel's available Artisan commands:
php artisan list
For production deployments, make sure your application is not running with:
APPDEBUG=true
- Configure SSL With Let's Encrypt
Running your Laravel website over HTTPS is essential for a production application.
Install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Then request an SSL certificate:
sudo certbot --nginx -d example.com -d www.example.com
Certbot can configure Nginx to use the certificate and redirect HTTP traffic to HTTPS.
After SSL is configured, test your website:
You should see the secure HTTPS connection in your browser.
- Test Your Laravel Application
Now test the application from your browser.
Check:
Homepage Login Registration Database operations File uploads Images Forms Email functionality API endpoints Admin panel Authentication Queued jobs
Also check the Laravel logs if something isn't working:
tail -f storage/logs/laravel.log
This is often one of the fastest ways to identify application errors.
- Useful Laravel Production Commands
Here are some commands you'll frequently use after deployment.
Clear application caches:
php artisan optimize:clear
Optimize the application:
php artisan optimize
Run migrations:
php artisan migrate --force
Create the storage link:
php artisan storage:link
Check routes:
php artisan route:list
Check Laravel version:
php artisan --version
Check server services:
sudo systemctl status nginx sudo systemctl status mysql sudo systemctl status php8.3-fpm
Remember to replace the PHP-FPM service name with the version actually installed on your server.
- Production Security Checklist
Before considering your Laravel application fully deployed, review these items.
Application APP_ENV=production APP_DEBUG=false Strong APP_KEY Strong database password No secrets committed to Git Production dependencies installed correctly Server Ubuntu packages updated Firewall enabled SSH secured Strong authentication Unnecessary services disabled Web server Nginx configured correctly Laravel public directory used as the document root HTTPS enabled HTTP redirected to HTTPS Database Strong database credentials Database backups configured Database not unnecessarily exposed to the public internet Laravel Storage permissions configured Cache optimized Logs monitored Queue workers configured if required Scheduled tasks configured if required
- What About Queue Workers?
If your Laravel application uses queues, simply deploying the application isn't enough.
You also need a queue worker.
A basic worker can be started with:
php artisan queue:work
For production, you should normally use a process manager such as Supervisor or another service-management approach so the worker can automatically restart when necessary.
This is especially important for applications that process:
Emails Notifications Reports Image processing API jobs Background tasks
- Configure Laravel Scheduler
If your application uses Laravel's scheduler, the server needs to execute Laravel's scheduler regularly.
A typical cron entry is:
-
-
-
-
- cd /var/www/your-laravel-app && php artisan schedule:run >> /dev/null 2>&1
-
-
-
This allows Laravel to determine whether any scheduled tasks need to run.
- Backups Are Not Optional
A production server should have backups.
You should consider backing up:
Database Uploaded files Application configuration Important server configuration
Don't assume that your VPS provider's infrastructure automatically gives you a complete application backup.
A good backup strategy should also include testing whether backups can actually be restored.
- Final Thoughts
Deploying Laravel on a VPS may seem complicated the first time, but the process becomes much easier once you understand what each component does.
The basic architecture looks like this:
Visitor ↓ Domain ↓ Nginx ↓ PHP-FPM ↓ Laravel ↓ MySQL
Nginx receives the web request, PHP-FPM executes PHP, Laravel handles the application logic, and MySQL stores your application's data.
Once this setup is working, you can add more advanced infrastructure such as:
Redis Laravel Horizon Queue workers Automated deployments Cloud storage Monitoring Database backups CDN Load balancing
The most important thing is to build a deployment process that is repeatable, secure, and easy to maintain.
If you're deploying Laravel for the first time, start with a simple VPS setup and gradually introduce additional infrastructure as your application's requirements grow.
Frequently Asked Questions Can I deploy Laravel on an Ubuntu VPS?
Yes. Ubuntu is a popular choice for Laravel deployments and works well with Nginx, PHP-FPM, MySQL, and other Laravel infrastructure.
Do I need Nginx for Laravel?
No. Laravel can run with other web servers, but Nginx is a common choice for production PHP applications.
Where should the Nginx root point?
For a Laravel application, Nginx should point to the application's public directory rather than the project root.
For example:
/var/www/your-laravel-app/public Should APP_DEBUG be enabled on production?
No. Keep:
APP_DEBUG=false
Production error pages should not expose sensitive application information.
Do I need SSL for Laravel?
For a public production website, HTTPS is strongly recommended. It protects traffic between visitors and your server and is essential for many authentication and API scenarios.
How do I update my Laravel application after deployment?
A typical Git-based deployment might involve pulling the latest code, installing dependencies, running migrations when required, rebuilding caches, and restarting workers when necessary.
Always review the changes before running production migrations.
Conclusion
Your Laravel application is now ready to move from your local development environment to a production VPS.
The process can be summarized as:
VPS → Ubuntu → Nginx → PHP-FPM → MySQL → Laravel → SSL → Production
Once you've successfully deployed one Laravel application, future deployments become much easier because you'll already understand the infrastructure behind the process.
In the next article, we'll look at one of the most commonly misunderstood Laravel files:
.env vs .env.example — What Every Laravel Developer Should Know.

