In this guide, we are going to learn how to install LEMP on Manjaro Linux. LEMP is a common stack to developers, using it to for testing and hosting web applications. LEMP is an abbreviation for Linux, Nginx (pronounced as Engine X) MariaDB / MySQL and PHP.

  • Nginx has been used due to its high performance and stability, as used in high traffic sites.
  • MariaDB / MySQL are open source database Engines for storing and managing website data. MariaDB is a fork of MySQL and is mostly preferred.
  • We then have PHP (hypertext pre-processor) which is a server-side scripting language used for developing dynamic web pages. We are going to install each of the components that make up LEMP stack on Manjaro Linux and test their functionality.

Step 1: Install nginx web server.

Let us first update our system packages before we carry out any installation.

sudo pacman -Syy

Install nginx on Manjaro Linux by running the command below:

sudo pacman -S nginx

Once Nginx has been installed, start it and enable it to start on system boot.

sudo systemctl start nginx
sudo systemctl enable nginx

Confirm nginx status

sudo systemctl status nginx

If running you should get the below output

Also test it from the browser by inputting <your-server-ip> or localhost. You should get Nginx welcome page as shown below:

At this point, nginx has been successfully installed on Manjaro Linux.

Step 2: Install MariaDB on Manjaro Linux

Let us proceed to install the next LEMP stack component which is MariaDB. Run the command below:

sudo pacman -S mariadb

Next, initialize the MariaDB data directory and create system tables as shown below:

$ sudo mysql_install_db –user=mysql basedir=/usr –datadir=/var/lib/mysql

Now start and enable mariadb.

sudo systemctl start mariadb
sudo systemctl enable mariadb

And confirm mariadb status for a successful installation.

sudo systemctl status mariadb

The output should be as below

Secure mariadb installation and set root password. Run the command below:

sudo mysql_secure_installation

Answer the prompts as shown:

Enter current password for root (enter for none): Just press Enter
Set root password? [Y/n] Y 
New password:  New-root-password
Re-enter new password: Re-enter New-root-password
Remove anonymous users? [Y/n] Y 
Disallow root login remotely? [Y/n] Y 
Remove test database and access to it? [Y/n] Y 
Reload privilege tables now? [Y/n] Y 
Thanks for using MariaDB!

To connect to MySQL, you run the below command and provide the password you set above.

$ mysql -u root -p 

Having connected to mysql run the below commands to create a db and a user for our web application databases.

create database mydb;
create user 'mydbuser'@'localhost' identified by ‘mypassword’;
grant all privileges on mydb.* to ‘mydbuser’@localhost’ identified by ‘mypassword’;
flush privileges;
exit;

Connect to MySQL with a user

In order to connect to MySQL with the above created user, issue the below command:

$ mysql -u mydbuser -p 

Provide the password you set above.

Step 3: Install PHP and PHP-FPM on Manjaro Linux

PHP-FPM is a short for PHP FastCGI Process Manager. It is a handy web tool that speeds up a website’s performance. It equips your webserver with the ability to handle a huge volume of network traffic simultaneously. Install PHP-FPM with the below command:

sudo pacman -S php php-fpm

After installation is complete, start and enable php-fpm to start on boot with the below commands:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Now confirm status is pfp-fpm is actually running:

$ systemctl status php-fpm

The output should be as shown below:

Enable nginx to use php-fpm.

We need to make a few modifications to nginx configuration file. Open the file with your preferred editor and make the changes as shown below:

$ sudo nano /etc/nginx/nginx.conf

Add the content as shown after ‘location’ contents.

location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
root /usr/share/nginx/html;
include fastcgi.conf;
} 

The file should appear as in the screenshot.

Save the file and restart both Nginx and PHP-FPM for the changes to come into effect.

sudo systemctl restart nginx
sudo systemctl restart php-fpm

Let us verify that PHP-FPM can serve nginx web pages by creating an info.php file in the /usr/share/nginx/html/ path

$ sudo nano /usr/share/nginx/html/info.php

Append the following lines and save the file

<?php
phpinfo();
?>

On your browser, launch localhost/info.php or http://<your-server-ip>/info.php. The output should be as shown

Step 4: Configure firewall to allow ports 80 and 443

We need to open ports 80 and 443 to allow external connections. First, let’s install.

$ sudo pacman -S ufw

Now open 80 and 443 through the firewall

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
$ sudo ufw enable

Step 5: Deploy a basic web application with LEMP on Manjaro Linux

First, let us include ‘sites-enabled‘ in nginx configuration.

$ sudo nano /etc/nginx/nginx.conf

Add the following line under http {

include /etc/nginx/sites-enabled/*;

Your nginx.conf http part file should look as below:

Now make directory for sites-enabled in nginx part.

$ sudo mkdir /etc/nginx/sites-enabled

Next, create a file for our web application virtual host.

$ sudo nano /etc/nginx/sites-enabled/example.com.conf

Paste the below content and save the file:

server {
    listen   80;
    server_name  example.com;

    root   /usr/share/nginx/example.com;
    index index.php index.html index.htm;

    location ~ .php$ {
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Let us now create a basic file for our web application.

$ sudo mkdir /usr/share/nginx/example.com
$ sudo nano /usr/share/nginx/example.com/index.html

Add the following content:

<html>
<head>
<title>my site</title>
</head>
<body>
<h1>It Works</h1>
</body>
</html>

Now Restart both php-fpm and nginx:

$ sudo systemctl restart php-fpm
$ sudo systemctl restart nginx

Test your LEMP configuration. On your browser, type http://<your-server-ip>/ <your-host-name> to load the web application. If your LEMP is successfully configured, your application should load as below.

You have successfully installed LEMP stack on Manjaro Linux. Enjoy your development and remember to check more interesting Linux guides below:

Learning Material:

$15.14
$151.37
in stock
Udemy.com
(179724)
$15.14
$151.37
in stock
Udemy.com
(62323)
$15.14
$151.37
in stock
Udemy.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here

one × 1 =