Skip to content

Install a LAMP stack on your VPS

Updated 3 min read

Updated: 11 October 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

A LAMP stack (Linux, Apache, MariaDB, PHP) runs most PHP websites. These steps work on a Ucartz VPS with Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.

Before you start

  • A VPS or dedicated server with a fresh Ubuntu 24.04 / Debian 12 or AlmaLinux 9 / Rocky Linux 9 installation, and root or sudo access.
  • A domain or subdomain pointing to the server (an A record), if you want HTTPS.
  • The system updated: apt update && apt upgrade or dnf upgrade.

Install Apache, MariaDB and PHP

Ubuntu 24.04 / Debian 12:

apt install apache2 mariadb-server php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-zip php-gd php-intl
systemctl enable --now apache2 mariadb

AlmaLinux 9 / Rocky Linux 9 (choose a current PHP stream first):

dnf module reset php && dnf module enable php:8.3
dnf install httpd mariadb-server php php-fpm php-mysqlnd php-xml php-mbstring php-gd php-intl php-opcache php-pecl-zip
systemctl enable --now httpd mariadb php-fpm

Secure MariaDB (set a root password or keep socket login, remove test data): mariadb-secure-installation.

Open the firewall

ufw allow 80,443/tcp                                   # Ubuntu / Debian with UFW
firewall-cmd --permanent --add-service=http --add-service=https && firewall-cmd --reload   # AlmaLinux / Rocky

Create a database

mariadb -u root -p
CREATE DATABASE site CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'siteuser'@'localhost' IDENTIFIED BY 'Strong-Password';
GRANT ALL PRIVILEGES ON site.* TO 'siteuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

The web server user is www-data on Ubuntu/Debian and apache (or nginx) on AlmaLinux/Rocky.

Create the Apache site

Create /etc/apache2/sites-available/example.com.conf (Ubuntu/Debian) or /etc/httpd/conf.d/example.com.conf (AlmaLinux/Rocky):

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/app
    <Directory /var/www/app>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Ubuntu/Debian: a2ensite example.com && a2enmod rewrite && systemctl reload apache2. AlmaLinux/Rocky: apachectl configtest && systemctl reload httpd.

Add a free SSL certificate

apt install certbot python3-certbot-apache                     # Ubuntu / Debian
dnf install epel-release && dnf install certbot python3-certbot-apache   # AlmaLinux / Rocky
certbot --apache -d example.com -d www.example.com

Certbot installs a timer that renews the certificate automatically; test it with certbot renew --dry-run.

Keep it secure

  • Install updates regularly (apt upgrade / dnf upgrade).
  • Use a separate database user for each site.
  • Set files to 644 and folders to 755.

Prefer not to do it yourself? Our engineers can set this up on your Ucartz VPS or dedicated server as a paid task.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket