Home Arch Linux How to Install LEMP Stack with PhpMyAdmin in Arch Linux

How to Install LEMP Stack with PhpMyAdmin in Arch Linux

Generally, the term LEMP stack can be broken down to Linux, Nginx, MySQL/MariaDB, and PHP modules. All these listed components have a priceless contribution in mimicking the behavior of a production server.

We have a hosting environment (Linux), a web server (Nginx), a database engine/server (MySQL/MariaDB), and a scripting language (PHP).

[ You might also like: How to Install LAMP Stack with PhpMyAdmin in Arch Linux ]

All these elements make up LEMP through which curious Linux-oriented users and developers can be able to host and test the performance of their web-based applications on a production server environment.

This article guide will walk you through the installation and configuration of the LEMP stack on your Arch Linux system so that it can function as a production-ready server system.

Step 1: Update Arch Linux System

This stride ensures that your system does not lose its performance advantage.

$ sudo pacman -Syu
Update Arch Linux
Update Arch Linux

Step 2: Install Nginx in Arch Linux

The first step is to ensure we have a running web server of your choice.

$ sudo pacman -S nginx
Install Nginx in Arch Linux
Install Nginx in Arch Linux

Once Nginx is installed, next, you need to start, enable and check the status of the Nginx server daemon.

$ sudo systemctl start nginx 
$ sudo systemctl enable nginx
$ sudo systemctl status nginx
Check Nginx Status in Arch Linux
Check Nginx Status in Arch Linux

Step 3: Install MySQL in Arch Linux

MariaDB’s open-source attribute and extended community support make it a great database engine candidate.

$ sudo pacman -S mysql
Install MySQL in Arch Linux
Install MySQL in Arch Linux

If you are installing the MySQL database engine for the first time, you will be presented with MariaDB as one of the installation options when the above command executes, go with it.

Next, enable and start the MySQL/MariaDB daemon so that it is continuously active even after system boot.

$ sudo systemctl enable mysqld 
$ sudo systemctl start mysqld 

Also, make sure that the database engine is active and running.

$ sudo systemctl status mysqld
Check MySQL Status in Arch Linux
Check MySQL Status in Arch Linux

If for some reason your database engine fails to start or is not active due to some unknown errors as shown below.

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist

Follow the below steps to fix the above error.

$ su
# cd /var/lib/mysql
# rm -r *
# sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# su dnyce

Start the database engine and check if it is running.

$ sudo systemctl enable mysqld 
$ sudo systemctl start mysqld 
$ sudo systemctl status mysqld

Step 4: Secure MySQL in Arch Linux

Next, you need to run the following security script to secure MySQL installation.

$ sudo mysql_secure_installation

Under this step, you will be able to choose and set your preferred database configuration.

Secure MariaDB Installation
Secure MariaDB Installation

Finally, test root user access to this database. Use the password credential you created from the above step.

$ mysql -u root -p
Connect MySQL Database
Connect MySQL Database

Step 5: Install PHP and PHP-FPM in Arch Linux

PHP is a scripting language and PHP-FPM (PHP FastCGI Processor Manager) is responsible for the speedy performance of a website.

$ sudo pacman -S php php-fpm
Install PHP in Arch Linux
Install PHP in Arch Linux

Enable, start, and check if php-fpm is up and running.

$ sudo systemctl enable php-fpm 
$ sudo systemctl start php-fpm
$ sudo systemctl status php-fpm
Check PHP-FPM Status in Arch Linux
Check PHP-FPM Status in Arch Linux

Step 6: Configure Nginx to Work with PHP

Using a terminal editor of your choice, open the following Nginx configuration file.

$ sudo nano /etc/nginx/nginx.conf

Edit this file to accommodate the following changes.

Configure Nginx to Work with PHP
Configure Nginx to Work with PHP

Restart both nginx and php-fpm.

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

To be certain that PHP, PHP-FPM, and Nginx can work together, create an info.php file on the following directory path and populate it as demonstrated.

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

Add the following code to it.

<?php
phpinfo()
?>

Accessing the info.php file from your browser should display some important information about the PHP version your system is using.

http://localhost/info.php
OR
http://IP-Address/info.php
Verify PHP Info in Arch Linux
Verify PHP Info in Arch Linux

Step 7: Install PhpMyAdmin in Arch Linux

You need a frontend to easily manage your MySQL/MariaDB databases.

$ sudo pacman -S phpmyadmin
Install PhpMyAdmin in Arch Linux
Install PhpMyAdmin in Arch Linux

Link Nginx web server with phpMyAdmin.

  
$ sudo ln -s /usr/share/webapps/phpMyAdmin/ /usr/share/nginx/html/

Restart Nginx and php-fpm.

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

Access phpMyAdmin and try login in:

http://localhost/phpmyadmin
Or
http://IP-Address/phpmyadmin
PhpMyAdmin Login
PhpMyAdmin Login
PhpMyAdmin Dashboard
PhpMyAdmin Dashboard

You now have a fully functional LEMP stack on your Arch Linux distribution. From here, you can comfortably test the performance of your web applications on a production server set up.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

1 thought on “How to Install LEMP Stack with PhpMyAdmin in Arch Linux”

Leave a Reply to Ja Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.