Bobcares

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

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.