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
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
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
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
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
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.
Finally, test root user access to this database. Use the password credential you created from the above step.
$ mysql -u root -p
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
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
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.
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
Step 7: Install PhpMyAdmin in Arch Linux
You need a frontend to easily manage your MySQL/MariaDB databases.
$ sudo pacman -S phpmyadmin
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
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.
Getting a 404 error when trying to load phpmyadmin.