Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Easy to use Bash Script to Install LAMP stack on Ubuntu.

Installation

Automatic

Run the below command in terminal:

wget --no-cache -O - https://gist.github.com/EmpireWorld/737fbb9f403d4dd66dee1364d866ba7e/raw/install-lamp.sh | bash

➡️ Go to next steps

Manual

First off, run the below command to update package index:

sudo apt update

Then run these commands in terminal separately to install each component:

Apache

sudo apt install apache2

MySQL

sudo apt install mysql-server

PHP

sudo apt install php php-mysql libapache2-mod-php php-cli

Adjust Firewall

sudo ufw allow in "Apache Full"

Adjust permissions

sudo chmod -R 0755 /var/www/html/

Allow running Apache on boot up

sudo systemctl enable apache2

Start Apache server

sudo systemctl start apache2

Test Apache

xdg-open "http://localhost"

Create sample PHP script file

sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php

Run sample PHP script file

xdg-open "http://localhost/info.php"

➡️ Go to next steps

Next Steps

Install phpMyAdmin

Run the below command in terminal to install phpMyAdmin and it's prerequisites:

sudo apt install phpmyadmin php-mbstring php-gettext

And then enable required extensions:

sudo phpenmod mcrypt
sudo phpenmod mbstring

Then restart Apache server:

sudo systemctl restart apache2

Now navigate to the phpMyAdmin:

xdg-open "http://localhost"

All done. now you have Apache2, MySQL, PHP installed.

Made with ❤️ by Bayat

#!/bin/bash
# Update Package Index
sudo apt update
# Install Apache2, MySQL, PHP
sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-cli
# Allow to run Apache on boot up
sudo systemctl enable apache2
# Restart Apache Web Server
sudo systemctl start apache2
# Adjust Firewall
sudo ufw allow in "Apache Full"
# Allow Read/Write for Owner
sudo chmod -R 0755 /var/www/html/
# Create info.php for testing php processing
sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# Open localhost in the default browser
xdg-open "http://localhost"
xdg-open "http://localhost/info.php"
@q99qk72xy

This comment has been minimized.

Copy link

@q99qk72xy q99qk72xy commented Nov 20, 2019

works like a charm ;) thank you

@BananaRaptor

This comment has been minimized.

Copy link

@BananaRaptor BananaRaptor commented Apr 24, 2020

Awesome ! Thanks a lot

@walditamaniko

This comment has been minimized.

Copy link

@walditamaniko walditamaniko commented May 23, 2020

Thanks for saving my time
Work 100% on Ubuntu 16.04 lts server

@JayGreentree

This comment has been minimized.

Copy link

@JayGreentree JayGreentree commented Jun 8, 2020

mysql should be replaced by mariadb

@lukosevicius

This comment has been minimized.

Copy link

@lukosevicius lukosevicius commented Sep 14, 2020

Thanks! used it so many times already

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.