Automating LAMP stack installation

The LAMP stack; Linux, Apache, Mysql and PHP changed the web -- forever. These four musketeers empowered hobbyist, novice and pro launch their ideas to the world with so much ease that the stack has over the years endured an onslaught of new shinny frameworks and tools.

These days, you might hear the cool kids talking about the MEAN stack (MongoDB, Express JS, Angular JS and NodeJS) but don't fall for it yet. These technologies are still in their infancy, stick to what has worked.

But installing the LAMP stack is no easy feat if you are not an advanced Linux user. Most users especially my Windows brothers usually just install xampp or wamp on their local machines and it usually does the job at least for local development. In production, you don't want to use these.

So here's a script that installs Apache, PHP and the most important extensions, Mysql and the awesome Phpmyadmin. This will install your distros default package version. For instance if installing on Ubuntu 16.04 LTS, it'll install php7.0 and php 5.6 on 14.04 LTS.

#!/bin/bash
#update packages 
sudo apt-get update  
#install apache
sudo apt-get -y install apache2  
#install mysql 
my_mysql_password="strong_password"  
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $my_mysql_password"  
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $my_mysql_password"  
sudo apt-get -y install mysql-server  
#install php and important modules 
sudo apt-get -y install php php-cli libapache2-mod-php php-mcrypt php-mysql php-curl  
#install phpmyadmin 
apt-get install pwgen -y #strong  password autogenerator  
MYSQL_ROOT_PASS="$my_mysql_password"  
AUTOGENERATED_PASS=$(pwgen -c -1 20)  
debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"  
debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"  
debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-user string root"  
debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $MYSQL_ROOT_PASS"  
debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $AUTOGENERATED_PASS"  
debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $AUTOGENERATED_PASS"  
apt-get -y install phpmyadmin  
service apache2 reload  

You can save this somewhere on your Linux machine as lamp.sh and make it executable using sudo chmod +x lamp.sh. Run it as ./lamp.sh or bash lamp.sh.

David Okwii

David Okwii is a Ugandan-based Technology writer and System's Engineer.

Kampala Uganda http://www.davidokwii.com

Subscribe to oquidave@geek:~ #

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!