Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Distributions»Fedora»How to Install Apache, MySQL & PHP (LAMP Stack) on Fedora

    How to Install Apache, MySQL & PHP (LAMP Stack) on Fedora

    By RahulFebruary 22, 20234 Mins Read

    A LAMP stack is a popular combination of open-source software that is used to power web applications. It is composed of four main components: the Linux operating system, the Apache web server, the MySQL relational database management system, and the PHP programming language. In this tutorial, we will guide you through the process of installing the LAMP stack on Fedora, a popular Linux distribution.

    Advertisement

    Step 1: Update System Packages

    Before installing the LAMP stack, it is important to update the system packages to ensure that you have the latest version of the software. To do this, open the terminal and enter the following command:

    sudo dnf update 
    

    Step 2: Install Apache Web Server

    Apache is a free and open-source web server software that is used to serve web pages over the internet. To install Apache on Fedora, run the following command:

    sudo dnf install httpd 
    

    Once Apache is installed, you need to start the Apache service and enable it to run at boot time. Run the following commands to do this:

    sudo systemctl start httpd 
    sudo systemctl enable httpd 
    

    Then verify httpd service is running properly:

    sudo systemctl status httpd 
    

    Install Apache on Fedora

    Step 3: Install MariaDB Database Server

    MariaDB is a popular open-source relational database management system. To install MySQL on Fedora, run the following command:

    sudo dnf install mariadb-server 
    

    Don’t like MariaDB? Use this tutorial to install MySQL on Fedora.

    After installing MySQL, you need to start the MySQL service and enable it to run at boot time. Run the following commands to do this:

    sudo systemctl enable mariadb 
    sudo systemctl start mariadb 
    

    Step 4: Secure MySQL Installation

    By default, MySQL installation is not secured. You need to run the following command to secure it:

    sudo mysql_secure_installation 
    

    Follow the onscreen instructions. The default password is none. Change your root account password and Press Y for all other operations to apply improved security.

    • Enter current password for root (enter for none): [ PRESS ENTER ]
    • Set root password? [Y/n] y
    • New password: [ ENTER PASSWORD HERE ]
    • Re-enter new password: [ RE-ENTER PASSWORD HERE ]
    • Remove anonymous users? [Y/n] y
    • Disallow root login remotely? [Y/n] y
    • Remove test database and access to it? [Y/n] y
    • Reload privilege tables now? [Y/n] y

    Now check the MariaDB service status.

    sudo systemctl status mariadb 
    

    Install MariaDB on Fedora

    Step 5: Install PHP

    PHP is a popular programming language that is used to develop dynamic web pages. To install PHP on Fedora, run the following command:

    sudo dnf install php php-common php-mysqlnd 
    

    You may also require some modules as per your requirements. Install the required PHP modules on your system.

    sudo dnf install php-xml php-json php-gd php-mbstring 
    

    Verify the current active PHP version on your system

    php -v 
    
    PHP 7.2.17 (cli) (built:  Apr 18 2019 14:12:38) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    

    Step 6: Add Firewall Rules

    As per our reader’s comment. I am including the below steps to enable firewall access for HTTP(80) and HTTPS(443). To understand about FirewallD read our next tutorial.

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

    Then reload the firewall daemon to apply the above changes.

    sudo systemctl reload firewalld 
    

    Step 7: Restart Apache

    After installing PHP, you need to restart the Apache service to ensure that PHP is loaded. Run the following command to do this:

    sudo systemctl restart httpd 
    

    Step 8: Test the LAMP Stack

    To test if the LAMP stack is working properly, you need to create a PHP file in the web root directory. Run the following command to create a PHP file:

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

    Paste the following code into the file:

    1
    2
    3
    <?php
      phpinfo();
    ?>

    Save and exit the file. Now access the info.php file using your system IP address in a web browser. To find your system IP use the command

    nmcli -p device show 
    

    Now open a web browser and enter the following URL: http://localhost/info.php

    Install Apache/PHP on Fedora

    Conclusion

    In this tutorial, we have walked you through the process of installing the LAMP stack on Fedora. The LAMP stack is a powerful combination of software that is used to power web applications. By following the steps outlined in this tutorial, you should now have a working LAMP stack on your Fedora system. You can now begin developing and deploying web applications using this powerful technology stack.

    Apache fedora lamp lamp stack mariadb MySQL PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Securing MySQL Database with Limited User Permissions

    PHP Arrays: A Beginner’s Guide

    Running Laravel Queue Worker as a Systemd Service

    View 19 Comments

    19 Comments

    1. Fari on July 18, 2021 4:21 pm

      Hellow. I’m trying to install joomla but there are some problems with /var/www/html folder permissions and it ask fpt account during installation process. Is it correct to leave as root user permissions or must be apache user for this folder? In any case it does not work on fedora 34 🙁
      Thanks

      Reply
    2. Raul on July 10, 2021 2:10 pm

      Hello nice tutorial, just need add
      systemctl start php-fpm
      and later when install php and php-common just restart http using
      systemctl restart httpd
      nice job and nice web congratulations!

      Reply
    3. Fizzle_Fuze on July 8, 2021 6:50 pm

      Apache isn’t handling PHP pages properly for me. It offers them for download instead of executing them. From what I’ve read on older versions, it needs a shared object loaded in httpd.conf, but I cannot find that .so on my system.

      Reply
      • Rahul on July 9, 2021 1:42 am

        Looks like, PHP extension is not enabled in Apache.

        Reply
    4. andrew on December 30, 2020 12:33 pm

      How can i change the default directory to be like a folder public_html in home instead of /var/www/html?

      Reply
    5. Luke Marvelly on October 31, 2020 5:52 pm

      Some of the commands were slightly different on my version of Fedora, dunno why I’m new to Fedora.

      These are what I had to type in for the firewall settings:
      firewall-cmd –permanent –add-service=http
      firewall-cmd –permanent –add-service=https

      and then I had to restart apache like Lucas abouve

      sudo systemctl restart httpd

      Reply
      • Elazar on December 7, 2020 3:46 am

        In Fedora 33 I had to use
        sudo firewall-cmd –add-service=http –add-service=https ––permanent

        sudo systemctl stop firewalld
        sudo systemctl start firewalld

        Reply
    6. raj on September 16, 2019 8:37 pm

      I followed all these steps but I am stuck in the final tep where the page is taking too long to load and is not displaying the phpinfo page. I get a connection timed out , 192.168.1.100 taking too long to respond message.

      Reply
      • fbatch on January 8, 2020 11:27 am

        Your ip address might not be 192.168.1.100
        Type “nmcli -p device show” to get this information, it can be something like 127.0.0.1

        Reply
    7. thanansetra on September 12, 2019 6:13 pm

      Thank you so much

      Reply
    8. Gretchen on September 8, 2019 8:10 pm

      Ah c’mon. It’s a dash dash / hyphen hyphen

      Reply
    9. Gretchen on September 8, 2019 8:08 pm

      Trying again:

      It’s — before permanent and add-service

      Reply
    10. Gretchen on September 8, 2019 8:04 pm

      CentOS 7:

      firewall-cmd –permanent –add-service=http

      firewall-cmd –permanent –add-service=http

      Reply
    11. Jazman on July 15, 2019 3:52 am

      firewall-cmd –permanent –add-service=http
      firewall-cmd –permanent –add-service=https
      systemctl reload firewalld

      those three commands save my day… especially the last one … reloading the firewall daemon … *doh*

      Reply
      • Epi Camacho on July 31, 2019 5:54 pm

        You’re using the incorrect syntax

        firewall-cmd –zone=public –add-service=http –permanent
        firewall-cmd –zone=public –add-service=https –permanent
        systemctl reload firewalld

        Reply
    12. Mario Moreno on May 31, 2019 1:19 am

      Tanks!!

      Reply
    13. Lucas Borges on May 12, 2019 8:47 pm

      Great tutorial!

      In my machine when I went to “http://192.168.1.100/phpinfo.php” i saw the php source code.
      To solve the problem I restarted the apache running this command on therminal.

      $ sudo systemctl restart httpd

      Apart from this, everything was ok.

      Reply
      • Tony on May 17, 2019 4:28 pm

        Disculpa con la ip funciona sin ningún problema, pero porque al poner localhost no se muestra nada?

        Reply
    14. Dileepa on February 22, 2019 4:05 pm

      thank you

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.