Setup LEMP Stack Centos 7 + NGINX + MariaDB + PHP 7 from Scratch

Web Server CNMP

Believe me or not, there are hundred ways to setup web server. I searched and tried many of them on a VPS with 512MB of RAM. Most of them had issue with database, MySQL or MariaDB was die again and again. This one has worked for me for more than a year: CNMP (Centos 7 + NGINX + MariaDB + PHP 7).

Grab a VPS

I’ve used DigitalOcean as VPS provider for a while. Linode is one of my next try since its same price but double RAM. If you have any experience with other VPS providers, please share.

Basic Setup

Setup Firewall

Timezones Configuration

Create a Swap File

This section doesn’t apply for VPS at Linode since they have option to create SWAP file at VPS configuration.

LEMP (Linux, NGINX, MariaDB/MySQL, PHP) Stack Setup

You will see this page if you try to access to your server by using IP

Nginx Test Page

 

Setup Configuration for WordPress Site

Create root directory & Server Block folders

sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled
sudo mkdir -p /var/www/vndeveloper.com/html

Create the First Server Block File

sudo vi /etc/nginx/sites-available/vndeveloper.conf

Create a symlink

sudo ln -s /etc/nginx/sites-available/vndeveloper.conf /etc/nginx/sites-enabled/

Download WordPress source

cd ~
wget https://wordpress.org/latest.zip
sudo unzip latest.zip
sudo mv wordpress/* /var/www/vndeveloper.com/html/

Create Database

mysql -u root -p
CREATE DATABASE dbname;
CREATE USER ‘dbuser’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON dbname.* TO ‘dbuser’@’localhost’;
FLUSH PRIVILEGES;

Wrap it up

That’s it. I know it’s too much if you are newbie to VPS but I hope it is helpful for you. This is how I setup Developer’s Notes (I didn’t cover ssl part yet). Leave a comment or feedback right below.


Leave a Reply