Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install a LAMP Stack on Ubuntu

Install Linux, Apache, MySQL and PHP on Ubuntu, and test that they work together.

VPS and Cloud Servers2 min read4 screenshots

What LAMP is

LAMP is a set of free software for web servers: Linux, Apache, MySQL (or MariaDB) and PHP. It runs many websites, including WordPress.

Note: The steps work on all current Ubuntu LTS releases. The original guide was written for Ubuntu 18.04, which is no longer supported. Use a supported version.

Requirements

  • An Ubuntu LTS server.
  • A non-root user with sudo rights.
  • An internet connection.

Step 1: Install Apache

Installing Apache

Update the package list and install Apache:

sudo apt update
sudo apt install apache2

Start it and make it start at boot:

sudo systemctl enable apache2
sudo systemctl start apache2

Check that it runs:

sudo systemctl status apache2

You should see active (running).

Test Apache. Open http://your_server_ip in your browser. The Apache default page appears. If you use UFW, allow web traffic first: sudo ufw allow "Apache Full".

Step 2: Install MySQL

Installing MySQL
sudo apt install mysql-server

The service starts by itself. Run the security script:

sudo mysql_secure_installation

It asks you to set a password policy, remove anonymous users, disallow remote root login and remove the test database. Say yes to the questions that you understand.

The MySQL secure installation

Log in to check it:

sudo mysql

Leave with exit.

Step 3: Install PHP

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

Restart Apache:

sudo systemctl restart apache2

Check the PHP version:

php -v

Step 4: Test PHP

Create a test file:

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

Add:

<?php
phpinfo();
?>

Open http://your_server_ip/info.php. You should see the PHP information page. Delete the file after the test:

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

Next steps

  • Create a database and a user for your site.
  • Set up an Apache virtual host for each domain.
  • Add an SSL certificate with Let's Encrypt (sudo certbot --apache).

Quick recap

  • apache2, mysql-server and php libapache2-mod-php php-mysql make the stack.
  • Run mysql_secure_installation.
  • Test with a phpinfo() page and delete it afterwards.