A LAMP stack (Linux, Apache, MySQL/MariaDB, PHP with 7.4) is a popular open-source web development platform. Here's a step-by-step guide to installing a LAMP stack on Ubuntu 22.04 or 24.04.
Prerequisites
Ensure your system is up to date:
sudo apt update && sudo apt upgrade -y
Step 1: Install Essential Packages
Install the necessary packages for adding repositories and handling files:
sudo apt -y install software-properties-common dirmngr file-roller unzip wget gnupg2 git curl vim tmux
Step 2: Add PHP Repository
Add the Ondřej Surý PHP PPA repository:
sudo add-apt-repository ppa:ondrej/php
Step 3: Update Package List
Update your package list to include the new repository:
sudo apt update
Step 4: Install Apache, MariaDB, and PHP
Install Apache, MariaDB, and PHP 7.4:
sudo apt install -y apache2 mariadb-server php7.4
Step 5: Install PHP Extensions
Install the necessary PHP extensions:
sudo apt install -y libapache2-mod-php7.4 php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,cli,fpm,opcache,xml,curl,xsl,soap,json,apcu,imap,xmlrpc}
Step 6: Configure PHP
Adjust PHP settings for better performance and larger uploads:
sudo sed -i "s/memory_limit = .*/memory_limit = 1024M/; s/upload_max_filesize = .*/upload_max_filesize = 256M/; s/post_max_size = .*/post_max_size = 296M/; s/session.gc_maxlifetime = .*/session.gc_maxlifetime = 7200/; s/max_execution_time = .*/max_execution_time = 18000/; s/;date.timezone.*/date.timezone = UTC/; s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/7.4/apache2/php.ini
Step 7: Restart Apache
Reload and restart Apache to apply the changes:
sudo systemctl reload apache2 && sudo systemctl restart apache2