Installing LAMP Stack on CentOS 7: A Step-by-Step Guide

Installing LAMP Stack on CentOS 7: A Step-by-Step Guide

Mounting the LAMP Stack

Before proceeding with the installation, ensure that you update the backup source by downloading the update from the official CentOS repository. This is crucial to ensure that you have the latest packages and dependencies.

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

Updating Local Cache

Update the local cache by running the following commands:

yum clean all
yum makecache

Installing Network Tools

If you plan to use commands such as ifconfig, install the network tools package:

yum install net-tools

Disabling Firewall and SELinux

To ensure that the LAMP stack functions correctly, disable the firewall and SELinux:

systemctl stop firewalld.service
systemctl disable firewalld.service

To disable SELinux, edit the configuration file /etc/selinux/config and comment out the following lines:

# SELINUX= enforcing
# SELINUXTYPE=targeted

Add the following line to disable SELinux:

SELINUX=disabled

Save and exit the file using wq. Then, run the following command to set SELinux to permissive mode:

setenforce 0

Installing Apache

Install Apache using the following command:

yum install httpd

Mounting MariaDB

Install MariaDB using the following command:

yum install mariadb mariadb-server

To configure MariaDB, copy the original configuration file:

cp /usr/share/mysql/my-huge.cnf /etc/my.cnf

Installing PHP

Install the PHP packages using the following command:

yum install php php-gd php-odbc php-pear php-mbstring php-mcrypt

Extracting PHPMyAdmin

Download PHPMyAdmin using the following command:

wget https://files.phpmyadmin.net/phpMyAdmin/4.0.0/phpMyAdmin-4.0.0-all-languages.zip

Extract the downloaded file to the /var/www/html/phpmyadmin directory.

Configuring Apache

To configure Apache, edit the configuration file /etc/httpd/conf/httpd.conf and add the following lines:

Include vhost/*.conf

Create a new configuration file for the PHPMyAdmin virtual host:

mkdir /etc/httpd/vhost
touch test.conf
DocumentRoot /var/www/html/test
ServerName test
Options FollowSymLinks
AllowOverride All

Create another configuration file for the PHPMyAdmin virtual host:

touch phpmyadmin.conf
DocumentRoot /var/www/html/phpmyadmin
ServerName phpmyadmin
Options FollowSymLinks
AllowOverride All

Restart Apache and MariaDB:

systemctl restart httpd.service
systemctl restart mariadb.service

Installing EPEL Source

To install the EPEL source, download the package using the following command:

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm

If the version is not the same, visit the official EPEL repository to find the correct version.

Installing mcrypt Extension

Install the mcrypt extension using the following command:

yum install php-mcrypt

Installing Redis and Memcache

Install Redis and Memcache using the following commands:

yum install redis
yum install memcached

To configure Redis, edit the configuration file /etc/redis.conf and uncomment the following line:

daemonize yes

Installing PHP Extensions

Install the PHP extensions using the following commands:

yum install php-redis
yum install php-memcached

Starting and Stopping Services

To start, stop, and restart services, use the following commands:

systemctl start httpd.service
systemctl stop httpd.service
systemctl restart httpd.service

systemctl start mariadb.service
systemctl stop mariadb.service
systemctl restart mariadb.service

Conclusion

In this article, we have covered the installation of a LAMP stack on CentOS 7, including Apache, MariaDB, PHP, and PHPMyAdmin. We have also covered the installation of EPEL source, mcrypt extension, Redis, Memcache, and PHP extensions. By following these steps, you should now have a fully functional LAMP stack on your CentOS 7 system.