Step 3: Update Your System
Before installing LAMP, ensure your system is updated with the latest packages:
apt update && apt upgrade -y
This ensures that your software repositories are current and that all installed packages are up to date.
Step 4: Install Apache Web Server
Apache is the web server component of the LAMP stack, responsible for handling incoming web requests.
Step 4.1: Install Apache
apt-get install apache2 gnupg wget lsb-release
Step 4.2: Start and Enable Apache
systemctl start apache2
systemctl enable apache2
Step 4.3: Verify Apache Status
To confirm that Apache is running correctly, execute:
systemctl status apache2
You can also check if Apache is working by opening your web browser and entering:
http://<your_server_ip>
If Apache is correctly installed, you should see its default welcome page.
Step 5: Install MySQL Database Server
MySQL is the database management system that stores and manages your website’s data.
Step 5.1: Download and Install MySQL Repository
wget https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb
dpkg -i mysql-apt-config_0.8.29-1_all.deb
Step 5.2: Update Packages and Install MySQL
apt update
apt install mysql-server
Step 5.3: Secure MySQL Installation
Run the security script to apply recommended security settings:
mysql_secure_installation
Step 5.4: Start and Enable MySQL
systemctl start mysql
systemctl enable mysql
systemctl status mysql
Step 6: Install PHP
PHP is the programming language that allows your website to display dynamic content.
Step 6.1: Add the PHP Repository
To install the latest PHP version, add the Sury PHP Repository:
apt install -y lsb-release ca-certificates apt-transport-https software-properties-common wget
wget -O /etc/apt/trusted.gpg.d/php-sury.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
Step 6.2: Install PHP and Required Extensions
apt update
apt install php8.3 libapache2-mod-php8.3 php8.3-mysql php8.3-gd php8.3-curl php8.3-xml
Step 6.3: Restart Apache
systemctl restart apache2
Step 6.4: Verify PHP Installation
php --version
This should return the installed PHP version, confirming that it is ready for use.
Step 7: Verify the LAMP Stack
To ensure everything is correctly installed, let’s test PHP processing on the server.
Step 7.1: Create a Test PHP File
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
Step 7.2: Open the PHP Info Page
Go to your browser and visit:
http://<your_server_ip>/info.php
This should display a PHP configuration page, listing all installed modules and settings.
Step 7.3: Remove the Test File
For security reasons, delete the test file once you’ve confirmed that PHP is working:
rm /var/www/html/info.php