Skip to content

Instantly share code, notes, and snippets.

@aamnah
Last active February 19, 2024 11:51
Show Gist options
  • Star 56 You must be signed in to star a gist
  • Fork 49 You must be signed in to fork a gist
  • Save aamnah/f03c266d715ed479eb46 to your computer and use it in GitHub Desktop.
Save aamnah/f03c266d715ed479eb46 to your computer and use it in GitHub Desktop.
Bash script to install Apache, MySQL and PHP as well as PHPMyAdmin and some tweaks. For Debian and Ubuntu. To run, copy the script to the server and run ``bash lamp.sh``
#!/bin/sh
#######################################
# Bash script to install an AMP stack and PHPMyAdmin plus tweaks. For Debian based systems.
# Written by @AamnahAkram from http://aamnah.com
# In case of any errors (e.g. MySQL) just re-run the script. Nothing will be re-installed except for the packages with errors.
#######################################
#COLORS
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
# Update packages and Upgrade system
echo -e "$Cyan \n Updating System.. $Color_Off"
sudo apt-get update -y && sudo apt-get upgrade -y
## Install AMP
echo -e "$Cyan \n Installing Apache2 $Color_Off"
sudo apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert -y
echo -e "$Cyan \n Installing PHP & Requirements $Color_Off"
sudo apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-mcrypt php5-mysql php5-ps php5-pspell php5-recode php5-xsl -y
echo -e "$Cyan \n Installing MySQL $Color_Off"
sudo apt-get install mysql-server mysql-client libmysqlclient15.dev -y
echo -e "$Cyan \n Installing phpMyAdmin $Color_Off"
sudo apt-get install phpmyadmin -y
echo -e "$Cyan \n Verifying installs$Color_Off"
sudo apt-get install apache2 libapache2-mod-php5 php5 mysql-server php-pear php5-mysql mysql-client mysql-server php5-mysql php5-gd -y
## TWEAKS and Settings
# Permissions
echo -e "$Cyan \n Permissions for /var/www $Color_Off"
sudo chown -R www-data:www-data /var/www
echo -e "$Green \n Permissions have been set $Color_Off"
# Enabling Mod Rewrite, required for WordPress permalinks and .htaccess files
echo -e "$Cyan \n Enabling Modules $Color_Off"
sudo a2enmod rewrite
sudo php5enmod mcrypt
# Restart Apache
echo -e "$Cyan \n Restarting Apache $Color_Off"
sudo service apache2 restart
@flexchar
Copy link

flexchar commented Mar 7, 2018

To get quickly started:

cd ~
wget https://gist.github.com/aamnah/f03c266d715ed479eb46/raw/758ef5aa1e05d5b518b74638865bc2029a5a1fe7/lamp.sh
chmod -x ./lamp.sh
bash ./lamp.sh

Note for those looking PHP 5.6: it appears that Ubuntu 17.+ builds no more include old versions. Use add-apt-repository ppa:ondrej/php && apt update and then install with apt install php5.6 instead php5.

@azazqadir
Copy link

Manually installing PHP MySQL and other on a Debian based server is still a time taking task. It is better to use Cloudways PHP MySQL hosting where you can launch a server in one-click with PHP stack already installed and configured. This saves time and energy.

@m45k174
Copy link

m45k174 commented Jun 2, 2019

For Debian 9:
Change:
php5 --> php
remove sudo
use 'su' before running the script

@aamnah
Copy link
Author

aamnah commented Jun 2, 2019

didn't realize people actually saw or used this script until i got the notification for the last reply.. there is an updated version here https://github.com/aamnah/bash-scripts/blob/master/install/amp_debian.sh good idea about sudo, will update this gist

@anilnetmente
Copy link

How can i add ondrej repo to download and install php 7.2 ?
Can you please define the code which can i use in lamp.sh

@francoross
Copy link

francoross commented Apr 15, 2021

./lamp.sh: line 1: syntax error near unexpected token `newline'
./lamp.sh: line 1: `<!DOCTYPE html>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment