How To ?

How to install LEMP in Ubuntu

A LEMP software stack is a gathering of open source programming that is ordinarily installed together to enable a server to have dynamic sites and web applications. This term is really an acronym which speaks to the Linux working framework, with the ENginx web server (which replaces the Apache part of a LAMP stack).

First, update the system.

sudo apt-get update

Then Install Nginx in your system.

sudo apt-get install nginx

We can make autostart nginx in nginx by

sudo systemctl enable nginx

Then start nginx with the following command

sudo systemctl start nginx

Now check out its status by typing following command in terminal.

systemctl status nginx

Then, you will get following output

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2016-06-04 08:31:23 EDT; 1 day 2h ago
 Main PID: 298 (nginx)
   CGroup: /system.slice/nginx.service
     ├─298 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
     └─299 nginx: worker process

You need to give permission to owner of a root directory

sudo chown www-data /usr/share/nginx/html -R

While typing [ localhost /  Ipaddress ] in your browser. You will saw:

 

Lets Start MariaDB.  MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL.

sudo apt install mariadb-server mariadb-client

Run MariaDB with this command.

sudo systemctl start mysql 

sudo systemctl enable mysql

After install MariaDB will automatically start.

systemctl status mysql

OUTPUT:

● mysql.service - LSB: Start and stop the mysql database server daemon
 Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled)
 Active: active (running) since Wed 2016-04-20 18:52:01 EDT; 1min 30s ago
 Docs: man:systemd-sysv-generator(8)

Now, Run the installation of MariaDB

sudo mysql_secure_installation

OUTPUT

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): ## Press Enter
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]## Press Enter
New password:##  Enter password
Re-enter new password:  ## Re-enter password
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]## Press Enter
 ... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]## Press Enter
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]## Press Enter
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]## Press Enter
 ... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Now, Let’s start install PHP

sudo apt install php7.0-fpm php7.0-mbstring php7.0-xml php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl

Start PHP

sudo systemctl start php7.0-fpm

After this, check status in the terminal.

systemctl status php7.0-fpm

OUTPUT

● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
 Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor pre
set: enabled)
 Active: active (running) since Wed 2016-04-20 19:21:05 EDT; 2s ago

Make default Nginx Block.

sudo rm /etc/nginx/sites-enabled/default

Create a new Nginx Block

sudo nano /etc/nginx/conf.d/default.conf

paste the following text in that default.conf file

server {
  listen 80;
  listen [::]:80;
  server_name 12.34.56.78;
  root /usr/share/nginx/html/;
  index index.php index.html index.htm index.nginx-debian.html;

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

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root /usr/share/nginx/html;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }

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

Save and close the file and reload it.

Leave a Reply

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