Automated LAMP (Linux, Apache, MySQL, PHP) stack installer for Ubuntu 24.04+ with full support for both interactive and non-interactive (--auto) deployment modes. Built for secure, repeatable production deployments.
- Installs Apache2, MySQL 8.0, PHP 8.x, and phpMyAdmin
- Automatic SSL provisioning via Let's Encrypt (Certbot)
- Security hardening with sane defaults (MySQL bind, file permissions, headers)
- Configures UFW firewall (HTTP/HTTPS/SSH) and optional SSH lock-down
- Persistent installation logging under
/var/log/lamp-installer/ - Modular architecture — decomposed into
modules/for maintainability - Supports both interactive and non-interactive (
--auto) deployment
The installer is decomposed into modules in modules/:
| Module | Purpose |
|---|---|
helpers.sh |
Common utilities: logging, validation, password generation |
config.sh |
CLI parsing, environment variables, interactive fallbacks |
install_packages.sh |
Installs base packages and prerequisites |
apache.sh |
Apache2 installation and VirtualHost configuration |
mysql.sh |
MySQL 8.0 installation and hardening |
php.sh |
PHP 8.x installation and detection of PHP-FPM/mod_php |
phpmyadmin.sh |
phpMyAdmin installation and Apache integration |
certbot.sh |
Certbot installation and automatic certificate issuance |
firewall.sh |
UFW setup and rule management |
cleanup.sh |
Final tasks: remove temp creds, write credential file |
install.sh |
Orchestrator: sources modules in correct order and controls flow |
uninstall.sh |
(Optional) Reversal script to remove installed components |
git clone https://github.com/imosudi/lamp-stack-installer.git
cd lamp-stack-installersudo bash install.shProvide required parameters when using --auto:
sudo bash install.sh --auto --domain example.com --email admin@example.com --ip 203.0.113.10 --mysql-root-pass 'StrongRootPwd!' --phpmyadmin-pass 'StrongPhpPwd!'Notes for --auto mode
--domainand--emailare required for automated SSL issuance.- Ensure DNS A records for both
example.comandphpmyadmin.example.compoint to the server IP before requesting certificates.
You can also create an .env file in the repo root and the installer will load it (example):
AUTO=true
DOMAIN=example.com
CERTBOT_EMAIL=admin@example.com
MANUAL_IP=203.0.113.10
MYSQL_ROOT_PASSWORD=StrongRootPwd!
PHPMYADMIN_PASSWORD=StrongPhpPwd!
ALLOW_SSH=true
LOGFILE=/var/log/lamp-installer/install.log- Validates inputs (IP, domain) and checks DNS resolution (best effort)
- Updates packages and installs prerequisites (curl, wget, openssl, snapd)
- Installs and configures Apache (virtual hosts, security headers)
- Installs PHP and required extensions (detects PHP-FPM vs mod_php)
- Installs MySQL 8.0, sets secure root password, and applies hardening
- Installs phpMyAdmin and configures a dedicated Apache vhost
- Configures UFW firewall (allows 80/443 and OpenSSH by default)
- Installs Certbot via
snapand requests certificates for both main domain andphpmyadmin.subdomain (if email provided) - Writes credentials to
/root/lamp_credentials.txt(chmod 600) and cleans temporary files - Logs everything to
LOGFILE(default/var/log/lamp-installer/install.log)
- MySQL
bind-addressset to127.0.0.1andlocal-infile=0 - Anonymous MySQL users removed and test DB dropped
- Strong TLS via Let’s Encrypt (automated)
- Apache security headers added (
X-Frame-Options,X-Content-Type-Options,Referrer-Policy) - UFW default
deny incomingandallow outgoingpolicy - Credentials file permissioned to
600and stored in/root
All persistent logs are stored under:
/var/log/lamp-installer/
Key files:
/var/log/lamp-installer/install.log— installation console output and errors/root/lamp_credentials.txt— generated credentials (chmod 600)- Apache + MySQL logs remain in their standard locations (
/var/log/apache2/,/var/log/mysql/)
[2025-11-02 14:01:20] Installing Apache2...
[2025-11-02 14:02:01] Installing MySQL server and client...
[2025-11-02 14:03:05] Configuring UFW...
[2025-11-02 14:04:10] Obtaining SSL via Let's Encrypt...
[2025-11-02 14:05:33] ✅ LAMP stack installation completed successfully!
Credentials saved to: /root/lamp_credentials.txt
A provided uninstall.sh (optional) should be used with caution. A minimal reversal might remove packages and sites but won't destroy user data unless explicitly designed to do so.
sudo bash uninstall.shContributions welcome — please fork, create a feature branch, and open a pull request. Suggested improvements:
- Support for multiple domains and SAN certificates
- Automatic backup & restore hooks for MySQL
- SELinux/AppArmor policy guides for hardened hosts
This project is licensed under the BSD 3-Clause License — see the LICENSE file for details.
BSD 3-Clause License
Copyright (c) 2025, Mosudi Isiaka
All rights reserved.
Mosudi Isiaka
📧 mosudi.isiaka@gmail.com
🌐 https://mioemi.com
💻 https://github.com/imosudi