Setting Up A LAMP Stack On Fedora 40
A LAMP stack combines Linux, Apache, MariaDB and PHP to provide a practical platform for dynamic websites. On Fedora 40, the process uses dnf, systemctl, firewalld and SELinux, giving administrators a useful introduction to the tools found on many Red Hat-based servers.
This guide builds a working web server suitable for a development machine, home lab or small virtual private server. A Sydney-based VPS can provide lower latency for Australian visitors, while a local Fedora installation connected through NBN is convenient for testing before deployment.
Prepare Fedora And Update Packages
Start by applying available updates and checking the server’s hostname and network address. Running administrative commands through sudo is preferable to logging in directly as root.
sudo dnf update -y
hostnamectl
ip addr
Fedora 40 is an older Fedora release, so it should be used for compatibility practice or an existing environment. For a new production system, choose a currently supported Fedora version and apply the same package and service principles. Set the correct time zone for the deployment location, such as Australia/Sydney, remembering that Australian eastern states switch between AEST and AEDT.
sudo timedatectl set-timezone Australia/Sydney
timedatectl
A server exposed to the internet should have a static address or stable DNS record. If you publish a personal project using an Australian .com.au domain, confirm that the domain’s DNS record points to the server before testing the site.
Install Apache MariaDB And PHP
Install the core LAMP packages with one command. php-fpm provides the PHP FastCGI process manager, while php-mysqlnd allows PHP applications to communicate with MariaDB.
sudo dnf install -y httpd mariadb-server php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-json
Enable and start the services, then verify their status:
sudo systemctl enable --now httpd
sudo systemctl enable --now mariadb
sudo systemctl enable --now php-fpm
systemctl --no-pager --full status httpd
systemctl --no-pager --full status mariadb
Apache serves files from /var/www/html by default. Create a simple page to confirm that HTTP requests reach the server.
echo '<h1>Fedora web server is running</h1>' | sudo tee /var/www/html/index.html
Configure Firewall And SELinux
Fedora normally uses firewalld to control incoming connections. Permit web traffic permanently, then reload the firewall rules.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
Avoid opening MariaDB’s port, 3306, to the public internet. Applications running on the same server can connect through the local system, and remote database administration should use a controlled VPN or SSH tunnel.
SELinux usually permits Apache to read content under /var/www/html. If an application needs to write uploads or cache files, assign an appropriate writable context rather than disabling SELinux.
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/uploads(/.*)?'
sudo restorecon -Rv /var/www/html/uploads
If semanage is unavailable, install the management utilities with sudo dnf install -y policycoreutils-python-utils. The correct security context matters on Fedora, particularly when an application appears to have normal Unix permissions but still receives “permission denied” errors.
Secure MariaDB And Create A Database
Run the MariaDB security script to remove anonymous accounts, restrict remote root access and delete the test database.
sudo mariadb-secure-installation
The exact prompts can vary by MariaDB version. Set a strong administrative credential, remove anonymous users, prevent remote root login and reload the privilege tables when prompted.
Create a separate database and user for each application instead of allowing a web application to use the MariaDB root account.
sudo mariadb
Inside the MariaDB prompt:
CREATE DATABASE site_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'site_user'@'localhost' IDENTIFIED BY 'Use-a-long-unique-password';
GRANT ALL PRIVILEGES ON site_db.* TO 'site_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Store credentials outside publicly readable files where possible. For a small Australian business website hosted in Melbourne or Brisbane, regular database backups are as important as the initial installation, especially when customer records or orders are involved.
Test PHP And Apache Integration
Create a temporary PHP diagnostic page to verify that Apache passes .php files to PHP correctly.
echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php
Open http://server-address/info.php from a browser, replacing server-address with the server’s IP address or DNS name. Confirm that PHP is enabled and that the MySQL extension appears in the displayed modules.
Remove the diagnostic file immediately after testing because it exposes configuration details:
sudo rm -f /var/www/html/info.php
For a more realistic test, create a small database connection script and keep it outside the web root when possible. Check Apache logs while testing requests:
sudo tail -f /var/log/httpd/access_log /var/log/httpd/error_log
If a tutorial or configuration example is reused, review the site’s copyright policy before copying substantial material into internal documentation or a published project.
Troubleshoot Services And Plan Maintenance
A blank page, refused connection or failed PHP request usually leaves clues in service status output and logs. Use these commands to inspect recent failures:
sudo systemctl status httpd php-fpm mariadb
sudo journalctl -u httpd -u php-fpm -u mariadb --since "30 minutes ago"
Check that Apache is listening and that firewalld contains the required services:
sudo ss -tulpn | grep -E ':(80|443|3306)\b'
sudo firewall-cmd --list-all
For a production deployment, add HTTPS with a trusted certificate, configure Apache virtual hosts, schedule MariaDB dumps and monitor disk space. Australian users may access a site across several time zones, so log timestamps and backup schedules should be documented clearly in UTC or in the server’s configured local zone.
When an installation issue cannot be resolved from service logs, configuration files and SELinux audit messages, the contact the team page provides a suitable route for site-related enquiries.
A functional LAMP server is more than four installed packages: Apache must serve requests, PHP must execute safely, MariaDB must use restricted credentials, and firewalld and SELinux must enforce sensible boundaries. The key point to remember is that reliable web hosting comes from verifying every layer, securing it, and maintaining it after the first successful page appears.