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

  • Share.

    13 Comments

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

    2. login as: root
      root@192.64.84.56‘s password:
      Last login: Sat Dec 14 09:22:39 2013 from 124.123.0.103
      [root@server ~]# /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):

          • 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

    Exit mobile version