How to Install PHP and MariaDB on Amazon Linux 2
- Mohammad Abu Mattar
- Cloud Computing
- 24 Oct, 2022
- 03 Mins read
Introduction
We will learn how to set up PHP and MariaDB on Amazon Linux 2 in this tutorial. We will also discover how to set up PHP so that it functions with the Apache web server. We will also discover how to set up MariaDB so that it functions with PHP.
Prerequisites
To follow along with this tutorial, you will need:
- An Amazon Linux 2 EC2 instance with a public IP address.
- A non-root user with sudo privileges.
- A domain name pointing to the public IP address of your EC2 instance.
- Apache web server installed and running. How to Install PHP and MariaDB on Amazon Linux 2.
Installing PHP/MariaDB, setting up MariaDB, and running a basic PHP demo
Step 1 — Installing PHP
PHP is a free and open-source scripting language that is used to create dynamic web pages. It is the most popular web scripting language in the world.
At first, we will enable amazon-linux-extras
so that we can specify the PHP version that we want to install.
Next, we will install PHP.
We will now verify that PHP has been installed.
The output should look like this:
Step 2 — Installing MariaDB
MariaDB is a free and open-source relational database management system (RDBMS) that is used to store data for dynamic web pages. It is a fork of MySQL.
At first, we will install MariaDB.
Next, we will start MariaDB.
We will configure MariaDB so that it starts automatically when the system boots.
We will now secure MariaDB.
You will be prompted to enter the current root password for MariaDB. Press Enter
to continue.
Next, you will be prompted to set a new root password for MariaDB. Enter a new password and press Enter
.
You will be prompted to remove anonymous users. Press Y
and then press Enter
.
You will be prompted to disable remote root login. Press Y
and then press Enter
.
You will be prompted to remove the test database and access to it. Press Y
and then press Enter
.
You will be prompted to reload the privilege tables now. Press Y
and then press Enter
.
Step 3 — Configuring PHP to Work with Apache
At first, we need to restart Apache.
We will create a directory for our PHP files.
Next, we will create a PHP file.
We will add the following content to the file.
We will now open the file in a web browser.
You should see the following output:
Step 4 — Configuring MariaDB to Work with PHP
At first, we will create a database for our PHP files.
Next, we will create a user for our PHP files.
We will grant all privileges to the user.
We will now exit MariaDB.
We will create a PHP file.
We will add the following content to the file.
We will now open the file in a web browser.
You should see the following output:
Conclusion
In this tutorial, we learned how to set up PHP and MariaDB on Amazon Linux 2. We also learned how to set up PHP so that it functions with the Apache web server. We also learned how to set up MariaDB so that it functions with PHP.