Posted on March 26, 2020
How to setup and install a LEMP stack
Today I’m going to show you how to setup a LEMP stack. LEMP stands for LINUX, NGINX, MYSQL, PHP. LEMP is a great stack to use for WordPress and various other applications. It leverages Nginx and Php-Fpm for fast processing.
- Linux knowledge ( Beginner to Intermediate)
- Linux server – we will be working on a CentOs 7 server
- Root access ( all code will be on root unless explicitly stated)
Install epel and Remi repository
Installing the epel and Remi repository will allow us to download extra packages that are needed for installing the LEMP stack. Remi repository will allow us to install the latest PHP-FPM7.3.
$ yum install epel-release $ yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Install and enable Nginx
$ yum install nginx $ systemctl start nginx.service $ systemctl enable nginx.service
Install and enable mariadb-server
$ yum install mariadb-server $ systemctl start mariadb.service $ systemctl enable mariadb.service
We are installing yum-utils so we can utilize the tool yum-config-manager. yum-config-manager will allow us to enable/disable a repo.
$ yum install yum-utils
Disable php5.3 and enable php7.3
We will then disable php5.3 and enable php7.4 to make sure we have the correct php versions.
$ yum-config-manager --disable remi-php54 $ yum-config-manager --enable remi-php73
Install php7.3 with all the necessary modules
A very long command but this will install php7.3 with all the needed modules.
$ yum -y install php php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdo php-pecl-apcu php-pecl-apcu-devel
Ensure correct permissions for your PHP folder
We will be changing this to user root and group nginx since they will be talking to each other.
$ chown -R root:nginx /var/lib/php
Enable and start php-fpm
$ systemctl enable php-fpm $ systemctl start php-fpm
Setting up a LEMP stack is not difficult to do. There are just a few things you have to look out for. I hope this tutorial helped you setup your LEMP stack. Please leave a comment for suggestions!