Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Distributions»CentOS»How to Install Apache, MySQL, PHP (LAMP) on CentOS/RHEL 7

    How to Install Apache, MySQL, PHP (LAMP) on CentOS/RHEL 7

    RahulBy RahulNovember 3, 20154 Mins ReadUpdated:April 22, 2020

    LAMP stands for Linux, Apache, MySQL and PHP. Its is used for hosting websites written with PHP programming language and using MySQL as backend database server. This article will help you to install Apache 2.4, MySQL 8 and PHP 7.3 on CentOS 7 and RedHat 7 systems. You may also use video tutorial on Youtube for installation instruction’s.

    Recommended Article:

  • 15 Best Security Tips for LAMP Stack (Apache-MySQL-PHP) for Linux

  • Step 1 – Prerequsitis

    The two most popular rpm repositories REMI and EPEL have most of the updated packages. They are also providing the latest packages for LAMP setup. Enable both repositories on your system using the following commands on your CentOS 7 system.

    rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    

    Step 2 – Install Apache Server

    Apache or HTTP is the most popular web server used on Linux based systems. Let’s install Apache web server using the following command by enabling EPEL and REMI yum repositories.

    yum --enablerepo=epel,remi install httpd
    

    Now start httpd service and enable to start on boot using commands.

    systemctl enable httpd.service
    systemctl start httpd.service
    

    Step 3 – Install MySQL Server

    First, add MySQL yum repository in your system using the following command. You may also visit repo.mysql.com to find repository rpms for other operating systems. The below command will work with CentOS and RedHat 7.

    rpm -Uvh  https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
    

    The default MySQL 8 repository is enabled for installation. To change edit repository configuration file (/etc/yum.repos.d/mysql-community.repo) and enable/disable repositories as per requirements.

    Then install the MySQL server and other dependency packages.

    yum install mysql-server
    

    After installation enable MySQL service and start it.

    systemctl enable mysqld.service
    systemctl start mysqld.service
    

    The installer generated a temporary password for MySQL root user and copied to log file. You can find this password using the below command.

    grep "A temporary password" /var/log/mysqld.log  | tail -n1
    
    [Some text hidden] A temporary password is generated for [email protected]: Eif;=YpBy2h#
    

    Apply security on newly installed MySQL server. This will also prompt you to change the temporary password with a new password.

    mysql_secure_installation
    
    MySQL security wizzard
    Enter password for user root:  [Enter password here found in log file]
    The existing password for the user account root has expired. Please set a new password. 
    New password: [Enter new password]
    Re-enter new password: [Re-enter new password]
    
    Change the password for root?   - n
    Remove anonymous users?   - y
    Disallow root login remotely?    - y
    Remove test database and access to it?    - y
    Reload privilege tables now?   - y
    

    MySQL has been installed on your system. After this install PHP.

    Step 4 – Install PHP

    Now, install PHP packages with enabling EPEL and REMI repositories using the following command.

    yum --enablerepo=epel,remi-php74 install php
    

    Then install required PHP modules. Use the following command to list available modules and install it.

    yum --enablerepo=remi-php74 list php-*
    yum --enablerepo=remi-php74 install php-mysql php-xml php-xmlrpc php-soap php-gd
    

    After installing php and other php modules restart Apache service.

    systemctl restart httpd.service
    

    Step 5 – Allow Port in Firewall

    Finally open firewall ports for HTTP (80) and HTTPS (443) services using the following command.

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

    Step 6 – Check Installed Version

    Let’s check the installed versions of packages on the system using following commands one by one.

    php -v
    
    PHP 7.4.5 (cli) (built: Apr 14 2020 12:54:33) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    
    httpd -v
    
    Server version: Apache/2.4.6 (CentOS)
    Server built:   Aug  8 2019 11:41:18
    
    mysql -V
    
    mysql  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
    

    Now you have successfully configured LAMP setup on your CentOS or RedHat 7 system.

    Recommended Article:

  • 15 Best Security Tips for LAMP Stack (Apache-MySQL-PHP) for Linux
  • Apache httpd lamp MySQL
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Linux Kernel 4.3 on Ubuntu & LinuxMint
    Next Article How to Upgrade to Fedora 23 from Fedora 22 using DNF

    Related Posts

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install MySQL Server on Ubuntu 22.04

    Updated:April 6, 20224 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    How To Disable HTTP Methods in Apache

    Updated:December 31, 20212 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    5 Comments

    1. Priyansh Soni on October 8, 2021 10:04 am

      can i use these command for Red hat 7.9 also? can i install php 5.2 also On Red hat 7.9?

      Reply
    2. Aneesh Sankar on December 31, 2019 3:05 pm

      Thank you brother.. I was in search such an informative guide…

      Reply
    3. Oack on October 4, 2019 7:43 am

      Note: get more…

      yum –enablerepo=remi-php73 install php-cli php-common php-bcmath php-dba php-devel php-embedded php-fpm php-gd php-imap php-interbase php-intl php-ldap php-mbstring php-mcrypt php-mysql php-odbc php-opcache php-pdo php-pdo_dblib php-pear php-process php-pspell php-recode php-tidy php-xml php-xmlrpc

      Reply
    4. Deviouskind on March 18, 2019 10:46 pm

      Thanks. My goal is to try out an open source ticketing system.
      On to how to run a php file! Thanks

      Reply
    5. Pankaj on August 4, 2015 6:27 am

      Trying to install only httpd using first 3 steps. But as I execute ” yum –enablerepo=epel,remi install http” it is giving me no httpd package available. Please help.

      Regards
      Pankaj

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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