#!/bin/bash # Exit immediately if a command exits with a non-zero status set -e # Ensure the script is run as root if [ "$EUID" -ne 0 ]; then echo "Error: Please run this script as root (using sudo)." exit 1 fi echo "=========================================" echo " Starting Expanded LEMP Installation... " echo "=========================================" # 1. Update the package lists echo "--> Updating package repository cache..." apt-get update -y # 2. Install Nginx and Nginx-extras echo "--> Installing Nginx and nginx-extras..." apt-get install -y nginx nginx-extras # 3. Install MariaDB (Server and Client) echo "--> Installing MariaDB..." apt-get install -y mariadb-server mariadb-client # 4. Install PHP-FPM, PHP Common, and a comprehensive suite of PHP extensions echo "--> Installing PHP-FPM and PHP extensions..." apt-get install -y \ php-fpm \ php-common \ php-cli \ php-mysql \ php-xml \ php-mbstring \ php-intl \ php-curl \ php-gd \ php-zip \ php-bcmath # 5. Ensure services are enabled to start on boot and are currently running echo "--> Enabling and starting services..." systemctl enable nginx systemctl start nginx systemctl enable mariadb systemctl start mariadb # Ubuntu's apt automatically starts the specific PHP-FPM version (e.g., php8.1-fpm or php8.3-fpm). # We can dynamically find the installed PHP-FPM service name and ensure it's enabled. PHP_FPM_SERVICE=$(systemctl list-unit-files | grep -o 'php.*-fpm.service' | head -n 1) if [ -n "$PHP_FPM_SERVICE" ]; then systemctl enable "$PHP_FPM_SERVICE" systemctl start "$PHP_FPM_SERVICE" echo "--> $PHP_FPM_SERVICE is enabled and running." else echo "--> Warning: Could not automatically detect the PHP-FPM service name, but it should be running." fi echo "=========================================" echo " Installation completed successfully! :D " echo "=========================================" # Print basic status echo "" echo "--> Installed Versions:" echo "Nginx: $(nginx -v 2>&1)" echo "MariaDB: $(mysql -V)" echo "PHP: $(php -v | head -n 1)" # Show loaded PHP modules echo "" echo "--> Loaded PHP Modules (Snippet):" php -m | grep -E 'xml|PDO|intl|mbstring|curl|gd|zip' # Secure installation reminder echo "" echo "Note: Run 'sudo mysql_secure_installation' next to secure your MariaDB database!"