How to Install LAMP Stack on Ubuntu 24.04

The LAMP Stack (Linux, Apache, MySQL/MariaDB, PHP) is a powerful platform for hosting dynamic websites and web applications. Below are the steps to install and configure the LAMP stack on Ubuntu 24.04.



Step 1: Update System Packages

Start by updating the package lists to ensure your system has the latest updates. Open a terminal and run:

sudo apt update && sudo apt upgrade -y

Step 2: Install Apache Web Server

Apache is the web server for serving your website content. Install it using:

sudo apt install apache2 -y

Once installed, enable and start the Apache service:

sudo systemctl enable apache2 sudo systemctl start apache2

To check if Apache is running, open your web browser and navigate to http://your-server-ip. You should see the default Apache page.


Step 3: Install MySQL or MariaDB

For managing databases, you can choose between MySQL or MariaDB. Install MySQL by running:

sudo apt install mysql-server -y

Secure the installation with:

sudo mysql_secure_installation

Follow the prompts to set up the root password and enhance security.

To log in to the MySQL shell, run:

sudo mysql -u root -p

For MariaDB, use this command instead:

sudo apt install mariadb-server mariadb-client -y

Step 4: Install PHP

PHP is the server-side scripting language. Install PHP and the necessary modules with:

sudo apt install php libapache2-mod-php php-mysql -y

To test PHP, create a test file in /var/www/html:

sudo nano /var/www/html/info.php

Add the following content:

<?php phpinfo(); ?>

Save the file and access it in a browser: http://your-server-ip/info.php. If you see the PHP info page, PHP is working correctly.


Step 5: Adjust Firewall Settings

Ensure your firewall allows HTTP and HTTPS traffic:

sudo ufw allow in "Apache Full" sudo ufw enable

Check the status of the firewall with:

sudo ufw status

Step 6: Test the LAMP Stack

  • Apache: Visit http://your-server-ip.
  • MySQL: Use the command line or a tool like phpMyAdmin to verify database access.
  • PHP: Visit http://your-server-ip/info.php.

Step 7: Optional: Install phpMyAdmin

If you prefer a graphical interface for managing databases, install phpMyAdmin:

sudo apt install phpmyadmin -y

During installation, select Apache and configure the database with the prompts. Access phpMyAdmin at http://your-server-ip/phpmyadmin.


Conclusion

You now have a fully functional LAMP stack on Ubuntu 24.04. This setup is perfect for hosting websites, running CMS platforms like WordPress, or deploying custom web applications.

For further configuration, consider securing your Apache and MySQL services and optimizing PHP for performance.

মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

২০২৫ সালের শীর্ষ ৫টি এআই টুল যা আপনার জানা অত্যন্ত জরুরি!

১৫,০০০ টাকায় সেরা ৫টি অ্যান্ড্রয়েড স্মার্টফোন

২০২৫ সালে অ্যান্ড্রয়েডের জন্য ১০টি অত্যন্ত দরকারি অ্যাপ