Bobcares

How to install LEMP stack on Ubuntu 18.04?

by | Feb 20, 2020

Are you looking on to set up the LEMP stack in Ubuntu 18.04? We can help you with it.

LEMP stack is a set of open-source software that allows users to create websites and web applications.

It involves installing an Nginx web server, MySQL database server together with PHP in a Linux OS.

At Bobcares, we get requests to setup LEMP stack in servers, as a part of our Server Management Services.

Today, let’s see how our Support Engineers setup the LEMP stack in Ubuntu 18.04.

 

What is a LEMP Stack?

LEMP stack is the acronym for Linux (E)Nginx MySQL PHP. This is a set of open-source software.

This stack of software allows one to create a web application and web pages.

Here we will take Linux (Ubuntu 18.04) OS and install Nginx webserver. Also, we use MySQL for database management and PHP for dynamic data processing.

Now let’s see how to set up a LEMP stack in an Ubuntu 18.04 for web application development.

 

How to setup LEMP stack in Ubuntu 18.04?

Here is how our Support Engineers install Nginx, MySQL, and PHP in Ubuntu 18.04.

Initially, we take an Ubuntu 18.04 server which has a UFW firewall and SSH installed in it.

However, before installing the LEMP stack, we make sure to update the server using the command,

apt update
apt upgrade

After updating and upgrading the packages, we can start the installation.

 

1. Installing Nginx in Ubuntu 18.04

Initially, we begin with the Nginx installation. Nginx is open-source software that can be used as a web server, reverse proxy, load balancer, etc. So, to install Nginx, we use the command,

apt install Nginx

After installing Nginx we have to allow connections via the firewall. For this, we make use of the command,

ufw allows 'Nginx HTTP'

Hence, after allowing the Nginx over ufw, the status appears as,

LEMP stack ubuntu 18.04.

Now to check the Nginx installation, we access the IP via a browser. In the case of a successful installation, it displays the Nginx default page.

 

2. MySQL for database management

To manage the data in a web application, we need a database management system. So to install MySQL we use the command,

apt install mysql-server

Additionally, we can use the mysql_secure_installation command to secure the installation.

Usually, this allows a user to set a secure root password and also prompt to remove the anonymous user.

Later configure the database software by answering Yes/No for the queries.

 

3. Installing PHP in Ubuntu 18.04

A website needs PHP for generating dynamic content. Hence we install PHP-FPM using the command,

apt install php-fpm php-mysql

Here we also install a helper package php-mysql to communicate with a database backend. Avoiding this step can create errors when trying to use database back-end.

Additionally, to check if the PHP is working, we create a PHP info page. We create it in the default location of Nginx.

So if we access the server IP via a browser it displays the PHP info page.

However, publically displaying the phpinfo() results of the server is a security risk. So, after verifying the PHP configuration, our Dedicated Engineers always remove this to prevent a possible malicious attack.

Now the LEMP stack installation is complete.

 

4. Configure Nginx to use PHP in Ubuntu 18.04

Finally, we need to configure Nginx so that it uses the PHP for creating dynamic content.

For this, we need to create a configuration file for the required domain and create the corresponding configuration.

In Nginx, we need to keep the default configuration in /etc/nginx/sites-available/. So create a file for the domain.

nano /etc/nginx/sites-available/domain_name.com

It is this file that holds the configuration. A sample configuration for domain_name.com appears as,

server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name domain_name.com;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}

Later we re-check the new configuration and reload Nginx.

 

[Need assistance in setting up LEMP stack in Ubuntu 18.04? – We can help you.]

 

Conclusion

So far, we saw how to install the LEMP stack in Ubuntu 18.04. Today, we saw how our Support Engineers configure Nginx to make use of PHP to build web applications.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF