Installing LAMP Stack on Fedora Server: Apache, MariaDB, and PHP 8.3

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

Why Choose LAMP on Fedora?

After two years of using Fedora as my primary development environment, I am truly impressed by its package update speed. Unlike the “stodgy” stability of CentOS or RHEL, Fedora always prioritizes the latest versions. When installing LAMP on Fedora, you get PHP 8.2 or 8.3 directly from the official repositories. You won’t need to mess around with third-party repos like Remi unless absolutely necessary.

For Junior developers, Fedora is an excellent “trial by fire” environment. It forces us to work seriously with SELinux and firewalld. Instead of disabling them to avoid trouble, understanding and configuring them correctly will take your server administration skills to the next level.

Components of the LAMP Stack

Before we start typing commands, let’s look at the four pieces we’ll be assembling:

  • Linux: The Fedora Server OS (I’m using version 39/40).
  • Apache (httpd): The go-to web server, extremely powerful and highly customizable.
  • MariaDB: An open-source fork of MySQL, high-performance and completely free.
  • PHP 8: The backend processing language, the backbone of CMS platforms like WordPress or Laravel.

Step 1: Installing Apache and Opening Firewall Ports

On Fedora, Apache is referred to as httpd. First, update your system to ensure everything is up to date:

sudo dnf update -y
sudo dnf install httpd -y

Once installed, you need to enable Apache to start automatically whenever the server boots:

sudo systemctl enable --now httpd

At this point, if you access the server’s IP, you’ll see a connection error. This is because firewalld is blocking ports 80 (HTTP) and 443 (HTTPS). Open them using these two commands:

sudo firewall-cmd --permanent --add-service={http,https}
sudo firewall-cmd --reload

Now, try entering your server’s IP into a browser. If the Fedora welcome page appears, you’ve cleared the first hurdle.

Step 2: Installing MariaDB and Hardening Security

For the database, MariaDB is a perfect drop-in replacement for MySQL. Installation is straightforward:

sudo dnf install mariadb-server -y
sudo systemctl enable --now mariadb

By default, MariaDB has no root password and several security vulnerabilities. You must not skip running this security script:

sudo mysql_secure_installation

The system will ask several confirmation questions. My advice: Choose ‘Y’ (Yes) for all of them. This will help you set a root password, remove anonymous users, and disallow remote root login.

Step 3: Installing PHP 8.x and Supplementary Modules

Fedora provides PHP updates very quickly. You should install PHP along with common modules for image processing and smooth database connectivity:

sudo dnf install php php-common php-mysqlnd php-gd php-xml php-mbstring -y

Verify your progress with the command:

php -v

Don’t forget to restart Apache so it can “recognize” its new partner, PHP:

sudo systemctl restart httpd

Step 4: Configuring SELinux – Don’t Disable It, Understand It

This is the part where many people choose to setenforce 0 to run away from problems. Don’t do that! SELinux is a powerful shield protecting your server. By default, it prevents Apache from connecting to the database to thwart potential attacks.

To allow Apache to “talk” to MariaDB, run this command:

sudo setsebool -P httpd_can_network_connect_db on

If your website has a feature to upload images to the /var/www/html/uploads directory, assign the correct label to it:

sudo chcon -t httpd_sys_rw_content_t /var/www/html/uploads -R

With just these two commands, you’ve resolved 90% of common SELinux issues while maintaining high security.

Step 5: Testing with an info.php File

To make sure everything is working together, create a quick test file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Navigate to http://your-ip-address/info.php. If the PHP configuration table appears, congratulations on a successful installation!

Warning: Delete this file immediately after checking with the command sudo rm /var/www/html/info.php. You certainly don’t want hackers knowing too much about your server configuration.

Conclusion

Installing LAMP on Fedora isn’t difficult; the challenge lies in controlling SELinux and Firewalld. With its always-fresh package set, Fedora is a great springboard for experiencing PHP 8.3 and the latest technologies. If you plan to run a real project, your next steps should be learning about Virtual Hosts and installing SSL with Let’s Encrypt to protect user data.

Share: