General

How to Deploy Laravel on Ubuntu Server Automatically with setup_laravel

2 Mins read
General

How to Deploy Laravel on Ubuntu Server Automatically with setup_laravel

2 Mins read

If you’ve ever tried deploying a Laravel application to a fresh Linux server, you know the struggle. Hours spent installing PHP, configuring Nginx, setting up databases, dealing with permissions, and finally adding SSL — only to realize something still doesn’t work.

It’s boring, time-consuming, and error-prone.

That’s why I built setup_laravel, a one-paste bash script that automates the entire Laravel deployment process. Whether you’re a solo developer, an agency shipping multiple apps, or someone just learning server management, this script makes Laravel deployment fast, secure, and painless.

In this guide, you’ll learn:

  • Why setup_laravel saves hours of setup time

  • The key features (Nginx, PHP, SSL, MySQL/PostgreSQL, caching, etc.)

  • Step-by-step instructions for your first deployment

  • How to add extra domains later with the included domain manager script


Why Deployments Are Painful (and How setup_laravel Fixes It)

Typical Laravel deployment involves:

  • Installing Nginx, PHP, and configuring OPcache manually

  • Choosing and securing a database (MySQL or PostgreSQL)

  • Generating passwords and hardening the database

  • Cloning your Laravel repo, setting permissions, running composer install

  • Configuring Nginx for SSL with Let’s Encrypt

  • Debugging small issues that waste hours

With setup_laravel, all of this happens automatically.

👉 You run one command. The script installs everything, optimizes Laravel, configures Nginx, and even sets up HTTPS with Certbot. You get a working Laravel app live on your domain without lifting a finger.


Features of setup_laravel

Here’s what makes the script powerful:

  • Nginx + PHP (8.4 by default) with recommended OPcache settings

  • Database setup: MySQL or PostgreSQL, secured with strong random passwords

  • Optional caching with Memcached

  • Composer install with optimized autoloader and config caching

  • Nginx best practices: gzip, asset caching, secure defaults

  • Automatic SSL using Let’s Encrypt (no manual certificate setup)

  • Interactive mode for beginners, or non-interactive mode for automation

  • Domain confirmation step ensures DNS records are in place before SSL

  • Future-ready: Optional GitHub push support coming soon

Also Read:  Implement 100ms Video Call SDK in a Laravel App

Prerequisites

Before running the script, make sure you have:

  1. An Ubuntu (or similar) server with root (sudo) access

  2. An open SSH port to connect to the server

  3. A domain name pointing to your server’s IP address

Your First Laravel Deployment with setup_laravel

Step 1: Copy the Script

SSH into your server and download the script:

wget https://raw.githubusercontent.com/theafolayan/setup-laravel/main/setup_laravel_nginx_ssl.sh

Step 2: Make It Executable

chmod +x setup_laravel_nginx_ssl.sh

Step 3: Run the Script

Interactive mode (good for first-timers):

sudo ./setup_laravel_nginx_ssl.sh

Non-interactive example (ideal for automation pipelines):

sudo ./setup_laravel_nginx_ssl.sh -n \
  -a myapp -d example.com --dns-confirm yes \
  --repo-url https://github.com/laravel/laravel.git \
  --db-choice mysql --db-name appdb --db-user appuser --db-pass secret

💡 Tip: Use --dry-run to preview what the script will do without making changes.

Automatic SSL Setup

Once the script finishes, Let’s Encrypt will handle SSL certificates for your domain. Just make sure your DNS A record points correctly to your server before running. Nginx will then be fully configured for HTTPS.

Adding Extra Domains

Need to point multiple domains to your Laravel app? Use the included manage_domains.sh script.

wget https://raw.githubusercontent.com/theafolayan/setup-laravel/main/manage_domains.sh
chmod +x manage_domains.sh
sudo ./manage_domains.sh

The script automatically updates Nginx and sets up SSL for each new domain.

Conclusion

Deploying Laravel apps no longer has to be a frustrating chore. With setup_laravel, you get a production-ready environment in minutes — PHP, Nginx, database, caching, SSL, and Laravel optimizations all included.

👉 Stop wasting time on repetitive setup.
👉 Start shipping faster.

Check out the GitHub repo here and try it on your next project.

13 posts

About author
Oluwaseun Raphael Afolayan is an Established Software craftsman and Technical Writer with over 5 years of experience building and documenting tech solutions for startups. He enjoys running around sweaty PUBG-mobile lobbies in his spare time.
Articles
Related posts
Backend DevelopmentGeneral

Implement 100ms Video Call SDK in a Laravel App

3 Mins read
The 100ms SDK is a powerful tool for integrating real-time video and audio capabilities into your applications. With the new 100ms-laravel package,…
ArticlesBackend DevelopmentGeneral

MD5 vs SHA1 - A comparision

3 Mins read
When it comes to encryption, there are a few different algorithms that you can use. Two of the most popular ones are…
GeneralArticles

Understanding IPS Patching

5 Mins read
An Intrusion Prevention System (IPS) is a security mechanism that detects and prevents threats to networks. In this article, we’d take a…
Subscribe to more programming tutorials

Be the first to get notifications of byte-sized articles to make you a better programmer.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.