How to install LEMP stack (nginx, MariaDB/MySQL and PHP) on CentOS

Posted on
  • Sunday, November 23, 2014
  • by
  • ZULFIANTO
  • in
  • Labels:
  • The LEMP stack is an increasingly popular web service stack, powering mission-critical web services in many production environments. As the name implies, the LEMP stack is composed of Linux, nginx, MariaDB/MySQL and PHP. nginx is a high performance and lightweight replacement of slow and hard-to-scale Apache HTTP server used in the traditional LAMP stack. MariaDB is a community-driven fork of MySQL, with more features and better performance. PHP, a server-side language for generating dynamic content, is processed by PHP-FPM, an enhanced implementation of PHP FastCGI.

    In this tutorial, I demonstrate how to set up the LEMP stack on CentOS platforms. I target both CentOS 6 and CentOS 7 platforms, and point out differences where necessary.

    Step One: Nginx

    As the first step, let's install nginx on CentOS, and do basic configuration for nginx, such as enabling auto-start and customizing the firewall.

    Install Nginx

    Let's install a pre-built stable version of nginx package from its official RPM source.

    On CentOS 7:
    $ sudo rpm --import http://nginx.org/keys/nginx_signing.key
    $ sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    $ sudo yum install nginx
    On CentOS 6:
    $ sudo rpm --import http://nginx.org/keys/nginx_signing.key
    $ sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    $ sudo yum install nginx
    Note that if you do not import the official nginx GPG key before installing nginx RPM, you will get this warning:

    warning: /var/tmp/rpm-tmp.KttVHD: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY

    Start Nginx 

     After installation, nginx does not start automatically. Let's start nginx right now, and configure it to auto-start upon boot. Also, we need to open a TCP/80 port in the firewall so that you can access nginx webserver remotely. All of these are achieved by entering the following commands.

    OnCentOS 7:
    $ sudo service nginx start
    $ sudo chkconfig nginx on
    $ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    $ sudo service iptables save

    Test Nginx

    The default document root directory of nginx is /usr/share/nginx/html. A default index.html file must be already placed in this directory. Let's check if you can access this test web page by going to http://<nginx-ip-address>/

    0 comments:

    Post a Comment

     
    Copyright (c) 2010 Blogger templates by Bloggermint