Published January 18, 2018 by

Install LAMP Stack (Apache, Mysql, php, phpMyAdmin) On Centos/RedHat


The LAMP is a combination of operating system and open-source software stack. The acronym LAMP came from the first letters of Linux, Apache HTTP Server, MySQL or MariaDB database, and PHP/Perl/Python.

1 Install Apache

Apache is an open-source multi-platform web server. It provides a full range of web server 

To install Apache



# sudo yum update
# sudo yum install httpd

Enable and Start Apache


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

Test Apache

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.


2 Install MySQL

Enable MySQL YUM repository

For Centos/RedHat
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
For Ferdora
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-fc26-10.noarch.rpm

Install MySQL Server

MySQL 8.0

For CentOS, RedHat
# yum --enablerepo=mysql80-community install mysql-community-server
For Fedora
# dnf --enablerepo=mysql80-community install mysql-community-server


MySQL 5.7

For CentOS, RedHat
# yum install mysql-community-server
For Fedora 
# dnf install mysql-community-server

Start MySQL


# systemctl start mysqld.service

At installing time MySQL by default set the root password. Using below command finds the MySQL root password

# grep "A temporary password" /var/log/mysqld.log

Configure MySQL

# mysql_secure_installation

Connect to MySQL

# mysql -u root -p

Check MySQL version

# mysql -v


3 Install PHP

Install PHP by using the following command


# sudo yum install php php-mysql

Test your PHP version

# php -v

To test PHP, create a sample “testphp.php” file in Apache document root folder.


# sudo vim  /var/www/html/testphp.php

Add the following lines

<?php
phpinfo();
?>

Restart apache2 service


# sudo systemctl restart httpd.service

Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.




4 Install phpMyAdmin

Add the EPEL Repository


# rpm -iUvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install phpMyAdmin

# yum update
# yum install phpmyadmin

Configuration phpMyAdmin

# vim /etc/httpd/conf.d/phpMyAdmin.conf

By default, the configuration for phpMyAdmin only allows access from the server on which it is installed. Find the following sections and change each IP address to your public IP, or another IP address that will be connecting to phpMyAdmin remotely:
Require ip 127.0.0.1
Allow from 127.0.0.1
Require ip 127.0.0.1
Allow from 127.0.0.1

Restart apache2 service.


# sudo systemctl restart httpd.service

Access phpMyAdmin Web Console

Now, you can access the phpMyAdmin console by navigating to http://localhost/phpmyadmin/ from your browser.