A collection of shell scripts that automate the deployment of production-ready LEMP Stack (Linux, Nginx, MySQL, PHP) applications on Ubuntu servers, tailored specifically for Laravel.
| Script | Purpose |
|---|---|
laravel_deploy.sh |
Fresh Laravel install — creates a new project from scratch |
laravel_deploy_github.sh |
GitHub deploy — clones your existing repo and sets everything up |
- Automated Updates: Updates system packages and adds PHP PPA.
- Custom PHP: Install any specific PHP version (e.g., 8.1, 8.2, 8.3).
- Database Management: Automatically creates a MySQL database and a dedicated user with a secure password.
- Composer: Installs the latest version of Composer globally.
- Laravel Installation: Creates a fresh Laravel project via Composer.
- Automatic .env Config: Links the new database credentials to the Laravel
.envfile. - Security: Sets correct folder permissions and installs SSL (Let's Encrypt) via Certbot.
-
Connect to your server via SSH:
ssh root@your_server_ip
-
Clone the repository:
git clone https://github.com/adnnco/LaraShip.git && cd LaraShip
-
Make the script executable:
chmod +x laravel_deploy.sh
-
Run the script:
sudo ./laravel_deploy.sh
The script will prompt you for:
- Project name
- Domain name
- SSL email
- PHP version
Deploys an existing Laravel repository from GitHub. Supports both interactive and fully non-interactive (CI/CD) modes.
- SSH Deploy Key: Automatically generates an ed25519 SSH key and guides you through adding it to GitHub — works with private and public repositories.
- GitHub Clone: Clones your repo directly from GitHub via SSH with a specified branch.
- Re-deploy Support: If the project directory already exists, runs
git pullinstead of re-cloning. - Branch Selection: Deploy any branch or tag (defaults to
main). - Composer: Installs dependencies with
--no-dev --optimize-autoloaderfor production. - NVM + Node.js: Installs NVM and the latest LTS version of Node.js automatically — no configuration needed.
- Frontend Build: Runs
npm installandnpm run buildautomatically if apackage.jsonis present (Vite / Mix). - Artisan Setup: Automatically runs
key:generate,migrate, and caches config/routes/views (aswww-datato avoid permission issues). - Storage Directories: Creates all required Laravel
storage/framework/*subdirectories before setting permissions, preventing cache path errors. - Automatic .env Config: Copies
.env.exampleand injects database credentials. - Database Management: Creates a MySQL database and dedicated user with a secure random password.
- Security: Sets correct folder permissions and installs SSL (Let's Encrypt) via Certbot.
- Confirmation Prompt: Shows a config summary before making any changes.
-
Connect to your server via SSH:
ssh root@your_server_ip
-
Clone the repository:
git clone https://github.com/adnnco/LaraShip.git && cd LaraShip
-
Make the script executable:
chmod +x laravel_deploy_github.sh
-
Run the script:
Option A — Pass all parameters (non-interactive / CI-CD friendly):
sudo ./laravel_deploy_github.sh \ --repo git@github.com:your-user/your-repo.git \ --branch main \ --project my-app \ --domain example.com \ --email admin@example.com \ --php 8.3
Option B — Interactive (prompts for anything not passed):
sudo ./laravel_deploy_github.sh --repo git@github.com:your-user/your-repo.git
-
Add the deploy key to GitHub when prompted:
The script will pause and print an SSH public key. Copy it, then go to:
GitHub repo → Settings → Deploy keys → Add deploy key
Paste the key, give it a title (e.g.,
VPS Deploy), and click Add key. PressENTERin the terminal to continue.
| Parameter | Required | Default | Description |
|---|---|---|---|
--repo |
Yes | — | GitHub repository SSH URL (e.g., git@github.com:user/repo.git) |
--branch |
No | main |
Branch or tag to deploy |
--project |
No | prompted | Project/folder name under /var/www/ |
--domain |
No | prompted | Domain name for Nginx and SSL |
--email |
No | prompted | Email address for Let's Encrypt |
--php |
No | prompted | PHP version to install (e.g., 8.3) |
- A fresh Ubuntu 20.04 or 22.04+ VPS (Droplet, AWS EC2, etc.).
- A Domain Name pointed to your server's IP address (A Record).
- Root or sudo access.
Once either script finishes, it will print your Database Credentials. Save them securely!
- Project Directory:
/var/www/your-project-name - Nginx Config:
/etc/nginx/sites-available/your-project-name - Log Files:
/var/www/your-project-name/storage/logs
- SSL: The Certbot step will fail if your domain's DNS has not propagated yet.
- PHP Extensions: The scripts install the most common Laravel extensions. If you need extras (e.g.,
php-gd,php-imagick), add them manually viaapt install. - SSH Key: The generated deploy key is saved at
/root/.ssh/github_deploy. If you re-run the script the same key is reused — no need to update GitHub. - Private Repos: SSH deploy keys work for both private and public repositories. Read-only access is sufficient for deployment.
Created with ❤️ for Laravel Developers.