How to Set Up a LAMP Stack on Fedora
A LAMP stack combines Linux, Apache, MariaDB or MySQL, and PHP to serve dynamic websites. Fedora provides current packages and sensible security defaults, making it a practical choice for a development server, a small office application, or a public-facing host.
These instructions use Fedora’s dnf package manager, the Apache httpd service, MariaDB, PHP, firewalld, and SELinux. The same workflow suits an administrator working from Sydney, Melbourne, Brisbane, or Perth, although production servers should use a fixed hostname, reliable backups, and a proper domain rather than relying on a desktop workstation.
Update Fedora And Install Packages
Start by updating the operating system and installing the web server, database server, PHP interpreter, and common PHP extensions:
sudo dnf upgrade --refresh -y
sudo dnf install -y httpd mariadb-server php php-mysqlnd php-fpm php-cli php-json php-mbstring
Enable Apache and MariaDB so they start during boot, then launch them immediately:
sudo systemctl enable --now httpd
sudo systemctl enable --now mariadb
sudo systemctl enable --now php-fpm
Check their current state before continuing:
systemctl status httpd mariadb php-fpm
On a home lab connected through the NBN, the server may receive a changing private address from the router. For reliable testing, either reserve an address in DHCP or use hostname -I to identify the current address.
Configure The MariaDB Database
MariaDB stores application data such as users, posts, orders, and sessions. Run its hardening script and follow the prompts to remove anonymous accounts, disable remote root access, delete the test database, and reload privilege tables:
sudo mariadb-secure-installation
Log in locally as the administrative database user:
sudo mariadb
Create a database and a restricted account for a sample PHP application. Replace the password with a long, unique value:
CREATE DATABASE lampapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'lampuser'@'localhost' IDENTIFIED BY 'Use-A-Long-Random-Password';
GRANT ALL PRIVILEGES ON lampapp.* TO 'lampuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
The application account should own only its application database. This is safer than using MariaDB’s root account from PHP, particularly for a small Australian business site handling customer records or local bookings.
Enable PHP Processing In Apache
Apache serves static files from /var/www/html. Create a simple PHP script to confirm that the web server passes .php files to the PHP module:
echo '<?php phpinfo();' | sudo tee /var/www/html/info.php
sudo chown apache:apache /var/www/html/info.php
sudo chmod 640 /var/www/html/info.php
Find the server’s address and open http://SERVER_IP/info.php in a browser. The page should display PHP’s version, enabled modules, and configuration. Remove this file after testing because it exposes information that can help an attacker:
sudo rm -f /var/www/html/info.php
For a real virtual host, create a directory and configuration file rather than placing every website in the default document root:
sudo mkdir -p /var/www/example.com/public
sudo chown -R apache:apache /var/www/example.com
A domain registered under .com.au may need DNS records managed through an Australian registrar, and DNS changes can take time to appear across providers. Use the real domain only after its A or AAAA records point to the server.
Open HTTP And HTTPS In Firewalld
Fedora normally runs firewalld, so allow web traffic through the active zone:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
Do not open MariaDB’s port 3306 to the internet unless there is a specific, controlled requirement. Applications on the same machine can connect through localhost, avoiding exposure of the database service.
If the site is hosted in an Australian data centre, check the provider’s network firewall as well as the operating system firewall. A cloud security group can block traffic even when firewall-cmd reports the correct services.
Work With SELinux Rather Than Disabling It
SELinux is an important Fedora security control. Keep it enabled and inspect its state with:
getenforce
Files served by Apache should have the correct SELinux context. If content is copied into a new document root, restore its labels:
sudo restorecon -Rv /var/www/example.com
If a PHP application must write uploads or cache files, label only the required directory:
sudo mkdir -p /var/www/example.com/public/uploads
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/example.com/public/uploads(/.*)?'
sudo restorecon -Rv /var/www/example.com/public/uploads
When a request fails unexpectedly, inspect recent denials rather than switching SELinux off:
sudo ausearch -m AVC -ts recent
This approach keeps the server aligned with Fedora’s security model and makes later troubleshooting clearer.
Test The Stack And Monitor Resources
Test Apache locally with curl:
curl -I http://127.0.0.1
You can also create a small database connection script, but remove it once validation is complete. For browser-based checks from outside the server, a simple web test can confirm that DNS, HTTP responses, and page availability work from an external network.
Review service logs when diagnosing errors:
sudo journalctl -u httpd -e
sudo journalctl -u mariadb -e
sudo tail -f /var/log/httpd/error_log
A busy PHP site can consume memory quickly. Check usage with free -h, top, or systemctl status php-fpm; administrators managing several services can also review cgroup resource controls to limit CPU and memory consumption. This matters when a Brisbane office server shares resources with backups, monitoring, and internal applications.
Remember that Australian time zones vary: Sydney and Melbourne switch between AEST and AEDT, while Queensland stays on AEST and Perth uses AWST. Set the correct timezone for logs and scheduled jobs:
sudo timedatectl set-timezone Australia/Sydney
timedatectl
A working Fedora LAMP stack has Apache serving requests, PHP executing safely, MariaDB restricted to trusted access, firewalld permitting only required traffic, and SELinux enforcing sensible labels. Keep packages updated, remove diagnostic files, monitor logs and resource usage, and remember that secure defaults are part of the setup rather than an optional extra.