LAMP Stack From Scratch

Frameworks come and go. A solid LAMP stack is still the most cost-effective way to run high-performance PHP sites. This guide focuses on a clean manual setup so you understand what’s happening.

1. Install the core packages

Install Apache, PHP 8.2, and MySQL. Keep it minimal and add extensions only when you actually need them.

2. Virtual hosts and document roots

Use a dedicated vhost per site with a clear document root. Avoid placing multiple apps in one root. Keep permissions sane (directories 755, files 644).

3. Enable rewrite rules intentionally

Most “pretty URLs” are just rewrite rules. Enable mod_rewrite and keep your rules explicit. Avoid catch-all rewrites that hide real 404s.

RewriteEngine On RewriteBase / RewriteRule ^lamp-tutorials$ tutorials.html [L] RewriteRule ^tutorials/why-no-frameworks$ tutorial-single.html [L]

4. Harden MySQL

  • Run the secure install routine
  • Use dedicated DB users per application
  • Grant the minimum privileges required
  • Disable remote root login

5. Logging and error handling

Log errors to disk. Don’t leak stack traces to users. Treat logs like sensitive data and block them from the public web.

Once this baseline works, you can add performance layers (Opcache tuning, caching headers, CDN), but the foundation should remain clean.