Computers & Electronics
18,328 views
25 min · 3 min read
7 steps
Advanced

How to install and configure a local development LAMP/LEMP stack on Windows, macOS, or Linux

This guide walks you through installing and configuring a local LAMP (Linux/Apache/MySQL/PHP) or LEMP (Linux/Nginx/MySQL/MariaDB/PHP) development stack on Windows, macOS, or Linux. It gives concrete, cross-platform steps and quick configuration tips so you can run PHP-based sites locally in about 30–90 minutes. Follow the steps that match your preferred stack and OS, and test with a simple PHP page.

Verified by pleasexplain editors
  1. Step 1: Choose stack and tools

    Decide whether you want LAMP (Apache) or LEMP (Nginx) and pick an installation method: native packages, a bundled installer (like XAMPP, MAMP, or Laragon), or containerization with Docker. Choosing Docker adds portability and isolates services, while native or bundled installers are faster to get started (expect 10–20 minutes).

    [Illustration: icons for Apache, Nginx, MySQL, PHP, Docker and platform logos]

  2. Step 2: Install package manager

    Install or update a package manager for your OS: Homebrew on macOS (install in ~5 minutes), Chocolatey or Winget on Windows (5–10 minutes), or use the native package manager on Linux (apt, dnf). A package manager simplifies later updates and dependency installation.

    [Illustration: computer screen showing terminal with brew or apt install commands]

  3. Step 3: Install web server

    Install Apache or Nginx using your chosen method: apt install apache2 or nginx on Linux, brew install httpd or nginx on macOS, or install XAMPP/MAMP on Windows/macOS. Start the service and verify by visiting http://localhost; success should show a default page within 1–2 minutes.

    [Illustration: browser window showing localhost default web server page]

  4. Step 4: Install database server

    Install MySQL or MariaDB: apt install mysql-server or mariadb-server on Linux, brew install mysql on macOS, or use bundled server in XAMPP/MAMP. Secure the server by running mysql_secure_installation or setting root password and removing anonymous users (takes 3–5 minutes).

    [Illustration: terminal showing mysql_secure_installation prompts and password entry]

  5. Step 5: Install PHP and extensions

    Install PHP (version 7.4–8.2) and common extensions: apt install php php-mysql php-xml php-curl on Linux, brew install php on macOS, or enable PHP in your bundle. Configure php.ini to set display_errors=On for development and memory_limit=256M; restart the web server (2–5 minutes).

    [Illustration: code editor open to php.ini with display_errors and memory_limit highlighted]

  6. Step 6: Configure virtual hosts and document root

    Create a project folder (e.g., ~/Sites/myproject) and configure virtual hosts: add an entry to hosts file (127.0.0.1 myproject.test) and set server block in Apache or Nginx to point to your document root. This lets you test multiple sites; reload the server to apply changes (5–10 minutes).

    [Illustration: diagram of hosts file entry and server block pointing to project folder]

  7. Step 7: Test with a PHP file and connect DB

    Create info.php with <?php phpinfo(); ?> and place it in your document root, then visit http://myproject.test/info.php to confirm PHP works. Create a test database and a sample connection script using mysqli or PDO; verify connection and basic CRUD in under 10 minutes.

    [Illustration: browser showing phpinfo page and code snippet connecting to MySQL]


  • Back up configuration files (apache2.conf, nginx.conf, php.ini, my.cnf) before editing so you can revert changes quickly.
  • Use version-specific PHP managers (phpenv, valet, or Docker images) to switch PHP versions within 1–2 minutes per switch without breaking other projects.
  • Set file permissions for your document root to allow your user and the web server to read and write, for example chown -R youruser:www-data and chmod -R 750 on Linux.
  • Enable error logging to a dedicated file and set error_log and log_level appropriately to diagnose issues without exposing errors to users.
  • Use isolated virtual hosts or Docker networks to prevent port conflicts; configure services to listen on non-standard ports if necessary (e.g., 8080 or 9000).
  • Automate common tasks with scripts or docker-compose files so you can spin up the full stack in 10–30 seconds on repeat runs.

  • Never enable display_errors=On in production; it leaks sensitive paths and data beyond a local environment.
  • Do not run database servers without a password or open them to the public internet; bind MySQL/MariaDB to 127.0.0.1 if you only need local access.
  • Editing the system hosts file requires administrator privileges; make a copy before changes in case you need to restore it later.
  • Running multiple bundled installers (XAMPP, MAMP, Laragon) simultaneously can cause port collisions—stop one stack before starting another.

Was this guide helpful?