Logo Logo
Back to list
Linux

Complete LAMP Stack Installation (Apache, PHP, and MySQL) on Linux

14. 03. 2026
Complete LAMP Stack Installation (Apache, PHP, and MySQL) on Linux

To set up a development environment on Linux, we need three key components: the Apache web server, a database (MySQL or MariaDB), and the PHP programming language. Below is a guide for installation and proper configuration to ensure everything works in harmony.

Basic Installation

  1. Update the system:
    sudo apt update && sudo apt upgrade
  2. Install the Apache server:
    sudo apt install apache2
  3. Install PHP and the Apache module:
    sudo apt install php libapache2-mod-php php-mysql
  4. Install MySQL or MariaDB server:
    sudo apt install mysql-server
    sudo apt install mariadb-server
  5. Secure the database installation:
    sudo mysql_secure_installation

Verify the installation locally by visiting: http://localhost

Configuration for PHPStorm

When using PHPStorm, you need to set the path to the PHP interpreter. On Linux, the path is: /usr/bin/php

Installing the Latest PHP 8.3 Version

To use the latest stable version, use the PPA repository:

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3 libapache2-mod-php8.3 php8.3-cli php8.3-mysql php8.3-curl php8.3-xml php8.3-mbstring

Switching Between PHP Versions

First, set the PHP version for the terminal (CLI):

sudo update-alternatives --config php
sudo update-alternatives --set php /usr/bin/php8.3

Then, instruct Apache to use the correct module so that your website runs on the same version as the terminal:

sudo a2dismod php8.1  # Disable the old version (e.g., 8.1)
sudo a2enmod php8.3   # Enable the new version 8.3
sudo systemctl restart apache2

Hvala za obisk! Dodajam politiko zasebnosti.

© 2024 Vse pravice pridržane.

Vam je koda pomagala? Če želite podpreti moj trud pri pripravi vodičev in vzdrževanju strani, mi lahko namenite donacijo za kavo.