How to Install Linux, Nginx, MySQL, and PHP (LNMP Stack) on CentOS

Prerequisites

Deploy a CentOS server

Install nginx

see Nginx

Install MySQL

With the web server up and running, we need to install a database server to allow storage and management of data for dynamic websites. But since the base MySQL is not available in CentOS repositories, we can substitute it with MariaDB, which uses the same commands and table structures.

To install MySQL run the command:

yum install mariadb-server -y

Once installation is done, enable and start MySQL to run during system boot.

systemctl enable mariadb

systemctl start mariadb

Next, we need to secure the database server by removing insecure defaults and setting a new root password through the secure installation script.

mysql_secure_installation

Enter a new root password different from your server’s password and verify the installation by logging in to MySQL.

mysql

Your output will be similar to:

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 13
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> 

The output shows that MariaDB is working perfectly well, and you can create databases and tables through the console.

Install PHP

Run the command below to install PHP and the MySQL module

yum install php php-mysqlnd -y

After installation is complete, restart Nginx to enable PHP and the MySQL module for your server.

systemctl restart nginx

Leave a Reply

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