HOW TO INSTALL LAMP ON CENTOS/RHEL 7 (Linux, Apache, MySQL, PHP)

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 LAMP stack on CentOS 7 and RedHat 7 systems.

 

Step 1: Install Apache Server with Basic Configurations

fter performing a minimal system installation and configure your server network interface with a Static IP Address, Install Apache package :

# yum install httpd

To manage httpd service, we can use those commands  :

# systemctl status|start|stop|restart|reload httpd

OR

# service httpd status|start|stop|restart|reload

OR

# apachectl configtest| graceful

 

Don’t forget to authorize httpd service permanently on firewall :
# firewall-cmd --permanent --add-service=http
# systemctl restart firewalld

Other important Firewalld options are presented below:

# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=8080/tcp

 

To verify Apache functionality open a remote browser and type (http://server_IP)

Apache DocumentRoot path it’s set to /var/www/html system path, to modify it :

# nano /etc/httpd/conf.d/welcome.conf

# systemctl restart httpd


Step 2: Install PHP5 Support for Apache

# yum search php

# yum install php php-mysql php-pdo php-gd php-mbstring

To get a full information list on PHP from your browser, create a info.php file on Apache Document Root using the following command from root account, restart httpd service and direct your browser to the http://server_IP/info.php address.

# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# systemctl restart httpd

 

Step 3: Install and Configure MYSQL Database

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

# yum install mysql-server

# systemctl enable mysqld.service

# systemctl start mysqld.service

# grep "A temporary password" /var/log/mysqld.log | tail -n1

A temporary password is generated for root@localhost: EX;By2h#

# mysql_secure_installation
MySQL security wizzard
Change the password for root?   - y
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-php73 install php

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

# yum --enablerepo=remi-php73 list php-*

# yum --enablerepo=remi-php73 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 : Check Installed Version

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

# php -v

PHP 7.3.1 (cli) (built: Jan  8 2019 13:55:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
# httpd -v

Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09
# mysql -V

mysql  Ver 8.0.13 for Linux on x86_64 (MySQL Community Server - GPL)

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