Customer Support

  1. Support
  2. VPS
  3. VPS – How to install LAMP Stack in Ubuntu
  1. Home
  2. Knowledge Base
  3. VPS
  4. VPS – How to install LAMP Stack in Ubuntu

VPS – How to install LAMP Stack in Ubuntu

What is LAMP?

The LAMP stack is a popular combination of open-source software that allows you to host dynamic websites and web applications. It consists of:

  • Linux – the operating system
  • Apache – the web server
  • MySQL – the database management system
  • PHP – the programming language for dynamic content

Step 1: Update your repositories

Before you begin, make sure all your system packages are up to date:

sudo apt update
sudo apt upgrade


Step 2: Install Apache

Apache is one of the most widely used web servers. To install it, run:

sudo apt install apache2

Once the installation is complete, verify that the service is running:

sudo systemctl status apache2

Open your browser and visit:

http://your_server_ip

If everything is working correctly, you’ll see Apache’s default “It works!” page.


Step 3: Install MySQL

MySQL allows you to store and manage data for your website:

sudo apt install mysql-server

After installation, run the MySQL security setup wizard:

sudo mysql_secure_installation

You’ll be prompted to configure the root password, remove anonymous users, and disable remote root login.
It’s recommended to answer “Yes” to all security prompts.

To access the MySQL shell:

sudo mysql

To exit:

exit


Step 4: Install PHP

PHP enables your server to display dynamic content. To install it:

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

To check your PHP version:

php -v


Step 5: Test PHP with Apache

Create a test file named info.php in the Apache web root directory:

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

Add the following code:

<?php
phpinfo();
?>

Save and close the file, then open in your browser:

http://your_server_ip/info.php

You should see a page displaying detailed PHP configuration information.
When you’re done, delete the file for security reasons:

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


Optional: Enable additional PHP modules

Depending on your application’s requirements, you may need to install extra PHP modules.
List all available modules with:

apt search php-

For example, to install the PHP CLI module:

sudo apt install php-cli


Completion

You have successfully installed the LAMP stack on your Ubuntu server.
Your system is now ready to host PHP-based applications such as WordPress, Drupal, or custom-built solutions.

Make sure to regularly update your packages and take backups to maintain a secure and stable environment.


You haven't found what you are looking for?

Contact our experts, they will be happy to help!

Contact us