CoachingUgosay

Lightning LAMP Setup: Quick and Easy Web Development

Video Thumbnail

What is LAMP?  

The LAMP stack consists of four open-source components—Linux, Apache, MySQL, and PHP that work together to build and run dynamic websites and web applications. In this setup:

  • Linux provides the operating system.
  • Apache functions as the web server.
  • MySQL manages the database.
  • PHP serves as the scripting language that delivers server-side functionality.

Node.js  

Node.js allows JavaScript to run outside of a web browser. It enables the creation of server-side programs and even full-stack applications using only JavaScript.

npm (Node Package Manager) 

npm comes bundled with Node.js. It is used to download, install, and manage tools or libraries (called packages) for your projects. It also allows you to publish your own packages for others to use.

nvm (Node Version Manager) 

nvm is a command-line tool that lets you install and switch between multiple versions of Node.js on the same machine. This is especially useful when different projects require different Node.js versions.

LAMP + Node.js Installation Script – Explanation

  1. Stop on errors
    • Script will exit if any command fails (set -e).
  2. Update system packages
    • apt update → refresh package list
    • apt upgrade → install latest updates
  3. Install Apache (Web Server)
    • apt install apache2 → install Apache
    • systemctl enable/start apache2 → start now & auto-start on boot
  4. Install MySQL (Database)
    • apt install mysql-server → install MySQL
    • systemctl enable/start mysql → start now & auto-start on boot
  5. Install PHP (Server-side scripting language)
    • apt install php libapache2-mod-php php-mysql → PHP + MySQL support
    • systemctl restart apache2 → reload Apache with PHP
  6. Create test PHP page
    • Creates info.php to check PHP: http://example.com/info.php
  7. Install Node.js using NVM (Node Version Manager)
    • curl → download tool if missing
    • Install NVM → easy Node.js version management
  8. Load NVM
    • Add NVM to .bashrc → available in future terminals
    • Load NVM now → available immediately
  9. Install latest Node.js LTS
    • nvm install --lts → install latest stable Node.js
    • nvm use --lts → use it now
    • nvm alias default 'lts/*' → set as default
  10. Update PATH
    • Make node and npm commands work immediately
  11. Show installed versions
    • Prints NVM, Node.js, and NPM versions

How to Run the Installation Script

  1. Copy the script content into a file.
  2. Save the file with a .sh extension (for example: lamp.sh).
  3. Open your terminal and navigate to the file’s directory.
  4. Make the script executable (only needed once):

Script:

#!/bin/bash
# LAMP + Node.js Installation Script (Ubuntu/Debian)

# Exit on any error
set -e

echo "============================"
echo " Updating system packages..."
echo "============================"
sudo apt update -y
sudo apt upgrade -y

# ----------------------------
# Install LAMP
# ----------------------------
echo "============================"
echo " Installing Apache..."
echo "============================"
sudo apt install apache2 -y
sudo systemctl enable apache2
sudo systemctl start apache2

echo "============================"
echo " Installing MySQL..."
echo "============================"
sudo apt install mysql-server -y
sudo systemctl enable mysql
sudo systemctl start mysql

echo "============================"
echo " Installing PHP..."
echo "============================"
sudo apt install php libapache2-mod-php php-mysql -y

echo " Restarting Apache to load PHP..."
sudo systemctl restart apache2

echo "============================"
echo " LAMP installation completed!"
echo "============================"

# Create PHP test file
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php > /dev/null
echo "Test PHP by visiting: `http://example.com/info.php`"

# ----------------------------
# Install Node.js, NVM, and NPM
# ----------------------------
echo "============================"
echo " Installing Node.js via NVM..."
echo "============================"

# Install curl if not installed
sudo apt install curl -y

# Install NVM (Node Version Manager)
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
fi

# Add NVM to bashrc if not already present
if ! grep -q 'NVM_DIR' ~/.bashrc; then
    echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
    echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc
    echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> ~/.bashrc
fi

# Load NVM into current session
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

# ----------------------------
# Install Node.js LTS + set default
# ----------------------------
echo "Installing latest LTS version of Node.js..."
nvm install --lts
nvm use --lts
nvm alias default 'lts/*'

# Ensure Node & NPM are in PATH immediately
export PATH="$NVM_DIR/versions/node/$(nvm version)/bin:$PATH"

echo "============================"
echo " Node.js, NPM, and NVM installed successfully!"
echo "============================"
echo "Versions installed:"
echo "NVM:  $(nvm -v)"
echo "Node: $(node -v)"
echo "NPM:  $(npm -v)"


More articles

How to Run LLMs Model Locally (Step-by-Step Guide)

Step-by-step guide to run LLMs locally with Python. Set up dependencies, download models, and run inference on your machine without cloud costs.

Read more

Design Without Research Is Just Guesswork

Generative AI in UI/UX isn’t about replacing designers — it’s about amplifying them. By turning transcripts into insights, drafts, and prototypes in hours, AI frees teams to focus on strategy and creativity. The real value lies in designers orchestrating AI outputs into human-centered, ethical, and impactful experiences.

Read more

Connect with Us

Got questions or need help with your project? Fill out the form, and our team will get back to you soon. We’re here for inquiries, collaborations, or anything else you need.

Address
12, Sri Vigneshwara Nagar, Amman Kovil
Saravanampatti, coimbatore, TN, India - 641035