LAMP Stack consists of Apache web server, MariaDB / MySQL database, and PHP language, running on top of Linux operating system. It is the most widely used tech stack all around the world for websites, hosting, blogs, etc.. used by small to enterprise organizations.

LAMP is the acronym of

L – Linux Operating System
A – Apache Web Server
M – MariaDB / MySQL Server
P – PHP language

Here, we will see steps to install Linux, Apache, MariaDB / MySQL, PHP (LAMP Stack) on CentOS 7.

Install Linux

At this moment, we don’t have any article written about how to install CentOS 7. However, you can click this link to find it in Google.

Once you have CentOS 7 (Linux) ready, proceed to install Apache, MariaDB / MySQL, PHP on it.

Install Apache

Open a terminal and switch yourselves to the root user.

$ su -

The Apache package is available in the base repository of CentOS 7. The name of the Apache package is httpd, and you can install it using the yum command.

yum install -y httpd

Start the Apache service with systemctl command.

systemctl start httpd

By default, Apache web service doesn’t start automatically on system reboot. So, to make the Apache service to start automatically during every system reboot run the following command.

systemctl enable httpd


FirewallD blocks all request coming to the system except SSH connections. So, we need to allow HTTP requests in the firewall from external machines to access web pages.

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

Test Apache Web Server

To make sure Apache web server installed correctly we will now test it to see if it is working correctly. Open up a web browser and then go to the following web address.




You should see the web page saying Testing 123. This page confirms that the Apache web server is working fine.

Apache Web Server's Default Page

Apache web server’s default document root is /var/www/html and the main configuration file is /etc/httpd/conf/httpd.conf. Additional configurations can be seen in the /etc/httpd/conf.d/ directory.

Install MariaDB / MySQL

The MariaDB has become the default database server replacing MySQL after the licensing issue.

MySQL is no longer available in the default os repository. However, you can install MySQL v8.0 on CentOS 7 from MySQL DEV if you do not want to use MariaDB.

Here, I will install the MariaDB.

yum install -y mariadb mariadb-server

Start the MariaDB service with the below command.

systemctl start mariadb

Enable MariaDB service to start during every boot.

systemctl enable mariadb

Secure MariaDB Installation

Secure your MariaDB installation with mysql_secure_installation command.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): <== Just Press Enter OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y <== Set Root Password New password: <== Enter New Root Password Re-enter new password: <== Re Enter Root password Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y <== Remove Anonymous User ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y <== Disable remote root login ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y <== Remove test database - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y <== Reload Privilege ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!

Install PHP

By default, Apache web server supports only HTML pages. To have support for PHP, we would need to install the PHP package along with support for the MariaDB / MySQL database.

PHP 5.4 (End Of Support)

The PHP version (v5.4) available in OS repository is already the end of support. If you still wish you install v5.4, use the below command to install it.

yum install -y php php-mysqlnd

PHP 7.3

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

yum install -y

Now, install PHP v7.3 with the following the command

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

Restart the Apache web service after the installation of the PHP.

systemctl restart httpd

Test LAMP Stack

Place a .php file on to the default directory of the Apache.

vi /var/www/html/helloworld.php

Copy/paste below lines into the helloworld.php file.

    <title>PHP Test</title>
    <?php echo '<p>Hello World</p>'; ?> 

Visit the following web address on your web browser.




You should see the Hello World page.

Test LAMP Stack


You have successfully installed LAMP Stack on CentOS 7. Consider installing phpMyAdmin on CentOS 7 to manage MariaDB / MySQL database servers. Also, you can install Let’s Encrypt SSL certificate in Apache on CentOS 7 for secure communication.

comments powered by Disqus