Skip to content

Instantly share code, notes, and snippets.

@hasanbayatme
Last active December 23, 2023 20:14
Show Gist options
  • Save hasanbayatme/737fbb9f403d4dd66dee1364d866ba7e to your computer and use it in GitHub Desktop.
Save hasanbayatme/737fbb9f403d4dd66dee1364d866ba7e to your computer and use it in GitHub Desktop.
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
Copy link

works like a charm ;) thank you

@BananaRaptor
Copy link

Awesome ! Thanks a lot

@walditamaniko
Copy link

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

@JayGreentree
Copy link

mysql should be replaced by mariadb

@lukosevicius
Copy link

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