shutdown57

NGINX + PHP8.2-FPM + NODEJS23 + MARIADB PACKAGE INSTALLATION

May 3rd, 2025
638
0
Never
8
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.56 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Automated Installation Script for NGINX, PHP 8.2-FPM, MariaDB, Composer, and Node.js 23
  4. # Created on: May 03, 2025
  5.  
  6. # Exit on any error
  7. set -e
  8.  
  9. # Colors for better readability
  10. GREEN='\033[0;32m'
  11. BLUE='\033[0;34m'
  12. RED='\033[0;31m'
  13. NC='\033[0m' # No Color
  14.  
  15. # Function to print messages
  16. print_message() {
  17.     echo -e "${BLUE}[INFO]${NC} $1"
  18. }
  19.  
  20. # Function to print errors
  21. print_error() {
  22.     echo -e "${RED}[ERROR]${NC} $1"
  23. }
  24.  
  25. # Function to print success messages
  26. print_success() {
  27.     echo -e "${GREEN}[SUCCESS]${NC} $1"
  28. }
  29.  
  30. # Check if script is run as root
  31. if [ "$(id -u)" -ne 0 ]; then
  32.     print_error "This script must be run as root or with sudo privileges"
  33.     exit 1
  34. fi
  35.  
  36. print_message "Starting installation of NGINX, PHP 8.2-FPM, MariaDB, Composer, and Node.js 23"
  37. print_message "Updating system packages..."
  38.  
  39. # Update system
  40. apt update && apt upgrade -y || {
  41.     print_error "Failed to update system packages"
  42.     exit 1
  43. }
  44.  
  45. print_success "System packages updated successfully"
  46.  
  47. # Install NGINX
  48. print_message "Installing NGINX..."
  49. apt install -y nginx || {
  50.     print_error "Failed to install NGINX"
  51.     exit 1
  52. }
  53.  
  54. # Enable and start NGINX
  55. systemctl enable nginx
  56. systemctl start nginx
  57. print_success "NGINX installed and started successfully"
  58.  
  59. # Install PHP 8.2 and required extensions
  60. print_message "Installing PHP 8.2-FPM and extensions..."
  61. apt install -y software-properties-common
  62. add-apt-repository -y ppa:ondrej/php
  63. apt update
  64. 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 || {
  65.     print_error "Failed to install PHP 8.2"
  66.     exit 1
  67. }
  68.  
  69. # Enable and start PHP-FPM
  70. systemctl enable php8.2-fpm
  71. systemctl start php8.2-fpm
  72. print_success "PHP 8.2-FPM installed and started successfully"
  73.  
  74. # Install MariaDB
  75. print_message "Installing MariaDB Server..."
  76. apt install -y mariadb-server || {
  77.     print_error "Failed to install MariaDB"
  78.     exit 1
  79. }
  80.  
  81. # Enable and start MariaDB
  82. systemctl enable mariadb
  83. systemctl start mariadb
  84. print_success "MariaDB installed and started successfully"
  85.  
  86. # Secure MariaDB installation
  87. print_message "It is recommended to secure your MariaDB installation by running: sudo mysql_secure_installation"
  88.  
  89. # Install Composer
  90. print_message "Installing Composer..."
  91. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  92. php composer-setup.php --install-dir=/usr/local/bin --filename=composer
  93. php -r "unlink('composer-setup.php');" || {
  94.     print_error "Failed to install Composer"
  95.     exit 1
  96. }
  97. print_success "Composer installed successfully"
  98.  
  99. # Install Node.js 23
  100. print_message "Installing Node.js 23..."
  101. curl -fsSL https://deb.nodesource.com/setup_23.x | bash - || {
  102.     print_error "Failed to add Node.js repository"
  103.     exit 1
  104. }
  105. apt install -y nodejs || {
  106.     print_error "Failed to install Node.js"
  107.     exit 1
  108. }
  109.  
  110. # Verify Node.js and npm installation
  111. NODE_VERSION=$(node -v)
  112. NPM_VERSION=$(npm -v)
  113. print_success "Node.js $NODE_VERSION and npm $NPM_VERSION installed successfully"
  114.  
  115. # Basic configuration for NGINX with PHP
  116. print_message "Configuring NGINX to work with PHP..."
  117. cat > /etc/nginx/sites-available/default << 'EOL'
  118. server {
  119.     listen 80 default_server;
  120.     listen [::]:80 default_server;
  121.  
  122.     root /var/www/html;
  123.     index index.php index.html index.htm;
  124.     server_name _;
  125.  
  126.     location / {
  127.         try_files $uri $uri/ =404;
  128.     }
  129.  
  130.     location ~ \.php$ {
  131.         include snippets/fastcgi-php.conf;
  132.         fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
  133.     }
  134.  
  135.     location ~ /\.ht {
  136.         deny all;
  137.     }
  138. }
  139. EOL
  140.  
  141. # Test NGINX configuration
  142. nginx -t || {
  143.     print_error "NGINX configuration test failed"
  144.     exit 1
  145. }
  146.  
  147. # Reload NGINX to apply changes
  148. systemctl reload nginx
  149.  
  150. # Display installation summary
  151. print_message "=== Installation Summary ==="
  152. echo "NGINX: $(nginx -v 2>&1)"
  153. echo "PHP: $(php -v | head -n 1)"
  154. echo "MariaDB: $(mariadb --version)"
  155. echo "Composer: $(composer --version)"
  156. echo "Node.js: $NODE_VERSION"
  157. echo "npm: $NPM_VERSION"
  158. echo
  159.  
  160. print_success "Installation completed successfully!"
  161. print_message "Next steps:"
  162. print_message "1. Secure your MariaDB installation: sudo mysql_secure_installation"
  163. print_message "2. Place your website files in /var/www/html/"
  164. print_message "3. Set appropriate permissions: sudo chown -R www-data:www-data /var/www/html/"
  165. print_message "4. Restart services if needed: sudo systemctl restart nginx php8.2-fpm mariadb"
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment