Installing And Configuring Apache MariaDB And PHP On CentOS 7 (LAMP Stack)
Posted by Daniel Naval on 11 May 2019 06:33 PM
In this article, we will be installing Apache, MySQL/MariaDB with PHP 7.1 and 7.2 (mod_php) on CentOS 7 Server. This is also called as the LAMP Stack or Linux, Apache, MySQL, PHP.
Before anything else, we will try to update your CentOS 7 kernel and packages by using this command:
yum -y update
I will then add the EPEL repository for us to install the latest phpMyAdmin by using the commands below:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release
Installing MySQL / MariaDB
yum -y install mariadb-server MariaDB
After the installation, you need to enable and start the MariaDB. These commands will start configure it to start whenever the server starts up.
systemctl start mariadb.service systemctl enable mariadb.service
Configuring MySQL Installation
This will ask you to enter current password for MySQL, just hit enter as there is none since it was just installed.
Installing Apache Web Server
yum -y install httpd
Once installed, we will be configure the Apache to enable and start whenever the server boots up.
systemctl start httpd.service systemctl enable httpd.service
For the Apache Web Server to be accessed from the outside network, we will have to open the HTTP (80) and HTTPS (443) ports from the firewall. By default, the CentOS7 is using the firewalld and can be configured by using the commands below:
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --permanent --zone=public --add-service=https firewall-cmd –reload
After you configure it, you can try to visit your IP address or the hostname you used for your server and the browser should show the page as below.
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
We will be needing the yum-config-manager utility for enabling and disabling the PHP versions:
yum -y install yum-utils yum -y udpdate
Once you have added the repository, you will then be installing the PHP versions available.
To install and enable PHP 7.0:
yum-config-manager --enable remi-php70 yum -y install php php-opcache
To install and enable PHP 7.1:
yum-config-manager --enable remi-php71 yum -y install php php-opcache
To install and enable PHP 7.2:
yum-config-manager --enable remi-php72 yum -y install php php-opcache
After you have enabled your desired PHP version, you need to restart the Apache Web Service to apply the changes.
systemctl restart httpd.service
Testing your PHP Accessibility and Informations
< ?php phpinfo();
Now, you can access the info.php on your browser and should show the page below:
Congratulations! You have now setup your LAMP Stack server.