#!/bin/bash

# Update CentOS
dnf update -y

# Install Apache
dnf install httpd -y

# Start Apache
systemctl start httpd

# Enable Apache to start on boot
systemctl enable httpd

# Install WGET
dnf install wget -y

# Install PHP 8.0 and required modules
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
dnf module enable php:remi-8.0 -y
dnf install php php-common php-fpm php-gd php-intl php-json php-mbstring php-mysqlnd php-opcache php-pecl-imagick php-pecl-redis php-pecl-zip php-process php-xml -y

# Restart Apache
systemctl restart httpd

# Install MySQL 8.0
cd /tmp/
wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
dnf -y localinstall mysql80-community-release-el9-1.noarch.rpm 
dnf module reset mysql -y
dnf module enable mysql:8.0 -y
dnf install -y mysql-community-server mysql-community-libs-compat mysql-community-client

# Start MySQL and enable it to start on boot
systemctl start mysqld
systemctl enable mysqld

# Get temporary MySQL root password
grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}' > /tmp/mysql-root-pw

# Restart Apache
systemctl restart httpd

This Bash script automates the installation of a LAMP (Linux, Apache, MySQL, PHP) stack on CentOS 9. The script performs the following steps:

#Updates CentOS 9 to the latest version using dnf update.

#Installs Apache web server using dnf install httpd.

#Starts Apache service using systemctl start httpd.

#Enables the Apache service to start automatically at boot using systemctl enable httpd.

#Installs wget using dnf install wget.

#Installs PHP 8.0 and the required modules using the Remi repository and dnf install command.

#Restarts the Apache service to load the updated PHP modules using systemctl restart httpd.

#Downloads and installs the MySQL repository, resets the MySQL module, enables the MySQL 8.0 module, and installs MySQL server, client, and library packages using dnf command.

#Starts the MySQL server using systemctl start mysqld and enables it to start on boot using systemctl enable mysqld.

#Gets the temporary root password for MySQL from the log file and saves it to /tmp/mysql-root-pw.

#Restarts the Apache service again to ensure all changes are applied using systemctl restart httpd.

Overall, this script automates the installation of a basic LAMP stack on CentOS 9, which is useful for setting up a web server or a development environment.

Tagged in:

, , , ,