cPanel & WHM Tutorials

How to Set Up LAMP Stack on Ubuntu Server

How to Set Up LAMP Stack on Ubuntu Server

When it comes to hosting dynamic websites and applications, one of the most popular and reliable environments is the LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP, and together, these components create a solid foundation for web development and hosting.

In this guide, we’ll walk you through setting up a LAMP stack on Ubuntu Server, step by step.

What is LAMP Stack?

  • Linux – The operating system (we’ll use Ubuntu).
  • Apache – The web server that serves your website content.
  • MySQL/MariaDB – The database system to store application data.
  • PHP – The scripting language that makes websites dynamic and interactive.

Step 1: Update Your Server

Before installing anything, update your system to ensure all packages are current:

sudo apt update && sudo apt upgrade -y

Step 2: Install Apache Web Server

Apache is the most widely used web server software. Install it with:

sudo apt install apache2 -y

Enable Apache to start on boot:

sudo systemctl enable apache2
sudo systemctl start apache2

Test Apache by visiting your server’s IP address in a browser:

http://your-server-ip

You should see the default Apache welcome page.

Step 3: Install MySQL Database Server

Next, install MySQL (or MariaDB if you prefer):

sudo apt install mysql-server -y

Run the security script to secure your database installation:

sudo mysql_secure_installation

This will prompt you to set a root password, remove test databases, and disable remote root login.

Log in to MySQL to test:

sudo mysql -u root -p

Step 4: Install PHP

PHP is required for dynamic websites like WordPress. Install PHP and common extensions:

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

Check the installed PHP version:

php -v

Step 5: Test PHP Processing

Create a test PHP file to confirm Apache and PHP are working together.

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

Add this line:

<?php
phpinfo();
?>

Save and exit. Now visit:

http://your-server-ip/info.php

You should see the PHP info page with details about your PHP installation.

Step 6: Adjust Firewall (Optional)

If you are running UFW firewall, allow Apache traffic:

sudo ufw allow in "Apache Full"

Step 7: Remove the PHP Info File

Since info.php contains sensitive server details, delete it after testing:

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

Step 8: Verify LAMP Stack

At this point, your Ubuntu server should have:
✅ Apache serving web pages
✅ MySQL storing your data
✅ PHP processing scripts

Your LAMP stack is ready for hosting apps like WordPress, Joomla, or custom PHP websites.

Conclusion

The LAMP stack is one of the most reliable, cost-effective, and widely supported hosting environments. Whether you’re deploying a personal website or a full enterprise application, LAMP provides the scalability and flexibility you need.

At Vicservers, we help businesses deploy secure and optimized LAMP hosting environments. With our VPS and dedicated server solutions, you get performance, security, and support all in one place.

Ready to launch your project? Contact Vicservers today for reliable hosting solutions tailored to your needs.

 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button