LAMP Server Installation Guide on AlmaLinux 8

From Acenet Knowledgebase
Revision as of 17:33, 26 October 2026 by Docs admin (talk | contribs) (New LAMP guide (tested Oct 2026))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This guide shows how to set up a LAMP server (Linux, Apache, MariaDB and PHP) on AlmaLinux 8, so you can host websites without a control panel. When you finish, your server will run:

  • Apache 2.4.37 web server
  • MariaDB 10.11 database server (a drop-in replacement for MySQL)
  • PHP 8.2, run through PHP-FPM
  • A free Let's Encrypt SSL certificate for your website

AlmaLinux 8 receives security updates until 2029. For a new server, we recommend AlmaLinux 10.

The version numbers are from October 2026; regular updates may install newer releases of the same versions.

Before you start

  • A server running a fresh installation of AlmaLinux 8, such as an Acenet cloud server, virtual server or dedicated server, with no control panel installed.
  • Root access over SSH. Run every command in this guide as root, or put sudo in front of it.
  • A domain name whose A record points to your server's IP address, for the website and SSL steps. In this guide, replace example.com with your own domain.

Step 1: Update the server

dnf -y update

If the update installed a new kernel, restart the server with reboot and log in again.

Step 2: Install Apache

dnf -y install httpd
systemctl enable --now httpd

Open http://your-server-ip/ in a browser. You should see the AlmaLinux test page. If the page doesn't load, open the firewall first (step 3).

Step 3: Open the firewall

If firewalld is running (the command below prints active), allow web traffic through it:

systemctl is-active firewalld
firewall-cmd --permanent --add-service=http --add-service=https
firewall-cmd --reload

If you use a different firewall, allow incoming connections on ports 80 (HTTP) and 443 (HTTPS).

Step 4: Install MariaDB

AlmaLinux 8 installs MariaDB 10.3 by default, which is too old. Switch to the MariaDB 10.11 module stream first:

dnf -y module reset mariadb
dnf -y module enable mariadb:10.11

Install MariaDB, start it, and secure it:

dnf -y install mariadb-server
systemctl enable --now mariadb
mariadb-secure-installation

The mariadb-secure-installation script asks a few questions:

  • Enter current password for root: press Enter (there is none yet).
  • Switch to unix_socket authentication and Change the root password: answering n is fine. The database's root user can only log in as the server's root user, through mariadb on the command line, which is secure without a password.
  • Answer Y to remove anonymous users, disallow root login remotely, remove the test database and reload the privilege tables.

Step 5: Install PHP

AlmaLinux 8 installs PHP 7.2 by default, which is too old. Switch to the PHP 8.2 module stream first:

dnf -y module reset php
dnf -y module enable php:8.2

Install PHP with PHP-FPM and the extensions most websites need (for example WordPress), then start PHP-FPM and restart Apache:

dnf -y install php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-opcache php-intl php-pecl-zip
systemctl enable --now php-fpm
systemctl restart httpd
php -v

Apache passes PHP files to PHP-FPM automatically (the configuration is in /etc/httpd/conf.d/php.conf). PHP's curl and JSON support are built in, so there are no separate packages for them.

Step 6: Test PHP

Create a test page:

echo '<?php phpinfo();' > /var/www/html/info.php

Open http://your-server-ip/info.php. You should see the PHP information page showing PHP 8.2 and Server API: FPM/FastCGI. Then delete the test page, because it shows details about your server that visitors shouldn't see:

rm /var/www/html/info.php

Step 7: Create a database and user for your website

Log in to MariaDB as root:

mariadb

Run these commands, replacing the database name, user name and password with your own (use a long, random password):

CREATE DATABASE exampledb;
CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Your website's software connects with these details and host localhost.

Step 8: Set up your website

Each website gets its own folder and its own Apache configuration file (a "virtual host").

1. Create the folder and give it to Apache's user:

mkdir -p /var/www/example.com/public_html
chown -R apache:apache /var/www/example.com

2. Create /etc/httpd/conf.d/example.com.conf:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>

3. Check the configuration and reload Apache:

apachectl configtest
systemctl reload httpd

Upload your website's files to /var/www/example.com/public_html. AllowOverride All lets the website use .htaccess files, which many applications need.

SELinux

AlmaLinux 8 has SELinux turned on. Files in /var/www are already labeled so Apache can read them, but Apache can't write to them. If your website needs to write files (for example uploads or a cache folder), label that folder as writable, replacing the path with your own:

dnf -y install policycoreutils-python-utils
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/example.com/public_html/wp-content(/.*)?"
restorecon -Rv /var/www/example.com/public_html/wp-content

If your website connects to a database or an API on another server, also allow Apache to make network connections:

setsebool -P httpd_can_network_connect 1

Step 9: Add a free SSL certificate

Install Certbot from the EPEL repository, along with Apache's SSL module:

dnf -y install epel-release
dnf -y install certbot python3-certbot-apache mod_ssl
systemctl restart httpd
certbot --apache -d example.com -d www.example.com

The restart creates the default certificate that Apache's SSL module expects. Without it, Certbot stops with an Apache configuration error.

Certbot asks for an email address for renewal notices, gets the certificate, and adds an HTTPS virtual host for your website. When it asks, choose to redirect HTTP to HTTPS.

Let's Encrypt certificates last 90 days. Turn on automatic renewal and test it:

systemctl enable --now certbot-renew.timer
certbot renew --dry-run

Keep your server updated

Install updates regularly, so you get security fixes for Apache, MariaDB, PHP and the operating system:

dnf -y update

To install security updates automatically, you can use dnf-automatic.

Where to find things

Item Location
Apache configuration /etc/httpd/conf/httpd.conf and /etc/httpd/conf.d/
Apache logs /var/log/httpd/
PHP settings /etc/php.ini and /etc/php.d/
PHP-FPM settings and log /etc/php-fpm.d/www.conf and /var/log/php-fpm/
MariaDB settings /etc/my.cnf.d/
Restart a service systemctl restart httpd (or php-fpm, or mariadb)

If you have any questions, please open a support ticket from your client area.