Setting Up LAMP (Linux, Apache, MariaDB and PHP) on Fedora 24 Server

Having installed Fedora 24 server edition, you might probably want to host a website on your server and for you to be able to do that on Linux, you will need to install LAMP.

Setup LAMP on Fedora 24 Server and Workstation

Setup LAMP on Fedora 24 Server and Workstation

In this tutorial, we shall go through steps you can follow to install LAMP (Linux, Apache, MariaDB and PHP) stack, a web service software that you can setup on your Fedora 24 server. For starters, you can think of it as similar to WAMP in Windows.

Step 1: Updating System Packages

As usual, it is important and recommended that you update your system packages using the command below:

# dnf update 
Update Fedora 24 Server

Update Fedora 24 Server

Let us now go through the actual installation of LAMP packages.

Step 2: Install Apache Web Server

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 in 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:

# dnf install httpd 
Install Apache on Fedora 24-Server

Install Apache on Fedora 24-Server

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:

# systemctl enable httpd.service

Then start the service:

# systemctl start httpd.service

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

# systemctl status httpd.service
Start and Verify Apache Web Server

Start and Verify Apache Web Server

In order 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 command:

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

Then reload the system firewall configurations as follows:

# systemctl reload firewalld
Open Apache Ports on Firewalld

Open Apache Ports on 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:

http://server-ip-address

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

# ip a | grep "inet" 
Check Fedora 24 Server IP Address

Check Fedora 24 Server IP Address

You should be able to view this page below:

Apache Default Webpage

Apache Default 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 Server

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 Fedora 24 server, issue the command below:

# dnf install mariadb-server
Install MariaDB on Fedora 24 Server

Install MariaDB on Fedora 24 Server

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:

# systemctl enable mariadb.service  

To start the service, use the command below:

# systemctl start mariadb.service  
Then, check whether MariaDB service is running as follows:
# systemctl status mariadb.service  
Start and Verify MariaDB Service

Start and Verify MariaDB Service

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

# mysql_secure_installation

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

Enter current password for root(enter for none): Here, Simply press [Enter]
Next you will be asked to set a root user password for your MariaDB server.
Set root password? [Y/n]: y and hit [Enter]
New password: Enter a new password for root user
Re-enter new password: Re-enter the above password 
Remove anonymous users? [Y/n]: y to remove anonymous users
It is not always good to keep your system open to remote access by root user, in case an attacker lands on your root user password, he/she can cause damage to your system. 
Disallow root login remotely? [Y/n]: y to prevent remote access for root user. 
Remove test database and access to it? [Y/n]: y to remove the test database
Finally, you need to reload privileges tables on your database server for the above changes to take effect.
Reload privileges tables now? [Y/n]: y to reload privileges tables 
Secure MariaDB Installation

Secure MariaDB Installation

You can also install MariaDB server database where it will store all server information, simply run the command below:

# mysql_install_db
Install MariaDB Database Tables

Install MariaDB Database Tables

Step 4: Install PHP and Modules

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

To install PHP on Fedora 24, use the command below:

# dnf install php php-common 
Install PHP on Fedora 24 Server

Install PHP on Fedora 24 Server

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

# dnf install php-mysql php-gd php-cli php-mbstring
Install PHP Modules in Fedora 24 Server

Install PHP Modules in Fedora 24 Server

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:

# 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:

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

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

<?php
phpinfo()
?>

Then open your web browser and enter the following URL:

http://server-ip-address/info.php

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

Verify PHP Information

Verify PHP Information

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

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

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.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

24 Responses

  1. xavico says:

    Thanks for this. I’ve just finish install LAMP. Thanks so much.

  2. Ropoja says:

    Nice post, it really helped me!

  3. Chi Fook says:

    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

  4. Wolfgang says:

    Thanks for the information!
    However, I had to use “systemctl start mariadb” instead of “systemctl start mariadb-service”.
    See also:
    https://fedoraproject.org/wiki/MariaDB

    • Ravi Saive says:

      @Wolfgang,

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

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

      Corrected in the writeup..

  5. Bobby says:

    The dash in this command # dnf install mariadb-server should be replaced with a dot.

    # dnf install mariadb.server

  6. Mojtaba says:

    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.

  7. Victor Parlindungan says:

    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

    • Ravi Saive says:

      @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
      
    • Aaron Kili K says:

      @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

  8. Richard says:

    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?

    • Ravi Saive says:

      @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..

  9. Mark says:

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

    Great! Thanks again.

  10. Barry Schofield says:

    how do I make it bootup apache when I switch on using Fedora 24?

    • Ravi Saive says:

      @Barry,

      You can enable Apache to start at Fedora 24 startup using below command.

      # systemctl enable httpd.service
      

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.