Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at: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

    By RahulApril 22, 20204 Mins Read

    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.

    Advertisement

    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

    Related Posts

    Comparing Apache MPM Worker and Prefork: Which is Right for Your Application

    How to Install Apache (httpd) on RHEL & CentOS Stream 9

    How to Install LAMP Stack on RHEL & CentOS Stream 9

    View 5 Comments

    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

    Advertisement
    Recent Posts
    • Configure Postfix to Use Gmail SMTP on Ubuntu & Debian
    • PHP Arrays: A Beginner’s Guide
    • Deploying Flask Application on Ubuntu (Apache+WSGI)
    • OpenSSL: Working with SSL Certificates, Private Keys and CSRs
    • How to Create and Read List in Python
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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