How To – Installation of Linux, Apache, MariaDB, PHP (LAMP Stack) on CentOS 9 Stream


LAMP is an acronym for Linux, Apache, MariaDB/MySQL & PHP. A LAMP Stack hosts dynamic websites and web apps. Its Windows counterpart is WAMP, the only difference being the Operating System. Functions of services making up a LAMP Stack are as follows:


1. Update your system packages

Suppose you are installing Apache on a fresh CentOS 9 Server. You need to update the software repository and packages on the system.

yum -y update

2. Installation of Apache Web Server

Now we will install Apache on our CentOS Server using the following command.

yum -y install httpd

After the installation is complete, start and enable the Apache Service.

systemctl start httpd
systemctl enable httpd

Open your browser and type http://YOUR-IP-ADDRESS or http://YOUR-DOMAIN-NAME to verify that Apache has been installed successfully.

3. Installation / Configuration of MariaDB Database Server

Once you have completed the installation of Apache, you can go ahead with the installation of MariaDB. Install MariaDB using the default YUM repository in CentOS 9.

yum -y install mariadb-server mariadb

Start and enable the MariaDB Service.

systemctl start mariadb
systemctl enable mariadb

3.1 Secure your MariaDB Service

The default installation of MariaDB is insecure. You can secure MariaDB with a script known as mysql_secure_installation.


On running the script you will be asked a series of interactive questions. Respond as below:

3.2 Creation of Database

After securing MariaDB, you may create your first database. Login to MariaDB using the password you assigned earlier.

mysql -u root -p

You may now create the database using the following command.

create database [DATABASE NAME];

3.3 Creation of MariaDB User / Assign Database Permissions

Now you can create a user and assign it permissions over the databases you just created.

GRANT ALL ON tuxpedia.* TO 'tuxpedia'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

After installation of PHP, you may start using the database created above for your application.

4. Installation of PHP

Now, you may install PHP using the default YUM repository. Furthermore, you will also need to install an extension php-mysqlnd which is required for PHP to interact with MariaDB / MySQL.

yum -y install php php-mysqlnd

Now, restart Apache Server to enable PHP Processing.

systemctl restart httpd

4.1 Testing PHP on Apache Server (Optional)

Next, you can test if your Apache Server is processing PHP properly.

echo "<?php phpinfo(); ?>" > /var/www/html/info.php

The above command creates a file which contains a function to display information regarding the PHP installed on your system. To access it, you can open the browser and type http://YOUR-IP-ADDRESS/info.php . Furthermore, if you have an A record configured, you can open it via http://YOUR-DOMAIN-NAME/info.php.

5. Conclusion

You have successfully completed the installation of LAMP Stack on your CentOS 7 Server. Now you can write your own PHP content OR you may install any PHP application and connect it with your Database Server.

6. Setup a LAMP Stack on CentOS 9: YouTube Video

Exit mobile version