Deploy any Laravel application to a fresh Ubuntu/Debian VPS in minutes with a single command. This script automates the entire process, from server setup and software installation to application configuration and security hardening, letting you focus on your code.
Deploying a Laravel application involves repetitive and error-prone tasks: installing the correct software, configuring Nginx, setting up a database, managing permissions, and securing the server. This script automates all of it, providing a production-ready environment out of the box.
- 🚀 One-Command Deployment: Run a single command and let the script handle everything else.
- 🔒 Secure by Default: Implements best practices for security, including SSL, secure permissions, and Nginx rate limiting.
- ⚡ Optimized for Performance: Automatically enables caching for routes, config, and views for a faster application.
- 🤖 Smart & Flexible: Auto-detects the default branch (
main,master,pupuk) or lets you specify one. - 🔧 Zero Manual Configuration: No need to edit Nginx configs or create database users manually. The script handles it all.
- PHP: Installs the latest version and necessary extensions (
pgsql,zip,gd,curl, etc.). - PostgreSQL: Sets up the database server.
- Nginx: Installs and configures the web server.
- Composer: Installs the latest version for dependency management.
- Certbot: Installs Certbot and the Nginx plugin for easy SSL setup.
- Clone Repository: Clones your Laravel project into
/var/www/<repo_name>. - Database Creation: Creates a PostgreSQL database (
laravel_pos) and a user (laravel_pos_app) with a securely generated password. - .env Configuration: Copies
.env.exampleand automatically configuresAPP_URL, database credentials, and sets the environment toproduction. - Dependency Installation: Runs
composer install --optimize-autoloader. - Laravel Setup:
- Generates an application key (
php artisan key:generate). - Runs database migrations and seeders (
php artisan migrate:fresh --seed). - Creates the storage link (
php artisan storage:link).
- Generates an application key (
- SSL Certificate: Obtains and installs a free SSL certificate from Let's Encrypt for your domain and
wwwsubdomain. - Secure Permissions: Sets correct ownership (
www-data:www-data) and permissions for project files, while keeping storage directories writable. - Nginx Security:
- Adds security headers (
X-Frame-Options,X-Content-Type-Options). - Denies access to hidden files (like
.env) and thebootstrap/cachedirectory. - Implements API rate limiting (100 requests/second).
- Adds security headers (
- Caching: Automatically runs
php artisan optimize,config:cache,route:cache, andview:cache. - Optimized Autoloader: Installs Composer dependencies with
--optimize-autoloaderfor faster class loading. - Production Mode: Sets
APP_ENV=productionandAPP_DEBUG=false.
Prerequisites:
- A fresh Ubuntu/Debian VPS.
- A domain name pointed to your VPS IP address.
- Root or
sudoaccess. - A valid Laravel repository URL.
1. Download the script:
wget https://raw.githubusercontent.com/IlhamGhaza/deploy-laravel/master/deploy-laravel.sh2. Make it executable:
chmod +x deploy-laravel.sh3. Run the deployment:
sudo ./deploy-laravel.sh <repo_url> [branch] <domain> <email>Deploying with a specific branch:
sudo ./deploy-laravel.sh https://github.com/laravel/laravel.git main example.com admin@example.comDeploying without a branch (auto-detects main/master/pupuk):
sudo ./deploy-laravel.sh https://github.com/laravel/laravel.git example.com admin@example.comYour application will be deployed to /var/www/<repo_name>.
Common Commands:
# Check service status
sudo systemctl status nginx php-fpm postgresql
# View Nginx logs
sudo tail -f /var/log/nginx/error.log
# View Laravel logs
sudo tail -f /var/www/<repo_name>/storage/logs/laravel.logFor more commands and troubleshooting, see the Quick Setup Guide.
If you encounter issues, please consult the detailed troubleshooting guides:
Contributions are welcome! If you have suggestions or improvements, please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.