#!/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-8.noarch.rpm -y
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.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-el8-1.noarch.rpm

dnf -y localinstall mysql80-community-release-el8-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 the LAMP (Linux, Apache, MySQL, PHP) stack on CentOS 8. It does the following:

#Updates CentOS to the latest version using dnf update.

#Installs Apache using dnf install httpd.

#Starts Apache and enables it to start automatically at boot using systemctl start httpd and systemctl enable httpd.

#Installs wget using dnf install wget.

#Installs PHP 8.0 and required modules using the Remi repository and the dnf install command with a list of packages. It enables the PHP 8.0 module using the dnf module enable command.

#Restarts Apache to make sure it is using the updated PHP version using systemctl restart httpd.

#Installs MySQL 8.0 using the MySQL repository and dnf install command with a list of packages. It enables the MySQL 8.0 module using the dnf module enable command.

#Starts MySQL and enables it to start automatically at boot using systemctl start mysqld and systemctl enable mysqld.

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

#Restarts Apache again to make sure everything is working correctly.

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