How to install LAMP stack on Ubuntu

The LAMP stack, an acronym for Linux, Apache, MySQL, and PHP/Python/Perl, is a tried-and-true solution that powers a significant portion of the internet. In this guide, we will walk you through the process of installing the LAMP stack on the latest Ubuntu 23, ensuring a seamless setup for your web development endeavors.

Why LAMP Stack?

Before we dive into the installation process, let’s briefly understand why the LAMP stack is a go-to choice for many developers. Combining the stability of Linux, the versatility of the Apache web server, the reliability of MySQL as a database management system, and the flexibility of PHP/Python/Perl for server-side scripting, the LAMP stack provides a comprehensive and scalable foundation for hosting dynamic web applications.

Step 1: Update Your System

Ensure your Ubuntu 23 system is up to date by executing the following commands in the terminal:

sudo apt update && apt upgrade
How to install LAMP stack on Ubuntu

Updating your system guarantees that you have the latest security patches and software updates.

Step 2: Install Apache Web Server

Apache is a widely used and highly configurable web server. Install it with the following command:

sudo apt install apache2
Install Apache Web Server

Once the installation is complete, start the Apache service and enable it to start on boot:

sudo systemctl start apache2
sudo systemctl enable apache2

Step 3: Install MySQL Database Server

MySQL is a powerful and popular relational database management system. Install it with the following command:

sudo apt install mysql-server
Install MySQL Database Server

Secure your MySQL installation with the following command:

Follow the on-screen prompts to configure security options for MySQL.

Step 4: Install PHP

PHP is a server-side scripting language that works seamlessly with the LAMP stack. Install PHP along with necessary modules:

sudo apt install php libapache2-mod-php php-mysql php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc
Install PHP ubuntu

After the installation, restart the Apache service for the changes to take effect:

sudo systemctl restart apache2

Step 5: Test Your LAMP Stack

Create a simple PHP file to test your LAMP stack. Use the following command to create a test file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Visit http://your_server_ip/info.php in your web browser, and you should see a page displaying PHP configuration information.

Test Your LAMP Stack

Congratulations! You’ve successfully installed the LAMP stack on Ubuntu 23. This powerful combination of Linux, Apache, MySQL, and PHP/Python/Perl provides a solid foundation for hosting dynamic web applications. As you embark on your web development journey, leverage the capabilities of the LAMP stack to create and deploy robust websites and applications. Happy coding!