Skip to content

Instantly share code, notes, and snippets.

@genialkartik
Last active July 4, 2024 00:05
Show Gist options
  • Save genialkartik/d21e0294e35fa0f36400a2b0a3c244f5 to your computer and use it in GitHub Desktop.
Save genialkartik/d21e0294e35fa0f36400a2b0a3c244f5 to your computer and use it in GitHub Desktop.
How to install LEMP [Linux , MariaDB, Php-Fpm] Stack and phpMyAdmin on Arch Linux (Manjaro)

LEMP installation on Arch Linux

It’s always a good idea to refresh repository and perform an update first.

Open terminal and execute:

sudo pacman -Syu

The Arch Linux repository contains two versions of

Nginx Web server: nginx and nginx-mainline. nginx is the more stable and older version and nginx-mainline is the latest version. You can install nginx In this Gist, I’m going to explain how you can install nginx-mainline

sudo pacman -S nginx-mainline

After installed nginx, start & check nginx status:

sudo systemctl start nginx
sudo systemctl status nginx

If nginx is not running, start it:

sudo systemctl start nginx

Enable nginx to start at bootup

sudo systemctl enable nginx

Check nginx has started or not:

sudo systemctl status nginx

Test nginx service:

sudo nginx -t

If you see a warn like that:

[warn] 15117#15117: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size

Open nginx configuration file and edit sudo nano /etc/nginx/nginx.conf

Add these lines inside http block:

types_hash_max_size 4096;
server_names_hash_bucket_size 128;

Save and exit (CTRL+X, Y, Enter). Reload and test nginx:

sudo systemctl reload nginx
sudo nginx -t

Check nginx version:

nginx -v

Install MariaDB/MySQL

sudo pacman -S mysql

You need to initialize the MariaDB data

directory prior to starting the service: sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Enable MariaDB service:

sudo systemctl enable mysqld

Start MariDB service:

sudo systemctl start mysqld

Check MariaDB service status:

sudo systemctl status mysqld

Run secure installation

and set root password: sudo mysql_secure_installation or (sudo /usr/bin/mysql_secure_installation)

Install PHP 7.2

sudo pacman -S php-fpm

After installed PHP, we need to edit

nginx configuration file: sudo nano /etc/nginx/nginx.conf

Find block below and add index.php

location / { /root /usr/share/nginx/html;
 index index.html index.htm index.php;
}

Find PHP section in configuration file

and edit:

location ~ \.php$ {
            root           /usr/share/www;
            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
}

Save and close nginx configuration file after you have edited (CTRL+X, Y, Enter)

Then start and enable php-fpm service:

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

To test PHP configuration,

create a test.php file in nginx web directory: sudo nano /usr/share/www/test.php (If you don’t have www directory in share folder, first you need to create one: sudo mkdir /usr/share/www)

Reload nginx service:

sudo systemctl reload nginx

Test PHP, open your browser:

http://localhost/test.php or http://127.0.0.1/test.php You must see php version info page

Enable extensions, open php.ini file

sudo nano /etc/php/php.ini

Find these lines and remove semicolons:

;extension=bz2
;extension=curl
;extension=mysqli
;extension=pdo_dblib
;extension=pdo_mysql
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=zip

Save and close php.ini file

Reload php-fpm service for the changes

to take effect: sudo systemctl reload php-fpm

Install phpMyAdmin (PMA)

sudo pacman -S phpmyadmin

Then, create a symbolic link for phpMyaAdmin

system path to Nginx default root path:

sudo ln -s /usr/share/webapps/phpMyAdmin/ /usr/share/www/

Finally restart nginx and php-fpm services:


sudo systemctl restart nginx
sudo systemctl restart php-fpm

LEMP Stack on your Manjaro/Arch Linux is ready.

If you get stuck somewhere or need any help, feel free to contact.

Thanks for Reading.

@jose-zapana
Copy link

Thanks for the Guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment