NewHalo Edge 3 is here: HTTP/3 everywhere and 42 edge locations.Learn more
Docs / LAMP and app hosting

Install a LAMP stack

LAMP and app hosting10 min readUbuntu 24.04 LTS

LAMP stands for Linux, Apache, MariaDB and PHP, a classic combination for running PHP websites. This guide installs all four on a fresh Ubuntu 24.04 VPS and checks that each part works.

Before you begin

  • A fresh VPS running Ubuntu 24.04 LTS with a public IP, for example 203.0.113.10.
  • SSH access as a user with sudo rights (this guide uses alex).
  • Optional: a domain name pointed at the VPS. You can test everything by IP address first.

Step 1: Update the system

Start with an up-to-date package list and installed packages. This avoids old versions and known bugs.

sudo apt update
sudo apt upgrade -y

Step 2: Install and open up Apache

Apache is the web server. It receives requests from visitors and hands PHP files to PHP. Install it, then allow HTTP and HTTPS through the firewall. The Apache Full profile opens ports 80 and 443.

sudo apt install -y apache2
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable

Confirm that Apache answers on the server itself:

curl -I http://localhost
HTTP/1.1 200 OK
Server: Apache/2.4.58 (Ubuntu)
Careful: Allow OpenSSH before ufw enable, or the firewall may block your SSH session.

Step 3: Install MariaDB

MariaDB is the database server, a drop-in relative of MySQL. Install it and check that it is running. The next guide, Secure your MariaDB installation, hardens it.

sudo apt install -y mariadb-server
sudo systemctl status mariadb --no-pager
Active: active (running)

Step 4: Install PHP

PHP runs your application code. The libapache2-mod-php8.3 package connects PHP to Apache. The other packages add extensions that most PHP applications need: mysql lets PHP talk to MariaDB, and the rest handle HTTP requests, images, multibyte text and archives.

sudo apt install -y php8.3 libapache2-mod-php8.3 php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip
sudo systemctl restart apache2

Check the PHP version:

php -v
PHP 8.3.6 (cli) (built: ...)
Copyright (c) The PHP Group

Step 5: Enable Apache's rewrite module

Many PHP applications use "pretty" URLs such as /about/team, which need Apache's rewrite module. Enable it now so you do not have to troubleshoot it later.

sudo a2enmod rewrite
sudo systemctl restart apache2
Enabling module rewrite.
To activate the new configuration, you need to run:
  systemctl restart apache2

Step 6: Check that PHP runs through Apache

Create a small test file in the web root. It calls phpinfo(), which prints PHP's settings.

sudo nano /var/www/html/info.php
<?php phpinfo(); ?>

Open http://203.0.113.10/info.php in a browser. If you see a page titled "PHP Version 8.3", PHP and Apache are working together. Then delete the file:

sudo rm /var/www/html/info.php
Careful: The phpinfo page reveals details about your server. Never leave it online.

Troubleshooting

  • The info page downloads as a file or shows raw code. The PHP module is not loaded. Confirm that libapache2-mod-php8.3 is installed, then run sudo systemctl restart apache2.
  • Apache logs "Could not reliably determine the server's fully qualified domain name". This message is harmless. To silence it, create /etc/apache2/conf-available/servername.conf containing ServerName example.com, then run sudo a2enconf servername and reload Apache.
  • MariaDB will not start. Read the last log lines with sudo journalctl -u mariadb -n 50 --no-pager.
  • The site does not load from your computer. Check the firewall with sudo ufw status. The "Apache Full" rule should appear.

Next steps

Secure the database with Secure your MariaDB installation, then create a database for your application with Create a database and a dedicated user. If you prefer nginx to Apache, the Install a LEMP stack guide covers the same components with a different web server.

Something not working? Chat or email our support team and we will help you get unstuck.

Contact support