When setting up a LEMP stack (Linux, Nginx, MariaDB, and PHP), MariaDB serves as the database management system that powers your websites and applications. Known for its reliability, performance, and open-source roots, MariaDB is an excellent alternative to MySQL and is widely adopted in hosting environments.

In this guide, we’ll walk through the process of installing and securing MariaDB on AlmaLinux OS as part of a LEMP setup. Whether you’re deploying a personal project or managing production workloads, these steps will ensure that your database is installed and configured properly.

Why MariaDB for LEMP?

MariaDB is a relational database system created as a community-driven fork of MySQL. It offers excellent compatibility with MySQL while also introducing performance improvements and advanced features. For web hosting environments, MariaDB provides security, scalability, and stability — making it a natural choice for powering websites and applications that require efficient database management.

When paired with Nginx and PHP in a LEMP stack, MariaDB delivers a complete, open-source platform capable of handling anything from simple blogs to enterprise-level applications.

Step 1: Update Your Server

Before beginning the installation, log in to your AlmaLinux server as root via SSH. You can use any SSH client, such as Bitvise or PuTTY. Once connected, update your server’s package repository with the following command:

dnf update -y

This ensures you have the latest software packages and security fixes installed before moving forward.

Step 2: Install MariaDB

Next, install the MariaDB server package by running:

dnf install mariadb-server -y

This command installs the latest stable release of MariaDB available from the AlmaLinux repository.

Step 3: Start and Enable MariaDB

Once installed, start the MariaDB service and enable it to launch automatically at system boot with this command:

systemctl start mariadb && systemctl enable mariadb

This guarantees that MariaDB will always start without manual intervention, even after a server reboot.

Step 4: Verify MariaDB Status

Check that the service is running correctly by executing:

systemctl status mariadb

If successful, the status will display as “active,” confirming that MariaDB is running. To exit the status screen, press the q key.

Step 5: Secure MariaDB

Out of the box, MariaDB ships with a default configuration that should be hardened before use in a production environment. To do this, run the MariaDB secure installation wizard:

mysql_secure_installation

This interactive script will guide you through steps such as setting a root password, removing anonymous users, disabling remote root logins, and deleting test databases. Following these prompts will significantly improve the security of your database.

Step 6: Log In to MariaDB

Finally, log in to your MariaDB server as the root user with the password you set during the secure installation process:

mysql -u root -p

After entering your credentials, you’ll gain access to the MariaDB shell, where you can begin creating and managing databases for your applications.

Conclusion

With these steps, you’ve successfully installed and secured MariaDB on AlmaLinux OS as part of your LEMP stack. Your server is now equipped with a powerful and efficient database system capable of handling dynamic applications and high-traffic websites.

At RackNerd, we provide high-performance VPS and dedicated server solutions optimized for running LEMP stacks and other hosting environments. Whether you’re a developer experimenting with new projects or a business deploying mission-critical applications, our hosting plans deliver the stability and scalability you need — backed by 24×7 support.

Ready to start building with confidence? Explore our hosting options today at racknerd.com.

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Logo
Reseller Hosting
Create your new income stream today with a reseller account
Logo
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Logo
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.
Logo

Leave a comment

Your email address will not be published. Required fields are marked *