A complete, production-ready LEMP (Linux, Nginx, MariaDB, PHP) stack installation and removal script specifically optimized for Laravel applications on Ubuntu servers.
- Overview
- About
- Features
- System Requirements
- Quick Installation
- Installation Options
- What Gets Installed
- Important Notes
- Post-Installation
- Complete Removal
- Troubleshooting
- Contributing
- License
This project provides automated installation and removal scripts for setting up a complete LEMP stack optimized for Laravel development and production environments. The scripts handle all the complex configuration, security settings, and optimizations needed for a robust Laravel hosting environment.
This S-LEMP stack installation script was created by Sulaiman Misri, a passionate full-stack developer and DevOps enthusiast. With years of experience in Laravel development and server administration, this project aims to simplify the process of setting up production-ready Laravel hosting environments.
- Name: Muhamad Sulaiman Misri
- Website: https://sulaimanmisri.com
- Expertise: Full-Stack Development, DevOps, Automation, Cloud Infrastructure, Software Architecture
- Current Role: Senior Full-Stack Developer at UEM Sunrise Sdn Bhd
This project was born from the idea of wanting:
- Fast Installation for Laravel Applications: Streamlined, automated setup that gets Laravel environments running quickly without manual configuration
- Optimized for Laravel: Pre-configured settings, extensions, and performance tuning specifically tailored for Laravel's requirements
The broader goals include:
- Ease of Use: Simple installation process for developers of all levels
- Production Ready: Enterprise-grade security and performance optimizations
- Flexibility: Support for different configurations and use cases
- Reliability: Comprehensive error handling and recovery mechanisms
- Open Source: Community-driven development and continuous improvement
- Interactive Configuration Wizard - Guided setup with validation
- Non-Interactive Mode - Perfect for automation and CI/CD
- Multiple PHP Versions - Support for PHP 8.3 LTS and PHP 8.4
- Queue Management - Redis or Database queue drivers with Supervisor
- Security Optimized - Firewall, secure passwords, and hardened configurations
- SSL Ready - Certbot integration for Let's Encrypt certificates
- Performance Tuned - OPcache, Redis caching, and Laravel optimizations
- Error Handling - Comprehensive error recovery and cleanup
- Helper Scripts - Laravel permission management and utilities
- Complete Uninstallation - Removes all LEMP components and configurations
- Safe Removal Process - Step-by-step removal with confirmations
- Data Protection - Warns about data loss and requires explicit confirmation
- Cleanup Everything - Removes packages, configs, logs, and temporary files
- Service Management - Properly stops and disables all services
- Operating System: Ubuntu 20.04 LTS, 22.04 LTS, or 24.04 LTS
- Architecture: x86_64 (amd64)
- Memory: Minimum 1GB RAM (2GB+ recommended)
- Storage: At least 10GB free space
- Network: Internet connection for package downloads
- Privileges: Root access (sudo)
If you encounter dpkg lock errors or package management issues, use the removal script to clean up:
# Run the removal script to clean up any package issues
sudo bash remove.sh
# Then run the installation
sudo bash install.sh# Download the installation script
wget https://raw.githubusercontent.com/msulaimanmisri/s-lemp/main/install.sh
# Make it executable
chmod +x install.sh
# Run the installation (interactive mode)
sudo ./install.sh# Download and run in one command (interactive mode)
wget -qO- https://raw.githubusercontent.com/msulaimanmisri/s-lemp/main/install.sh | sudo bash# Download the script
wget https://raw.githubusercontent.com/msulaimanmisri/s-lemp/main/install.sh
# Run in non-interactive mode with defaults
sudo ./install.sh --non-interactive
# Or with custom options
sudo ./install.sh --non-interactive --php-version 8.4 --queue-driver redis| Option | Description | Values | Default |
|---|---|---|---|
--non-interactive, -n |
Run without prompts using defaults | - | Interactive mode |
--php-version |
Choose PHP version | 8.3, 8.4 |
8.3 |
--queue-driver |
Select queue backend | database, redis |
database |
--help, -h |
Show help information | - | - |
When running in interactive mode, you'll be prompted to configure:
-
Project Settings
- Project name (alphanumeric, 3-50 characters)
- Domain name (valid domain format)
- SSL email address
-
Database Configuration
- Database name, username, and password
- MariaDB root password
- Automatic secure password generation option
-
Redis Configuration
- Redis authentication password
- Automatic secure password generation option
-
Advanced Settings
- PHP version selection (8.3 LTS or 8.4)
- Queue driver (Database or Redis)
- Number of queue worker processes (1-20)
- Nginx - High-performance web server with optimized configuration
- MariaDB - Database server with secure installation
- PHP - Version 8.3 or 8.4 with essential Laravel extensions
- Redis - In-memory data structure store for caching and queues
- Node.js - Latest LTS version for frontend asset compilation
- Composer - PHP dependency manager
- Supervisor - Process manager for Laravel queue workers
- Certbot - SSL certificate management
Essential extensions for Laravel development:
php-fpm,php-mysql,php-redis,php-xml,php-zipphp-curl,php-mbstring,php-gd,php-imagickphp-bcmath,php-soap,php-intl,php-readlinephp-common,php-json,php-opcache,php-cli
- UFW Firewall - Configured with appropriate rules
- OPcache - PHP bytecode caching for performance
- Security Headers - Nginx security configuration
- Process Isolation - Dedicated PHP-FPM pools per project
- Automatic Updates - Unattended security updates
- Log Management - Centralized logging configuration
fix-laravel-permissions- Laravel permission management utility- Laravel scheduler cron job setup
- Project deployment templates
- Backup Your Data - This script makes system-wide changes
- Fresh Server Recommended - Best used on clean Ubuntu installations
- Domain Configuration - Have your domain DNS ready if using SSL
- Root Access Required - Script must be run with sudo privileges
- All passwords are generated securely using
/dev/urandomor OpenSSL - MariaDB is installed with secure defaults (no anonymous users, no test database)
- Redis is configured with authentication
- Nginx includes security headers and proper SSL configuration
- UFW firewall is enabled with minimal required ports
The script installs Certbot but does not automatically generate SSL certificates. After installation:
- Ensure your domain points to your server's IP
- Test accessibility:
curl -I http://yourdomain.com - Generate SSL certificate:
sudo certbot --nginx -d yourdomain.com
-
Clone your project:
cd /var/www/your-project-name git clone https://github.com/your-username/your-laravel-app.git .
-
Install dependencies:
composer install --optimize-autoloader --no-dev npm install && npm run build -
Configure environment:
cp .env.example .env php artisan key:generate
-
Set up database:
php artisan migrate --force php artisan db:seed --force
-
Fix permissions:
fix-laravel-permissions /var/www/your-project-name
- HTTP:
http://your-domain.comorhttp://your-server-ip - HTTPS:
https://your-domain.com(after SSL setup)
# Check service status
sudo systemctl status nginx php8.3-fpm mariadb redis-server supervisor
# View logs
sudo tail -f /var/log/nginx/error.log
sudo journalctl -u php8.3-fpm -f
# Restart services
sudo systemctl restart nginx php8.3-fpm
# Check queue workers
sudo supervisorctl status
# Laravel permissions fix
fix-laravel-permissions /var/www/your-project# Download removal script
wget https://raw.githubusercontent.com/msulaimanmisri/s-lemp/main/remove.sh
# Make executable and run
chmod +x remove.sh
sudo ./remove.shThe removal script completely removes:
- All LEMP stack components (Nginx, PHP, MariaDB, Redis)
- All configuration files and directories
- All databases and data (PERMANENTLY DELETED)
- All project files in
/var/www/ - All SSL certificates
- All cron jobs and scheduled tasks
- All helper scripts and utilities
- All package repositories and caches
- ALL DATA WILL BE PERMANENTLY DELETED
- ALL DATABASES WILL BE LOST
- ALL PROJECT FILES WILL BE REMOVED
- This action cannot be undone
- Make sure to backup any important data before removal
dpkg was interrupted error:
# Use the removal script to clean up package issues
sudo bash remove.sh
# Or manually fix:
sudo killall apt apt-get dpkg
sudo rm -f /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/cache/apt/archives/lock
sudo dpkg --configure -a
sudo apt-get -f install -yAnother process is using apt:
# Run the removal script which handles this automatically:
sudo bash remove.shInstallation fails with package conflicts:
sudo apt update && sudo apt upgrade -y
sudo dpkg --configure -a
sudo apt -f installPHP-FPM service won't start:
sudo nginx -t
sudo php-fpm8.3 -t
sudo systemctl status php8.3-fpmDatabase connection issues:
sudo mysql -u root -p
sudo systemctl status mariadbSSL certificate generation fails:
# Check domain accessibility
curl -I http://yourdomain.com
# Check Nginx configuration
sudo nginx -t
# Manual certificate generation
sudo certbot --nginx -d yourdomain.com --email [email protected] --agree-tos- Nginx:
/var/log/nginx/ - PHP-FPM:
/var/log/php/ - MariaDB:
/var/log/mysql/ - Redis:
/var/log/redis/ - Laravel:
/var/www/your-project/storage/logs/
We welcome contributions from the community! This is an open-source project, and your input helps make it better for everyone.
-
Fork the Repository
git clone https://github.com/msulaimanmisri/s-lemp.git cd s-lemp -
Create a Feature Branch
git checkout -b feature/your-feature-name
-
Make Your Changes
- Follow the existing code style and conventions
- Test your changes thoroughly
- Update documentation as needed
-
Commit Your Changes
git add . git commit -m "feat: add your feature description"
-
Push and Create Pull Request
git push origin feature/your-feature-name
- Shell Script Standards: Follow ShellCheck recommendations
- Error Handling: Include proper error handling and rollback mechanisms
- Documentation: Comment complex logic and update README when needed
- Testing: Test on clean Ubuntu installations (20.04, 22.04, 24.04)
- Security: Review security implications of any changes
When reporting bugs, please include:
- Ubuntu version and architecture
- Installation mode used (interactive/non-interactive)
- Complete error messages and logs
- Steps to reproduce the issue
- Expected vs actual behavior
For new features, please:
- Describe the use case and problem it solves
- Provide implementation suggestions if possible
- Consider backward compatibility
- Discuss performance and security implications
- 🐛 Bug Fixes: Help identify and fix issues
- 🚀 New Features: Add support for new PHP versions, databases, etc.
- 📚 Documentation: Improve installation guides, troubleshooting
- 🧪 Testing: Test on different Ubuntu versions and configurations
- 🔒 Security: Security audits and improvements
- ⚡ Performance: Optimization and performance enhancements
- 🌐 Localization: Translate documentation to other languages
-
Local Testing Environment
# Use Docker or VirtualBox for testing docker run -it ubuntu:22.04 /bin/bash # Or use Vagrant vagrant init ubuntu/focal64 vagrant up
-
Code Quality Tools
# Install ShellCheck for shell script linting sudo apt install shellcheck # Check script quality shellcheck install.sh remove.sh
- Be Respectful: Treat all contributors with respect and kindness
- Be Constructive: Provide helpful feedback and suggestions
- Be Patient: Understand that this is a volunteer-driven project
- Be Collaborative: Work together to find the best solutions
All contributors will be recognized in our contributors list. Significant contributions may be highlighted in release notes and project documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
You are free to:
- Use this software for any purpose
- Modify and distribute the software
- Include it in proprietary projects
Under the conditions:
- Include the original license and copyright notice
- The software is provided "as is" without warranty
If you encounter any issues or need help:
- Check the Documentation: Review this README and troubleshooting section
- Search Issues: Look through existing GitHub issues
- Create an Issue: Report bugs or request features
- Community Discussion: Join discussions in GitHub Discussions
Made with ❤️ for the Laravel community
This project aims to simplify Laravel deployment and make robust hosting accessible to everyone.