How To Install Linux, Apache, MariaDB, PHP (LAMP Stack) on CentOS 7 / RHEL 7

3

LAMP Stack stands for Linux, Apache, MariaDB, and PHP stack. It is mainly used for hosting websites and blogs.

Here, we will see how to install LAMP stack on CentOS 7 / RHEL 7.

Install LAMP Stack

Install Linux

Here is the article about step by step installation of CentOS 7 / RHEL 7.

Now you have Linux, and the next is to install Apache, MySQL, and PHP on it. Let’s install them one by one.

Install Apache

The package name of the Apache is httpd. Install the httpd package using the YUM command.

yum install -y httpd

Start the Apache service by using the following command.

systemctl start httpd

Enable Apache webserver to start automatically during every boot.

systemctl enable httpd

Configure the firewall to allow HTTP requests.

firewall-cmd --permanent --add-port=80/tcp

firewall-cmd --reload

To make sure everything installed correctly, we will now test Apache to ensure it is working correctly. Open up any web browser and then enter the following into the web address:

http://localhost

OR

http://your.ip.adr.ess

You will get the web page saying “Testing 123”, this confirms that the Apache is working fine.

Apache Web Server Default Page
Apache Web Server Default Page
Apache’s default document root is /var/www/html on CentOS, and the main configuration file is /etc/httpd/conf/httpd.conf. Additional configurations for Apache are stored in the /etc/httpd/conf.d/ directory.

Install MariaDB

In CentOS / RHEL, MySQL is now replaced by MariaDB as a default database.

CentOS 7/ RHEL ships MariaDB v5.5. The version is nearing the end of support on April 2020. So, it is recommended to install MariaDB v10.4 or install MySQL v8.0 instead of MariaDB for LAMP stack.

To install MariaDB, use the following command.

yum install -y mariadb mariadb-server

Start the MariaDB service using the below command.

systemctl start mariadb

To make the MariaDB start during every boot. Type the following on terminal and hit enter.

ADVERTISEMENT

systemctl enable mariadb

Nex is to make the MariaDB secure by using the mysql_secure_installation command.

This program enables you to improve the security of your MariaDB installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the localhost.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
mysql_secure_installation

Output:

Install Linux, Apache, MariaDB, PHP (LAMP Stack) on CentOS 7 - Secure MariaDB Installation
Install Linux, Apache, MariaDB, PHP (LAMP Stack) on CentOS 7 – Secure MariaDB Installation

Install PHP

By default Apache server supports the HTML language only, not PHP. Install the PHP package along with support for the MariaDB.

PHP v5.4 (End Of Support)

The PHP version (v5.4) available in the CentOS base repository is already the end of support.

PHP v7.3

Remi, a third-party repository which offers up to date version of PHP (v7.3). To enable the Remi repository, install the Remi repository auto-configuration package.

yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum install -y --enablerepo=remi-php73 php php-cli php-mysqlnd

You need to restart the server after the installation of the PHP, to do that type the following on the terminal.

systemctl restart httpd

Test LAMP Stack

To test PHP, place a .php file on to the default directory of the Apache.

echo "<?php phpinfo()?>" > /var/www/html/info.php
This file will display lots of useful information about our PHP installation, such as the installed PHP version, PHP extension details, etc.

Now open your web browser and type the following into the web address:

http://localhost/info.php

OR

http://you.ip.addr.ess/info.php

The page looks like below:

PHP Information
PHP Information

Scroll down the browser to the modules section to check the support for MariaDB. You will get the screen like below.

MySQL Modules
MySQL Modules

Conclusion

That’s All. You have successfully installed the LAMP Stack on CentOS 7 / RHEL 7. If you are new to a database management system, consider installing phpMyAdmin to manage databases over a web browser. Also, install Let’s Encrypt SSL certificate for secure communication.

You might also like