How to Install LEMP stack in Manjaro Linux

Dimitris Damtsas
4 min readDec 2, 2018

--

Manjaro Linux is one of the greatest Linux flavors out there. With tons of customization options and the power of bleeding edge AUR (Arch User Repository),this distro never seize to amaze Linux users, from beginners to pros . Although truth be told,beginners should be a little cautious regarding the AUR capabilities.

In this post we will install LEMP stack ,step by step. LEMP stands for Linux-NGINX-MySQL-PHP.

For more info regarding the capabilities of this stack and what is the difference between this and LAMP you can check this out.

Prerequisites :

  1. Manjaro Linux installed on your pc
  2. No LEMP nor LAMP installed on your pc
  3. Basic understanding of linux commands
  4. A cup of your favourite coffee

First of all we must update our system,in case we missed an important package:

sudo pacman -Syu

Then we begin with the installation of every package needed.

  1. NGINX :
sudo pacman -S nginxsudo systemctl start nginx.servicesudo systemctl enable nginx.service

The above commands installed ,started and enabled Nginx to start on every boot,in that order.To check if everything works properly,reboot your pc and type:

sudo systemctl status nginx.service

and you should get this message on your terminal:

Open your favorite browser and type http://localhost/. You should see the welcome page from NGINX. Well done!

2.SQL Server

Next,we’ll install the SQL server. We will use MariaDB for this tutorial, an open-source relational database management system:

sudo pacman -S mysql

You'll then have the option to choose between two repositories that provide the requested package:

Pressing enter and Y when requested will begin the installation of mariadb.Next,before starting and enabling the mariadb service,we must initialize and create the system tables:

sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Finally we will start and enable mariadb service:

sudo systemctl start mysqldsudo systemctl enable mysqld

To check if everything working properly we can test it by typing:

sudo systemctl status mysqld.service

Before we continue to the third part,we must set our root pasword ,to sequre Mysql server . We simply type:

mysql_secure_installation 

And we are greeted we the MariaDB Secure installation screen :

We simply then type enter in the first prompt and in the second one we set our root password by typing Y. We then type y (which equals to yes,obviously) until we get a message saying “Thanks for using MariaDB!”

3. PHP & PHP-FPM installation

PHP is a server-side scripting language as well as general-purpose programming language. It is currently in version 7.2.12 and is used by a lot of companies including Facebook.We will install it alongside with PHP-FPM a FastCGI Process Manager and php-gd extension:

sudo pacman -Sy php php-fpm php-gd

We then starting the php-fpm service by typing:

sudo systemctl start php-fpm

To run LEMP without warnings or problems we must make a few changes on the php cofnidguration file. So we type :

sudo nano /etc/php/php.ini

And we change the values by uncommenting :

extension=gd

extension=pdo_mysql
extension=mysqli

Next we will edit the nginx.conf,so it can serve our PHP files :

sudo nano /etc/nginx/nginx.conf

And we add these lines highlighted with bold letters:

server_name localhost;

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

To test if our server can actually serve php files we will create a a php file with the info of our currently installed php:

sudo nano /usr/share/nginx/html/info.php<?php phpinfo(); ?>

We save it and we are restarting our Nginx and PHP-FPM service by typing:

sudo systemctl restart nginx.service


sudo systemctl restart php-fpm

Finally to see if everything is working we our pointing our web browser to http://localhost/info.php :

4. phpMyAdmin installation

phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web. phpMyAdmin supports a wide range of operations on MySQL and MariaDB in our case.We will install it by typing:

sudo pacman -S phpmyadmin

We then must create a symlink so we can access phpMyadmin:

sudo ln -s /usr/share/webapps/phpMyAdmin/ /usr/share/nginx/html/sudo systemctl restart nginx.servicesudo systemctl restart php-fpm

Then point your browser to http://localhost/phpMyAdmin/

And that was it. You now have successfully installed LEMP and you are ready for awesome web development projects.

--

--

Dimitris Damtsas

How To’s,ideas and everything that swivels around the mind of someone who’s between woodworking and web development. Located in Greece.