A New L.A.M.P Installer

#!/bin/bash

###############################################################################
# 📦 One-Click LAMP Installer Script
# ---------------------------------------
# Installs a complete LAMP or LEMP stack (Apache/Nginx, MariaDB, PHP) on
# Ubuntu 20.04/22.04 or Debian 11+ with minimal interaction.
#
# wget https://raw.githubusercontent.com/hosteons/lamp-lemp-oneclick-installer/main/lamp_lemp_installer.sh
# nano apache.sh
# chmod +x apache.sh
# bash ./apache.sh
#
# 📝 License: MIT
# You are free to use, modify, and distribute this script. Attribution is appreciated.
###############################################################################

set -e

echo "====================================="
echo " One-Click LEMP Installer Script"
echo " by Hosteons.com | MIT Licensed"
echo "====================================="

if [[ "$EUID" -ne 0 ]]; then
  echo "❌ Please run this script as root"
  exit 1
fi

if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$ID
    VER=$VERSION_ID
else
    echo "❌ Unsupported OS"
    exit 1
fi

if [[ "$OS" != "ubuntu" && "$OS" != "debian" ]]; then
    echo "❌ Only Ubuntu and Debian are supported."
    exit 1
fi

apt -y update
apt-get install nano wget curl perl sudo -y
echo "🔧 Installing LEMP stack..."
sudo apt -y install apache2 mariadb-server mariadb-client -y
sudo systemctl enable apache2 --now
sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-imagick php-fpm php-mbstring php-zip php-xml
curl -o setup-repos.sh https://raw.githubusercontent.com/webmin/webmin/master/setup-repos.sh 
sh setup-repos.sh 
apt -y install webmin --install-recommends 
echo "✅ Webmin configured."
echo "✅ LAMP configured."
echo "🔧 Making Website"
read -rp "Enter your domain name (e.g. example.com): " DOMAIN   
sudo mkdir /var/www/$DOMAIN
sudo chown -R "$USER":www-data /var/www/$DOMAIN
sudo chmod -R 755 /var/www/$DOMAIN
cat <<EOF > /etc/apache2/sites-available/$DOMAIN.conf
<VirtualHost *:80>
    ServerName $DOMAIN
     DocumentRoot /var/www/$DOMAIN
    <Directory "/var/www/$DOMAIN">
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/$DOMAIN.error.log
    CustomLog ${APACHE_LOG_DIR}/$DOMAIN.access.log combined
</VirtualHost>

EOF
cat <<EOF > /var/www/$DOMAIN/uptime.php
<?php
function sec2human($time) {
  $seconds = $time%60;
    $mins = floor($time/60)%60;
    $hours = floor($time/60/60)%24;
    $days = floor($time/60/60/24);
    return $days > 0 ? "$days day".($days > 1 ? 's' : '') : "$hours:$mins:$seconds";
}

$array = array();
$fh = fopen('/proc/uptime', 'r');
$uptime = fgets($fh);
fclose($fh);
$uptime = explode('.', $uptime, 2);
$array['uptime'] = sec2human($uptime[0]);


$fh = fopen('/proc/meminfo', 'r');
  $mem = 0;
  while ($line = fgets($fh)) {
    $pieces = array();
    if (preg_match('/^MemTotal:\s+(\d+)\skB$/', $line, $pieces)) {
      $memtotal = $pieces[1];
    }
    if (preg_match('/^MemFree:\s+(\d+)\skB$/', $line, $pieces)) {
      $memfree = $pieces[1];
    }
    if (preg_match('/^Cached:\s+(\d+)\skB$/', $line, $pieces)) {
      $memcache = $pieces[1];
      break;
    }
  }
fclose($fh);

$memmath = $memcache + $memfree;
$memmath1 = ($memcache + $memfree) /1000;
$memmath2 = $memmath / $memtotal * 100;
$memmath3 = $memtotal /1000;
$memmath4 = ($memtotal - ($memcache + $memfree))/1000;
$memmath5 = ($memtotal - $memfree)/1000;
$memmath6 = $memcache/1000;

$memory = round($memmath2) . '%';
$memory1 = round($memmath1) . 'mb ';
$memory3 = round($memmath3) . ' ';
$memory4 = round($memmath4) . ' ';
$memory5 = round($memmath5) . ' ';
$memory6 = round($memmath6) . ' ';

$memlevel = "success";
if ($memory <= 50) { $memlevel = "warning"; }
if ($memory <= 35) { $memlevel = "danger"; }

$array['memory'] ="<center>$memory3 / $memory4</center>";

$hddtotal = disk_total_space("/");
$hddfree = disk_free_space("/");
$hddmath = $hddfree / $hddtotal * 100;

$hddmath1 = $hddtotal /1000000000;
$hddmath2 = $hddfree /1000000000;
$hddmath3 = ($hddtotal-$hddfree) /1000000000;

$hdd = round($hddmath) . '%';
$hdd1 = round($hddmath1) . '';
$hdd2 = round($hddmath2) . '';
$hdd3 = round($hddmath3) . '';
$hdd = round($hddmath);

$hddlevel = "success";
if ($hdd <= 50) { $hddlevel = "warning"; }
if ($hdd <= 35) { $hddlevel = "danger"; }

$array['hdd'] = "<center>$hdd1 / $hdd3</center>";

$load = sys_getloadavg();
$array['load'] = $load[0];

$array['online'] = '<div align="center" style="font-size:0.85em;"><font color=green face=corbel> &#x25B2;</div>';
echo json_encode($array);
EOF
sudo apache2ctl configtest
sudo a2ensite $DOMAIN.conf
sudo a2dissite 000-default.conf
sudo a2enmod rewrite
sudo apt install php-opcache -y
sudo systemctl restart apache2
echo "Hello $DOMAIN!  This is LAMP webserver." | sudo tee /var/www/$DOMAIN/index.php
echo "✅ LAMP configured."
echo "✅ Let's Encrypt."
sudo apt -y install certbot python3-certbot-apache
sudo certbot --apache

######################Old way ro making websites################################################
sudo mkdir -p /var/www/example.com
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 755 /var/www/your-domain
sudo nano /etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
    <Directory "/var/www/example.com">
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
    CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
</VirtualHost>
sudo apache2ctl configtest
sudo a2ensite example.com.conf
sudo a2dissite 000-default.conf
sudo apt install php-opcache -y
sudo systemctl restart apache2

#######################################
Secure with Let’s Encrypt on Debian
#######################################
sudo apt install python3-certbot-apache -y
sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d example.com
sudo systemctl status certbot.timer
sudo certbot renew --dry-run
test with https://domai


Posted : Friday 26th of June 2026 @ 11:58 PM— Tags : lamp-installer