Setting Up LAMP (Apache, MariaDB, PHP) on Fedora 40 Server

After installing the Fedora 40 server edition, you might want to host a website on your server. To do this, you need a reliable server environment setup called the LAMP stack, which consists of Linux, Apache, MariaDB (a MySQL drop-in replacement), and PHP.

In this tutorial, we will walk through the steps you can follow to install the LAMP (Linux, Apache, MariaDB, and PHP) stack, which is web service software that you can set up on your Fedora 40 server.

Step 1: Updating Fedora System Packages

Once Fedora Server is installed, the first step is to update the system packages to ensure you have the latest security patches and software updates.

sudo dnf update
Update Fedora System
Update Fedora System

Step 2: Install Apache on Fedora

Apache is a popular and most reliable web server on the Linux platform powering multiple websites and web-based applications on the web. It comes with several modules to enhance its functionality under different categories including security modules, server access modules plus so much more.

To install Apache, issue the command below on your terminal:

sudo dnf install httpd
Install Apache in Fedora
Install Apache in Fedora

After installation is complete, you need to perform a few tasks to get your Apache web server running.

First, you need to set it to start automatically at boot time:

sudo systemctl enable httpd.service

Then start the service:

sudo systemctl start httpd.service

Next, to be sure that the service is running, you can issue the command below:

sudo systemctl status httpd.service
Check Apache Status
Check Apache Status

To access your web server over HTTP/HTTPS, you need to enable access to it through the system firewall.

To do that, run the following commands:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

Then reload the system firewall configurations as follows:

sudo systemctl reload firewalld

One last thing to do under Apache installation is to check whether the default Apache installation index page can load in your web browser, therefore open your web browser and enter your server IP address as shown:


If you don’t know your server IP address, you can find using the below ip command.

ip a | grep "inet" 
Check Fedora Server IP
Check the Fedora Server IP

You should be able to view this page below:

Fedora Apache Webpage
Fedora Apache Webpage

Note: The Apache default root directory is /var/www/html, and this is where you can drop your web files.

Step 3: Install MariaDB on Fedora

MariaDB is a fork of the popular MySQL relational database server, it is free software and conforms to the GPU general public license.

To install MariaDB on the Fedora server, issue the command below:

sudo dnf install mariadb-server
Install MariaDB in Fedora
Install MariaDB in Fedora

After completing the installation, you need to enable the service to run automatically at system startup, also start it for you to be able to create and use databases on your server.

To enable it to start at boot time, run the command below:

sudo systemctl enable mariadb.service  

To start the service, use the command below:

sudo systemctl start mariadb.service  

Then, check whether the MariaDB service is running as follows:

sudo systemctl status mariadb.service  
Manage MariaDB Service
Manage MariaDB Service

Now that MariaDB is running on your server, you need to secure its installation using the command below:

sudo mysql_secure_installation

After running this command, you will be asked a few questions demanding you to make a few changes and these include:

Secure MariaDB Installation
Secure MariaDB Installation

Step 4: Install PHP on Fedora

PHP is a serve-side scripting language that handles and sends user requests to the web and database server.

To install PHP on Fedora, use the command below:

sudo dnf install php php-common 
Install PHP in Fedora
Install PHP in Fedora

In order for PHP to work well with mysql databases, you need to install some PHP modules therefore, execute the command below to install the required PHP modules:

sudo dnf install php-mysqlnd php-gd php-cli php-mbstring
Install PHP Extensions in Fedora
Install PHP Extensions in Fedora

When the installation process is complete, you need to restart the Apache web server, this will allow all the changes to take effect before you can have a complete working LAMP stack.

To restart Apache, issue the command below:

sudo systemctl restart httpd 

Now you can test it all, using your favorite editor, create a called file info.php in your Apache root directory as follows:

sudo vi /var/www/html/info.php

Add the following lines in the file, save it, and exit.


Then open your web browser and enter the following URL:


In case everything is set, then you should be able to view this PHP information below:

Verify PHP in Fedora
Verify PHP in Fedora

I believe all is well at this point, you can now use LAMP on your Fedora server. For any questions, please use the comment section below to express your thoughts, and always remember to stay connected to TecMint.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. Hello, after executing mysql_install_db command i got this error :
    Installing MariaDB/MySQL system tables in ‘/var/lib/mysql’ …
    2017-08-12 19:34:55 139953582225664 [Note] /usr/libexec/mysqld (mysqld 10.1.25-MariaDB) starting as process 5851 …

    Installation of system tables failed! Examine the logs in
    /var/lib/mysql for more information.

    The problem could be conflicting information in an external
    my.cnf files. You can ignore these by doing:

    shell> /usr/bin/scripts/mysql_install_db –defaults-file=~/.my.cnf

    You can also try to start the mysqld daemon with:

    shell> /usr/libexec/mysqld –skip-grant –general-log &

    and use the command line tool /usr/bin/mysql
    to connect to the mysql database and look at the grant tables:

    shell> /usr/bin/mysql -u root mysql
    mysql> show tables;

    Try ‘mysqld –help’ if you have problems with paths. Using
    –general-log gives you a log in /var/lib/mysql that may be helpful.

    The latest information about mysql_install_db is available at
    MariaDB is hosted on launchpad; You can find the latest source and
    email lists at

    Please check all of the above before submitting a bug report

    i use fedora 26

  2. on Fedora 25 Server, package php-mysql is not available, so the command :

    # dnf install php-mysql

    won’t work and it should replace with :

    # dnf install php-mysqlnd

    • @Wolfgang,

      Yes, you right, the correct command should be like this:

      # systemctl start mariadb.service
      # systemctl status mariadb.service

      Corrected in the writeup..

  3. hi,

    I did everything as said step by step. the site works fine, but the login page and the dashboard are a mess. could you please help me.

  4. I’ve just finish installing LAMP with your tutorial. Everything working fine, except the php. The php is not being executed. I try adding semicolon after the braces, but not executed too.

    Note :
    Fedora 24 on vmware

    • @Victor,

      How you executing PHP command? could you share with us and also could you run the following command to confirm that the php installed correctly..

      # php -v
    • @Victor

      Try to install libapache2-mod-php5, apache2’s module to work with php as follows and then test php again:

      sudo dnf install libapache2-mod-php5

  5. How would I connect Apache and MariaDB together if they were on separate VMs? Lets say I installed Apache on one VM and then MariaDB on another VM, how would they work together?

    • @Richard,

      On the Apache Serer, just add the MariaDB settings like username, password, database name and server IP address (IP Address of MariaDB) in the Apache application configuration file may be in config.php for something like this..

  6. Thanks for this. Very helpful! One type though: “systemctl enable mariadb-service ” et. seq should be “systemctl enable mariadb.service”

    Great! Thanks again.


Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.