Verified and Tested 05/29/15

Introduction

This how-to will help you with your LEMP installation in Arch Linux so that you can successfully run a high available solid platform for your web environment. LEMP is simply a software bundle that consists of 4 components that work together to form a powerful web server. Linux (L) is the core of the platform which will sustain the other components. Nginx (E) is used for the web service. MySQL (M) is used for database management, and PHP (P) is used as the file programming language.

Prerequisites

You need a Arch Linux server that is configured with a static IP address. If you do not have a server already, please visit our Cloud Hosting page and spin up a reliable solid state cloud server in under 30 seconds.

Getting Started

To get started, login to your Arch Linux server via SSH or through the VNC Console here. Atlantic.Net Cloud servers are setup as minimal installations in order to avoid having unnecessary packages from being installed and never used. If some software packages that you’re used to using aren’t installed by default, feel free to install them as needed.

Let’s start make sure that your server is fully up-to-date.

sudo pacman -Syu

With the server up-to-date, we can continue the process and install LEMP on your server.

Install Nginx On Arch Linux

We must first begin by installing Apache with the following command:

sudo pacman -S nginx

Start the Nginx service with the following command:

sudo systemctl start nginx.service

To edit the main Nginx configuration file for one or many websites according to your preference, they are configured in the following directory:

sudo nano /etc/nginx/nginx.conf

You can now verify that Apache is installed correctly by typing http:// and your IP address on your browser.

http://YOUR.IP.ADD.RESS (To get your servers IP Address type the following command:)

curl -s icanhazip.com
This is the default page after Installing Nginx on a LEMP Stack Arch Linux Server

This is the default page after Installing Nginx on a LEMP Stack Arch Linux Server

Restart the Nginx service so the changes can take affect on your system.

sudo systemctl restart nginx.service

Install MySQL On Arch Linux

We then would like to continue by installing MySQL. However, in Arch Linux MySql is replaced with MariaDB. So, after running the following MySql command hit enter to select 1 then Enter, then confirm your installation by tapping Enter.

sudo pacman -S mysql

After the install, you must run the following command to fully complete the installation.

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

Make sure that the MySql/MariaDB service is on with the following command before proceeding:

sudo systemctl start mysqld.service

To ensure the security of the default settings of MySQL/MariaDB, continue with the command below:

sudo mysql_secure_installation

Note: When prompt with “Enter current password for root” hit enter for none then Y(Yes) to set MYSQL password. You will then be prompted with a series of questions. Simply type Y for yes on all of them, see the screen shot below:

This is the secure installation of screen when installing MySql on an Arch Linux LEMP Stack server

This is the secure installation of screen when installing MySql on an Arch Linux LEMP Stack server

Install PHP On Arch Linux

Finally, we will conclude the the LEMP Stack by installing PHP with the following command:

sudo pacman -S php-fpm

Make sure that PHP has started with the following command:

sudo systemctl start php-fpm.service

We must make so changes to the PHP configuration file so the specified LEMP module is activated.enabled:

sudo nano /etc/php/php.ini

Using  the Ctrl+w in your text editor(nano) locate the following line and remove the semicolon to activate

;extension=mysqli.so

Now we can go ahead and configure the Nginx configuration file so that it can recognize PHP files.

sudo nano /etc/nginx/nginx.conf

The following instructions are crucial and must be completed so  PHP and Nginx to work correctly. Locate the following line #location ~ \.php$ { using Ctrl+w, tap enter to create a space in between the # and paste the following code in between:

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

Fantastic! You can now save the file and restart Nginx and PHP so all your configuration take effect.

sudo systemctl restart nginx.service

In order to verify and test the installation, create a test PHP file in the following directory with the command below:

sudo nano /srv/http/info.php

Insert the following PHP code in the empty file then save and exit:

<?php
phpinfo();
?>

Restart the Apache HTTP service one last time so all the changes take affect.

sudo systemctl restart httpd.service

You can now verify that PHP is installed correctly by typing the following on your browser.
http://YOUR.IP.ADD.RESS/info.php

This is the default page after installing PHP on a LEMP Stack Arch Linux server

This is the default page after installing PHP on a LEMP Stack Arch Linux server

What Next?

Congratulations! You now have a server with a LEMP Stack platform for your web environment. Thank you for following along and feel free to check back with us for further updates.