#!/bin/bash


#Update CentOS
yum update -y

#Install Apache
yum install httpd -y

#Start Apache
systemctl start httpd

#Enable Apache to start on boot
systemctl enable httpd

#Install WGET & Unzip
yum install wget  unzip -y


#Install PHP 7.2 and required modules
yum install epel-release -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager --enable remi-php72
yum 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 5.7

cd /tmp/

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm

yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql56-community

yum 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

#Restart Apache

systemctl restart httpd

This is a bash script that automates the installation of LAMP stack on a CentOS 7 server. Here’s what each line of the script does:

#!/bin/bash: This is called the “shebang” line and tells the shell to interpret the script using the bash shell.

yum update -y: This updates the CentOS system to the latest software packages.

yum install httpd -y: This installs Apache web server.

systemctl start httpd: This starts the Apache web server.

systemctl enable httpd: This configures the Apache web server to start automatically at boot time.

yum install wget unzip -y: This installs the wget and unzip utilities.

yum install epel-release -y: This installs the Extra Packages for Enterprise Linux (EPEL) repository.

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y: This installs the Remi repository, which provides PHP packages.

yum-config-manager --enable remi-php72: This enables the Remi repository to install PHP 7.2.

yum 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: This installs PHP 7.2 and the required PHP modules.

systemctl restart httpd: This restarts the Apache web server to load the PHP modules.

cd /tmp/: This changes the current directory to the /tmp directory.

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm: This downloads the MySQL 5.7 repository package.

yum -y localinstall mysql57-community-release-el7-11.noarch.rpm: This installs the MySQL 5.7 repository package.

yum-config-manager --disable mysql57-community: This disables the MySQL 5.7 repository.

yum-config-manager --enable mysql56-community: This enables the MySQL 5.6 repository.

yum install -y mysql-community-server mysql-community-libs-compat mysql-community-client: This installs MySQL 5.7 and the required MySQL packages.

systemctl start mysqld: This starts the MySQL server.

systemctl enable mysqld: This enables the MySQL server to start automatically at boot time.

systemctl restart httpd: This restarts the Apache web server to load the PHP modules.

To run this script, you need to save it as a file with a .sh extension (e.g. install_lamp.sh), make it executable (chmod +x install_lamp.sh), and run it with root privileges (sudo ./install_lamp.sh).

Categorized in: