Pratik Patil Pratik Patil - 11 months ago 97
Bash Question

Automated Installation of LAMP Stack Using Shell Script

How to automate the installation of LAMP Stack? As we have to install several packages one by one and then configure them. Again we have to separately install some GUI tool like phpMyAdmin or MySQL-Workbench to access MySQL databases. Is it possible to make this full installation completely automated? Using shell script or something else?


Answer Source

I have prepared the following shell script to make this installation fully automated.

# ******************************************
# Program: LAMP Stack Installation Script
# Developer: Pratik Patil
# Date: 10-04-2015
# Last Updated: 11-01-2016
# ******************************************

if [ "`lsb_release -is`" == "Ubuntu" ] || [ "`lsb_release -is`" == "Debian" ]
    sudo apt-get -y install mysql-server mysql-client mysql-workbench libmysqld-dev;
    sudo apt-get -y install apache2 php5 libapache2-mod-php5 php5-mcrypt phpmyadmin;
    sudo chmod 755 -R /var/www/;
    sudo printf "<?php\nphpinfo();\n?>" > /var/www/html/info.php;
    sudo service apache2 restart;

elif [ "`lsb_release -is`" == "CentOS" ] || [ "`lsb_release -is`" == "RedHat" ]
    sudo yum -y install httpd mysql-server mysql-devel php php-mysql php-fpm;
    sudo yum -y install epel-release phpmyadmin rpm-build redhat-rpm-config;
    sudo yum -y install mysql-community-release-el7-5.noarch.rpm proj;
    sudo yum -y install tinyxml libzip mysql-workbench-community;
    sudo chmod 777 -R /var/www/;
    sudo printf "<?php\nphpinfo();\n?>" > /var/www/html/info.php;
    sudo service mysqld restart;
    sudo service httpd restart;
    sudo chkconfig httpd on;
    sudo chkconfig mysqld on;

    echo "Unsupported Operating System";

Open Following URL in browser to verify the installation of Apache Server:


Open Following URL in browser to verify the installation of PHP: