• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install LEMP Stack on CentOS 7

Written by Admin, Updated On May 7, 2019
centos, lemp, mariadb, mysql, nginx
How to Install LEMP on CentOS 7

LEMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. LEMP stands for Linux OS, with the Nginx (pronounced like “Engine-X”) web server, Data store in a MySQL or MariaDB database, and dynamic content is processed by PHP. In this tutorial, we will show you how to install LEMP stack on CentOS 7.

Prerequisites#

You must logged in with non-root user account with sudo privileges.

Install NGINX#

Nginx is not available in default CentOS 7 repositories so installation is pretty easy. To install the package run the following command:

sudo yum install httpd

Once the installation is finished, you need to start and enable the Apache service by typing:

sudo systemctl start httpd
sudo systemctl enable httpd

You can confirm installation by checking the status of service by below command:

sudo systemctl status httpd

Install MariaDB#

Now we are going to install MariaDB on your CentOS system. To install type following:

sudo yum install mariadb-server
  • If you want to install MySQL instead of MariaDB, check this tutorial How to Install MySQL on CentOS 7.

When the MariaDB installation completed, you should start and enable the service with:

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Also, check the status of service by typing:

sudo systemctl status mariadb.service

Install PHP#

By default, CentOS 7 ships with PHP version 5.4 so we are going to use Remi repository to install PHP 7.2.

Run the following command to install the Remi repository to your system:

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Now you have to install yum-utils package and enable remi repository on your CentOS system using below command:

sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72

Next, install the PHP and required extensions along with it by typing:

sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql

You should now restart the Apache service to take effect. Use below command to restart Apache service:

sudo systemctl restart httpd

Set up Nginx configuration file#

You need to create a directory under the web root /var/www/html with your domain name.

Configuration file for all domains are stored at /etc/nginx/conf.d directory. So we will create configuration file for each domain in this folder. This configuration files are know as Nginx Server blocks and you can refer this tutorial How to Set Up Nginx Server Blocks on CentOS to create these files and add the below lines to it.

server {

    # . . . other code

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Now To take effect of configuration changes you need to reload PHP and Nginx services. Type below command to do it:

sudo systemctl restart php-fpm
sudo systemctl reload nginx

Once it done also check status of Nginx by typing following:

sudo nginx -t

If everything is okay then it will show output as following :

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Verify Installation#

Create a info.php file at /var/www/html/info.php and add below lines to it and save.

<?php
phpinfo();
?>

Now, open your favorite browser and open info.php file with your server public ip address as given below:

http://SERVER_IP_ADDRESS/info.php

If it will show show PHP information page then your installation is successful.

Conclusion#

You have learned how to install LEMP stack on CentOS 7. If you have any questions or suggest don’t forget to leave a comment.

Detailed Tutorials#

  • How to Install Nginx on CentOS 7
  • Install MariaDB on CentOS 7 Server
  • How to Install PHP 7.3, 7.2, 7.1 on CentOS 7
  • Set Up Nginx Server Blocks on CentOS 7

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install LAMP Stack on CentOS 7
Next Article   How to Install phpMyAdmin with Nginx on Ubuntu 18.04

Related Posts

  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023
  • How to Install MySQL on Debian 11

    How to Install MySQL on Debian 11

    November 28, 2022
  • How to Install MySQL on Ubuntu 22.04

    How to Install MySQL on Ubuntu 22.04

    November 27, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook