Set up a production-ready LAMP (or LEMP) server for a Laravel app on Ubuntu — in a single command.
One curl | bash line installs and wires up everything a fresh Ubuntu server needs to run a Laravel project: web server, PHP, MySQL, Composer, your code, and an optional free SSL certificate. The script is interactive — it asks questions along the way, so you don't need to edit any files.
📖 Full walkthrough: Setting Up Your Web Server in Minutes: A Beginner's Guide
- What it installs
- Prerequisites
- Quick start
- What the script asks you
- Step-by-step: what happens
- After it finishes
- LAMP vs LEMP
- Troubleshooting
- FAQ
- Safety notes
- Contributing
| Component | Details |
|---|---|
| Web server | Apache or Nginx (you choose) |
| PHP | Pick one: 7.4, 8.0, 8.1, 8.2, 8.3, or 8.4 — plus common Laravel extensions (mysql, mbstring, xml, curl, gd, zip, intl, bcmath, soap, fpm, imagick, ldap, opcache) |
| Database | MySQL Server (creates a user + database for you) |
| PHP tooling | Composer (installed globally) |
| Version control | Git |
| Node.js (optional) | 16.x, 18.x, or 20.x |
| Yarn (optional) | Installed only if you chose Node.js |
| PM2 (optional) | Process manager, installed only if you chose Node.js |
| SSL (optional) | Free HTTPS certificate via Let's Encrypt / Certbot |
It also clones your Laravel repo, runs composer install, creates .env, generates the app key, fills in your database credentials, and writes a web-server virtual host pointing at your app's public/ folder.
Before you run this, make sure you have:
- ✅ A server running Ubuntu 22.04 LTS (tested target — other versions may work but aren't verified)
- ✅ A user with
sudoaccess - ✅ The HTTPS URL of your Laravel GitHub repository (e.g.
https://github.com/you/your-app.git) - ✅ An internet connection on the server
- 🔲 (Optional) A domain name pointed at your server
- 🔲 (Optional, for SSL) A DNS
Arecord for that domain pointing to your server's public IP — this must be set before requesting an SSL certificate - ☕ About 5 minutes and a cup of coffee
New to servers? "A server running Ubuntu" usually means a cheap VPS from providers like DigitalOcean, Vultr, Hetzner, Linode, or AWS Lightsail. After you create one, you connect to it with
ssh root@your-server-ip(or your provided username), then run the command below.
SSH into your fresh Ubuntu server, then run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/sohag-pro/SingleCommand/main/lamp.sh)"That's it. The script takes over and asks you questions as it goes. Answer the prompts and wait.
Prefer to read the script before running it? (Recommended — never blindly pipe a remote script into bash.)
# Download it, read it, then run it
curl -fsSL https://raw.githubusercontent.com/sohag-pro/SingleCommand/main/lamp.sh -o lamp.sh
less lamp.sh # review what it does
bash lamp.sh # run itThe script is interactive. Here's every question it will ask, in order, so you can prepare your answers:
| Prompt | Example answer | Notes |
|---|---|---|
| Web server (1 Apache / 2 Nginx) | 1 |
Defaults to Apache if you press Enter |
| PHP version (1–6) | 4 |
e.g. 4 = PHP 8.2 |
| MySQL username | admin |
Defaults to admin |
| MySQL password | •••••• |
Hidden as you type. Remember it |
| Database name | mydatabase |
Defaults to mydatabase |
| Install Node.js? | y / N |
Optional |
| Node.js version (1–3) | 2 |
Only if you said yes |
| Install Yarn? | y / N |
Only offered if Node.js installed |
| Install PM2? | y / N |
Only offered if Node.js installed |
| GitHub repository URL | https://github.com/you/app.git |
Your Laravel project |
| Domain name | example.com |
Used for the web-server config |
| Install SSL certificate? | y / N |
Optional |
| Have you configured DNS? | y / N |
Asked before SSL is issued |
💡 Tip: Have your MySQL password and GitHub repo URL ready before you start.
- System update —
sudo apt update. - Web server — installs Apache or Nginx based on your choice.
- PHP — adds the
ondrej/phpPPA, installs your chosen PHP version and all common Laravel extensions. - MySQL — installs MySQL Server, then creates the user, grants privileges, and creates the database you named.
- Git + Composer — installs both; Composer is verified by checksum and placed in
/usr/local/bin. - Node.js / Yarn / PM2 — optional, only if you opt in.
- Clone your app — clones your repo into
/var/www/html/<repo-name>and setswww-dataownership +755permissions. - Laravel setup — runs
composer install, copies.env.example→.env, runsphp artisan key:generate, and writes your DB name / user / password into.env. - Virtual host — generates an Apache
.confor Nginx server block pointing at your app'spublic/directory, enables the site, and restarts the web server. - SSL (optional) — installs Certbot and requests a Let's Encrypt certificate for your domain.
- Summary — prints the PHP version, MySQL user, and database name when done.
-
Visit
http://your-domain.com(orhttps://if you set up SSL) — your Laravel app should load. -
Your project lives at
/var/www/html/<your-repo-name>. -
Your
.envalready has the database credentials filled in. -
Run migrations if your app needs them:
cd /var/www/html/<your-repo-name> sudo -u www-data php artisan migrate
-
If you didn't add a domain yet, you can reach the server by its IP for testing.
- LAMP = Linux + Apache + MySQL + PHP. Easiest for beginners; uses
.htaccessfiles. Pick1(Apache). - LEMP = Linux + Nginx (the "E" is for its pronunciation, "engine-x") + MySQL + PHP. Faster under high traffic, lighter on memory. Pick
2(Nginx).
Both work great with Laravel. If unsure, choose Apache.
| Problem | Fix |
|---|---|
Failed to clone repository |
Check the repo URL. For private repos, the server needs access (deploy key or a token in the URL). |
Site shows a 403 / blank page |
Check permissions: sudo chown -R www-data:www-data /var/www/html/<repo>. |
502 Bad Gateway (Nginx) |
The PHP-FPM socket version must match your PHP version. Confirm php<version>-fpm is running: sudo systemctl status php8.2-fpm. |
| SSL fails | Your domain's DNS A record must point to this server's IP before running Certbot. DNS changes can take time to propagate. |
| MySQL user already exists | The script doesn't stop on this — pick a fresh username, or drop the old user in MySQL first. |
| Need to re-run web-server config | Edit the file in /etc/apache2/sites-available/ or /etc/nginx/sites-available/, then restart the server. |
Is it safe to run more than once? It's designed for a fresh server. Re-running on a configured server may error on steps like "create MySQL user" (because it already exists). Best on a clean Ubuntu install.
Does it support private GitHub repos?
The clone step uses plain git clone. For private repos, set up SSH deploy keys or use a personal-access-token URL before running, otherwise the clone will fail.
Can I use it for non-Laravel PHP apps?
The PHP/MySQL/web-server parts are generic, but the later steps (.env, php artisan key:generate, public/ document root) assume Laravel.
Which PHP version should I choose? Match what your Laravel app requires. If you're starting fresh, PHP 8.2 or 8.3 is a safe modern choice.
- This script runs many commands with
sudoand pipes a remote file intobash. That's convenient but means you're trusting this repository. Read the script first (see Quick start) before running it on anything important. - It grants the MySQL user
ALL PRIVILEGES ... WITH GRANT OPTION— fine for a single-app server, but broader than a locked-down production setup would want. - Intended for new/disposable servers. Don't run it on a machine that already hosts other sites or databases without reviewing each step.
Issues and pull requests are welcome. The entire tool is a single script: lamp.sh. Keep it POSIX-friendly bash, test on Ubuntu 22.04, and prefer clear prompts over silent assumptions.
Tested on Ubuntu 22.04 LTS.