A comprehensive bash script to automatically install and configure a complete LEMP (Linux, NGINX, MariaDB, PHP) stack with multiple PHP versions on Ubuntu. Perfect for development environments or production servers that need to support applications requiring different PHP versions.
- Multiple PHP Versions: Installs PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2 simultaneously
- Easy PHP Switching: Includes a convenient command-line tool to switch between PHP versions
- NGINX Web Server: Installs and configures latest NGINX from Ondřej Surý's repository
- MariaDB Database: Installs and secures MariaDB server with automated configuration
- phpMyAdmin: Sets up web-based database management interface
- Security Features:
- Fail2Ban for intrusion prevention (protects SSH, NGINX)
- UFW Firewall pre-configured with sensible defaults (ports 22, 80, 443)
- Secure MariaDB installation
- Monitoring & Testing: Creates testing pages for PHP info and server status
- A fresh installation of Ubuntu (18.04, 20.04, 22.04, or newer)
- Root privileges
- Internet connection
- Download the installer script:
wget https://raw.githubusercontent.com/script-php/lemp/main/installer.sh- Make it executable:
chmod +x installer.sh- Run the script as root:
sudo ./installer.sh- Follow the on-screen prompts to complete the installation.
| Component | Details |
|---|---|
| NGINX | Latest version from Ondřej Surý's repository |
| PHP | Versions 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2 with common extensions |
| MariaDB | Latest stable version |
| phpMyAdmin | Web interface for database management |
| Fail2Ban | Intrusion prevention system |
| UFW | Uncomplicated Firewall with pre-configured rules |
After installation, you can switch between PHP versions using the included phpswitch command:
# List available PHP versions
phpswitch
# Switch to PHP 8.1
phpswitch 8.1
# Check current PHP version
php -vThe script will automatically configure NGINX to use the selected PHP version.
For production servers, consider:
-
Setting a strong password for MariaDB root user during installation
-
Disabling root SSH access if not needed:
# Edit SSH config
nano /etc/ssh/sshd_config
# Change this line
PermitRootLogin no
# Restart SSH
systemctl restart sshdYou can easily customize the installer by editing the script:
- To install additional PHP versions, modify the
php_versionsarray - To add more PHP extensions, update the apt-get install commands
- To modify firewall rules, update the UFW section
If you encounter issues during installation:
- Check the log file at
/var/log/lemp_installer.log - Verify all services are running:
systemctl status nginx
systemctl status mariadb
systemctl status php*-fpm- Check NGINX configuration:
nginx -tContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Ondřej Surý for maintaining the PHP and NGINX repositories
- The LEMP stack community for documentation and best practices
This script is provided "as is", without warranty of any kind. Use at your own risk.