How to install LAMP on CentOS 7.

share on:
install lamp on centos 7

 

Here’s a simple script to install LAMP in CentOS 7 unattended.

I have tested this script on new CentOS 7 server from DigitalOcean. Please use this script at your own risk.

The LAMP will include

  • Apache 2.4.x
  • MariaDB 10.3.8
  • PHP 7.2

The Script will Store MariaDB username and Password info in /root/LAMP.txt file.

To change the MariaDB password then you can follow the instructions from /root/Mysql_password-Change.txt file.

You are free to edit this script in the way you want.

 

Please don’t use this script in production servers 🙂

 

 

#!/bin/sh

    [[email protected] ~]# yum update -y
    yum install epel-release rsync pwgen curl wget unzip -y

    yum install httpd -y
    systemctl enable httpd
    systemctl start httpd
    echo "ServerName localhost" >> /etc/httpd/conf/httpd.conf


    cat <<'EOF' >> /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

    yum remove mariadb-libs -y
    yum -y install MariaDB-server MariaDB-client    

    systemctl enable mariadb
    systemctl start mariadb

    yum install pwgen -y
    PASSWORD=`pwgen -c -1 8`

    mysqladmin -u root password $PASSWORD

    # Maually doing what "mysql_secure_installation" is supposed to do.        
    mysql -uroot -p"$PASSWORD" -e "UPDATE mysql.user SET Password=PASSWORD('$PASSWORD') WHERE User='root'" > /dev/null 2>&1
    mysql -uroot -p"$PASSWORD" -e "DELETE FROM mysql.user where User='root' and Host not in ('localhost','127.0.0.1', '::1')" > /dev/null 2>&1
    mysql -uroot -p"$PASSWORD" -e "DELETE FROM mysql.user where User=''" > /dev/null 2>&1
    mysql -uroot -p"$PASSWORD" -e "DELETE from mysql.db where db='test' or Db='test\_%'" > /dev/null 2>&1
    mysql -uroot -p"$PASSWORD" -e "FLUSH PRIVILEGES" > /dev/null 2>&1

    # restarting MYSQL service
    systemctl restart mariadb
    echo -e "username root \npassword $PASSWORD\n                 >>>>>Have a Nice Day<<<<<\n" >> /root/LAMP.txt
    echo -e "\n\n\n           To change the password to your liking ( for root and other users ) just use this command.\n\n               mysqladmin -u root -p'oldpassword' password 'newpassword'\n\n\n               Don't forget to change "oldpassword" and "newpassword" value.\n\n\n" >> /root/Mysql_password-Change.txt 

    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    yum --enablerepo=remi,remi-php72 install php-mysql php-ldap php-devel php-mbstring php-xmlrpc php-xml php-gd php mod_php php-mysqlnd php-opcache php-pecl-apcu php-cli php-imap php-pear php-pdo php-xsl php-xmlrpc php-pecl-mongodb php-dev php-pgsql php-pecl-redis php-common php-pecl-mongo php-pdo php-pecl-memcache php-pecl-memcached php-gd php-xml php-mbstring php-mcrypt php-pecl-apcu php-cli php-pear php-pecl-zip php-soap php-intl -y

    yum install firewalld -y
    systemctl enable firewalld
    systemctl start firewalld

    firewall-cmd --zone=public --add-service=http --add-service=https --permanent
    firewall-cmd --zone=public --add-port=80/tcp --add-port=443/tcp --permanent
    firewall-cmd --reload

 

 

Thanks for visiting this page and have a great day. 🙂

 

Review overview

Helpful10

Summary

10
share on:
engy

engy

Hello there, My name is Rishi Guleria and I work as a Linux system administrator. I have created this blog to share what I have learned so far and to learn new things. Don't forget to leave the feedback. Have a great day. :)

1 Comment

Leave a Response

share on: