Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Automated Installation Script for NGINX, PHP 8.2-FPM, MariaDB, Composer, and Node.js 23
- # Created on: May 03, 2025
- # Exit on any error
- set -e
- # Colors for better readability
- GREEN='\033[0;32m'
- BLUE='\033[0;34m'
- RED='\033[0;31m'
- NC='\033[0m' # No Color
- # Function to print messages
- print_message() {
- echo -e "${BLUE}[INFO]${NC} $1"
- }
- # Function to print errors
- print_error() {
- echo -e "${RED}[ERROR]${NC} $1"
- }
- # Function to print success messages
- print_success() {
- echo -e "${GREEN}[SUCCESS]${NC} $1"
- }
- # Check if script is run as root
- if [ "$(id -u)" -ne 0 ]; then
- print_error "This script must be run as root or with sudo privileges"
- exit 1
- fi
- print_message "Starting installation of NGINX, PHP 8.2-FPM, MariaDB, Composer, and Node.js 23"
- print_message "Updating system packages..."
- # Update system
- apt update && apt upgrade -y || {
- print_error "Failed to update system packages"
- exit 1
- }
- print_success "System packages updated successfully"
- # Install NGINX
- print_message "Installing NGINX..."
- apt install -y nginx || {
- print_error "Failed to install NGINX"
- exit 1
- }
- # Enable and start NGINX
- systemctl enable nginx
- systemctl start nginx
- print_success "NGINX installed and started successfully"
- # Install PHP 8.2 and required extensions
- print_message "Installing PHP 8.2-FPM and extensions..."
- apt install -y software-properties-common
- add-apt-repository -y ppa:ondrej/php
- apt update
- apt install -y php8.2-fpm php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl || {
- print_error "Failed to install PHP 8.2"
- exit 1
- }
- # Enable and start PHP-FPM
- systemctl enable php8.2-fpm
- systemctl start php8.2-fpm
- print_success "PHP 8.2-FPM installed and started successfully"
- # Install MariaDB
- print_message "Installing MariaDB Server..."
- apt install -y mariadb-server || {
- print_error "Failed to install MariaDB"
- exit 1
- }
- # Enable and start MariaDB
- systemctl enable mariadb
- systemctl start mariadb
- print_success "MariaDB installed and started successfully"
- # Secure MariaDB installation
- print_message "It is recommended to secure your MariaDB installation by running: sudo mysql_secure_installation"
- # Install Composer
- print_message "Installing Composer..."
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- php -r "unlink('composer-setup.php');" || {
- print_error "Failed to install Composer"
- exit 1
- }
- print_success "Composer installed successfully"
- # Install Node.js 23
- print_message "Installing Node.js 23..."
- curl -fsSL https://deb.nodesource.com/setup_23.x | bash - || {
- print_error "Failed to add Node.js repository"
- exit 1
- }
- apt install -y nodejs || {
- print_error "Failed to install Node.js"
- exit 1
- }
- # Verify Node.js and npm installation
- NODE_VERSION=$(node -v)
- NPM_VERSION=$(npm -v)
- print_success "Node.js $NODE_VERSION and npm $NPM_VERSION installed successfully"
- # Basic configuration for NGINX with PHP
- print_message "Configuring NGINX to work with PHP..."
- cat > /etc/nginx/sites-available/default << 'EOL'
- server {
- listen 80 default_server;
- listen [::]:80 default_server;
- root /var/www/html;
- index index.php index.html index.htm;
- server_name _;
- location / {
- try_files $uri $uri/ =404;
- }
- location ~ \.php$ {
- include snippets/fastcgi-php.conf;
- fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
- }
- location ~ /\.ht {
- deny all;
- }
- }
- EOL
- # Test NGINX configuration
- nginx -t || {
- print_error "NGINX configuration test failed"
- exit 1
- }
- # Reload NGINX to apply changes
- systemctl reload nginx
- # Display installation summary
- print_message "=== Installation Summary ==="
- echo "NGINX: $(nginx -v 2>&1)"
- echo "PHP: $(php -v | head -n 1)"
- echo "MariaDB: $(mariadb --version)"
- echo "Composer: $(composer --version)"
- echo "Node.js: $NODE_VERSION"
- echo "npm: $NPM_VERSION"
- echo
- print_success "Installation completed successfully!"
- print_message "Next steps:"
- print_message "1. Secure your MariaDB installation: sudo mysql_secure_installation"
- print_message "2. Place your website files in /var/www/html/"
- print_message "3. Set appropriate permissions: sudo chown -R www-data:www-data /var/www/html/"
- print_message "4. Restart services if needed: sudo systemctl restart nginx php8.2-fpm mariadb"
Advertisement