Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»How to Install Apache/PHP 7 on CentOS/RHEL 7.6/6.9 and Fedora 31/30

    How to Install Apache/PHP 7 on CentOS/RHEL 7.6/6.9 and Fedora 31/30

    By RahulMarch 13, 20202 Mins Read

    Are you planning to deploy a PHP application with the Apache webserver? This tutorial will help you with installing Apache web server and PHP on your CentOS, Redhat, and Fedora systems.

    Advertisement

    Recommended Article:

  • 15 Best Security Tips for LAMP Stack (Apache-MySQL-PHP) for Linux
  • Step 1 – Prerequsities

    First of all, you need to add some required rpm repositories on your system. Use one of the below commands as per your operating systems.

    On CentOS/RHEL 7
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    
    On CentOS/RHEL 6
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
    
    On Fedora 31
    sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm 
    sudo dnf install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
    sudo dnf install http://rpms.famillecollet.com/fedora/remi-release-31.rpm
    
    On Fedora 30
    sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm 
    sudo dnf install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
    sudo dnf install http://rpms.famillecollet.com/fedora/remi-release-30.rpm
    
    On Fedora 29
    sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm 
    sudo dnf install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
    sudo dnf install http://rpms.famillecollet.com/fedora/remi-release-29.rpm
    

    Step 2 – Install Apache/PHP

    After enabling the required yum repositories on your system. Now install the Apache and PHP packages on your system. This will install the latest available packages on your system.

    For CentOS and RHEL 7/6

    sudo yum --enablerepo=remi,remi-php71 install httpd php php-common
    

    For Fedora 31/30/29/28/27/26

    sudo dnf --enablerepo=remi install httpd php php-common
    

    Step 3 – Install PHP Modules

    You also required installing PHP modules required for your application. The below command will install some frequently used PHP modules on your system. You may install any other modules with the same command.

    For CentOS and RHEL 7/6

    sudo yum --enablerepo=remi,remi-php71 install php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml
    

    For Fedora 31/30/29/28/27/26

    sudo dnf --enablerepo=remi install php-cli php-pear php-pdo php-mysqlnd php-gd php-mbstring php-mcrypt php-xml
    

    Step 4 – Manage Apache Service

    At this point, your system has installed the Apache web server, PHP, and modules. Now start the Apache server and also enable them to autostart on system boot.

    For CentOS/RHEL 7 and Fedora

    sudo systemctl start httpd.service 
    sudo systemctl enable httpd.service
    

    For CentOS/RHEL 6

    service httpd start 
    chkconfig --levels 235 httpd on
    

    As a result of this tutorial, you have successfully configured a web hosting environment on your Red Hat-based system.

    Recommended Article:

  • 15 Best Security Tips for LAMP Stack (Apache-MySQL-PHP) for Linux
  • Install Apache2, MySQL and PHP5 on Ubuntu and Debian System

  • Apache httpd Install PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Apache CouchDB on Ubuntu & Debian

    How to Schedule a Cron Job for PHP: A Step-by-Step Guide

    How to Compare Two Array Values in PHP: A Practical Guide

    View 13 Comments

    13 Comments

    1. LesD on January 18, 2020 9:48 pm

      Had to run for latest CentOS
      firewall-cmd –add-service=http –permanent
      to open up the firewall otherwise Apache did not respond

      Reply
    2. jmeinken on February 16, 2018 3:13 pm

      Followed the steps on RHEL 7 and everything worked perfectly. Thanks!

      Reply
    3. jag on August 13, 2014 5:01 am

      Thanx.

      Reply
    4. jody brabec on April 4, 2014 8:41 pm

      Thanks, you saved my sanity!

      Reply
    5. deepak on January 28, 2014 5:53 pm

      gr8 article.

      Reply
    6. Ramesh on January 24, 2014 6:51 am

      Very useful wiki. Just follow the steps blindly in F19. It works awesome.

      Reply
    7. raju on December 14, 2013 3:17 pm

      login as: root
      [email protected]‘s password:
      Last login: Sat Dec 14 09:22:39 2013 from 124.123.0.103
      [[email protected] ~]# /usr/bin/mysql_secure_installation

      NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

      In order to log into MySQL to secure it, we’ll need the current
      password for the root user. If you’ve just installed MySQL, and
      you haven’t set the root password yet, the password will be blank,
      so you should just press enter here.

      Enter current password for root (enter for none):
      ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
      Enter current password for root (enter for none):
      ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
      Enter current password for root (enter for none):

      Reply
      • raju on December 14, 2013 3:19 pm

        the above problem i am getting i entered correct root password getting this reinstalled centos again getting this message

        Reply
        • Rahul on December 16, 2013 10:44 am

          Hi Raju,

          Is this a fresh install of MySQL ?

          Reply
          • raju on December 16, 2013 10:52 am

            you are correct the vps package already did 3 steps can you install web min for my server i will give you root password above ip is you need to install

            also i tried setup a website on vps with commands

            but not luck can you please make a post to setup a website in means WordPress for a newbie

            also include upload database process import export from MySQL commands

            Reply
            • Richard on January 29, 2014 12:44 am

              Before executing mysql_secure_installation one must start the service with:
              #service mysqld start

              Reply
    8. Patrik on September 13, 2013 3:54 pm

      Very well written article…. I like article’s written with clear steps…. thank you so much

      Reply
    9. Nishant on September 10, 2013 7:44 am

      Great article …. Thanks

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Setting Up Angular on Ubuntu: Step-by-Step Guide
    • Converting UTC Date and Time to Local Time in Linux
    • Git Restore: Functionality and Practical Examples
    • Git Switch: Functionality and Practical Examples
    • Git Switch vs. Checkout: A Detailed Comparison with Examples
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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