How to Create and Configure a Full LAMP Stack on Ubuntu

Learn how to set up a LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu. This guide covers all the necessary steps to configure the server for web hosting and developing dynamic websites.

← Back

Step 1: Update Your System

First, update the package index to ensure all your system’s software is up to date:

sudo apt update && apt upgrade -y

Step 2: Install Apache Web Server

Next, install the Apache web server to serve web pages:

sudo apt install apache2 -y

To check Apache is running, visit your server's IP address:

http://your_server_ip

Step 3: Install MySQL (or MariaDB)

Install MySQL for your database management:

sudo apt install mysql-server -y

Secure your MySQL installation by running:

sudo mysql_secure_installation

Follow the prompts to secure your database.

Step 4: Install PHP and PHP Modules

Install PHP and the necessary PHP modules to interact with Apache and MySQL:

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

Step 5: Test PHP Processing

Create a test PHP file to verify PHP is running:

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

Then visit:

http://your_server_ip/info.php

After confirming PHP is working, remove the test file:

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

Step 6: Install Additional PHP Modules (Optional)

If needed, install additional PHP modules for more functionality:

sudo apt install php-cli php-curl php-gd php-mbstring php-xml php-zip -y

Conclusion

You've successfully created and configured a LAMP stack on your Ubuntu server! This setup is ideal for hosting dynamic websites, content management systems like WordPress, and frameworks such as Laravel.

← Back