How to Install LAMP Stack on Ubuntu
A complete step-by-step guide to installing Apache, MySQL and PHP on Ubuntu — including a one-shot installation command and a fix for the common php-opcache package error.
The LAMP stack is one of the most popular environments for hosting PHP applications on Linux. It combines Linux, Apache, MySQL and PHP into a complete web application platform.
Whether you're building a WordPress website, Laravel application, PHP API or simply creating a local development environment, installing LAMP gives you everything you need to get started.
What Does LAMP Stand For?
Linux
The operating system powering the server.
Apache
Handles HTTP requests and serves web pages.
MySQL
Stores and manages application data.
PHP
Processes dynamic server-side application code.
How the LAMP Stack Works
A typical request flows through the stack like this:
Install LAMP on Ubuntu
First update your Ubuntu package index:
sudo apt update
Install Apache, MySQL and PHP
You can install the complete LAMP environment with the following command:
sudo apt install -y apache2 mysql-server php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip php-bcmath php-intl php-soap
Start Apache and MySQL
Enable both services so they start automatically with Ubuntu:
sudo systemctl enable --now apache2 mysql
Enable Apache URL Rewriting
The Apache rewrite module is commonly required by modern PHP applications and frameworks such as Laravel.
sudo a2enmod rewrite
sudo systemctl restart apache2
