Published December 15, 2018 by

Install LAMP stack in Ubuntu using Shell Script



LAMP is a combination of operating system and open-source software stack. The acronym LAMP came from the first letters of Linux, Apache HTTP Server, MySQL or MariaDB database, and PHP/Perl/Python.

In this tutorial, we install LAMP stack using run single shell script on Ubuntu LAMP (Linux, Apache, MySQL and PHP, PhpMyAdmin) stack.

This Script will be working on all Ubuntu versions.

What this script does:
  1. Install Apache Web server
  2. Install PHP
  3. Install MySQL
  4. Install PhpMyAdmin
For Install LAMP stack Create a file named lamp.sh
 sudo vim lamp.sh  

Insert Below script in a lamp.sh file and save.

 #!/bin/bash  
   
 #######################################  
 # Bash script to install an LAMP stack in ubuntu  
 # Author: Subhash (serverkaka.com)  
   
 # Check if running as root  
 if [ "$(id -u)" != "0" ]; then  
   echo "This script must be run as root" 1>&2  
   exit 1  
 fi  
   
 # Ask value for mysql root password   
 read -p 'db_root_password [secretpasswd]: ' db_root_password  
 echo  
   
 # Update system  
 sudo apt-get update -y  
   
 ## Install APache  
 sudo apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert -y  
   
 ## Install PHP  
 apt-get install php libapache2-mod-php php-mysql -y  
   
 # Install MySQL database server  
 export DEBIAN_FRONTEND="noninteractive"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password"  
 apt-get install mysql-server -y  
   
 # Enabling Mod Rewrite  
 sudo a2enmod rewrite  
 sudo php5enmod mcrypt  
   
 ## Install PhpMyAdmin  
 sudo apt-get install phpmyadmin -y  
   
 ## Configure PhpMyAdmin  
 echo 'Include /etc/phpmyadmin/apache.conf' >> /etc/apache2/apache2.conf  
   
 # Set Permissions  
 sudo chown -R www-data:www-data /var/www  
   
 # Restart Apache  
 sudo service apache2 restart  

Give execute permission to lamp.sh file
 sudo chmod +x lamp.sh  

Finally, now run the lamp.sh file
 sudo ./lamp.sh  

After successfully script execute, Go to a browser and hit http://localhost/



For access PhpMyAdmin hit http://localhost/phpmyadmin


For access MySQL use below command:
 mysql -u root -p   

For check PHP installation use below command:
 php -v  

Reference: https://github.com/SubhashPatel?tab=repositories