Install Nginx, MariaDB, PHP7 (LEMP) on Arch Linux Server

In a previous tutorial, I explained how to install Arch Linux on KVM VPS. Now this tutorial will show you how to Install Nginx, MariaDB, PHP7, aka LEMP stack, on Arch Linux server. You can also follow this guide to install LEMP stack on your Arch Linux home computer.

Step 1: Update Arch Linux Server

Before installing any packages on Arch Linux, it’s always a good idea to refresh repository and perform an update first. Enter the following command in terminal to upgrade software.

sudo pacman -Syu

Step 2: Install Nginx

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. That doesn’t necessarily mean nginx-mainline is unstable. In fact, recommends using nginx mainline if you don’t have a strong reason to use the older version.

To install the older version:

sudo pacman -S nginx

This tutorial installs the mainline version.

sudo pacman -S nginx-mainline

By default, the above two commands will also install geoip and geoip-database package. Once it’s installed, check Nginx status.

systemctl status nginx


● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2016-04-12 13:10:57 CST; 1 day 7h ago
   Main PID: 2010 (nginx)
      Tasks: 2 (limit: 512)
     CGroup: /system.slice/nginx.service
             ├─2010 nginx: master process /usr/bin/nginx -g pid /run/; daemon on; master_process on
             └─2011 nginx: worker process

If it’s not running, start it with systemctl:

sudo systemctl start nginx

Enable Nginx to auto-start when Arch Linux server is booted up.

sudo systemctl enable nginx

Check Nginx version

[[email protected] ~]$ nginx -v
nginx version: nginx/1.11.5

Enter the IP address of your Arch Linux server in the browser address bar, if you see the following text, that means Nginx is running correctly.

Install (LEMP) Nginx, MariaDB, PHP7 on Arch Linux Server

You can check your server’s public IP with the following command.


If you are installing Nginx on your Arch Linux home computer, just type or localhost in the address bar.

Step 3: Install MariaDB

MariaDB is Arch Linux’s default implementation of MySQL since 2013. Oracle MySQL was dropped to AUR. So you see, Arch Linux really wants you to migrate from MySQL to MariaDB.

MariaDB is provided with the mariadb package.

sudo pacman -S mariadb

You need to initialize the MariaDB data directory prior to starting the service. This can be done with mysql_install_db command.

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

Now start MariaDB.

sudo systemctl start mysqld

Check if it’s running:

systemctl status mysqld


● mysqld.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-04-13 21:09:45 CST; 5s ago
  Process: 8373 ExecStartPost=/usr/bin/mysqld-post (code=exited, status=0/SUCCESS)
 Main PID: 8372 (mysqld)
    Tasks: 26 (limit: 512)
   CGroup: /system.slice/mysqld.service
           └─8372 /usr/bin/mysqld --pid-file=/run/mysqld/

Enable MariaDB to auto-start when Arch Linux is booted up.

sudo systemctl enable mysqld

Run the post-installation security script.

sudo mysql_secure_installation

You will be asked to enter your MariaDB root password. Since you have not a MariaDB root password yet, press enter and then set the root password. It’s also good idea to remove test database, anonymous user and disable root remote login.

Check MariaDB version.

[[email protected] ~]$ mysql --version
mysql  Ver 15.1 Distrib 10.1.18-MariaDB, for Linux (x86_64) using readline 5.1

The default main configuration file is /etc/mysql/my.cnf.

Step 4: Install PHP7

The latest version of PHP in Arch Linux repository is 7.0.12 at the time of this writing (October 2016). To install it, run this command:

sudo pacman -S php-fpm

After it’s installed, we need to tell Nginx to run PHP using php-fpm. To achieve that, edit /etc/nginx/nginx.conf file.

sudo nano /etc/nginx/nginx.conf

Find the location ~ \.php$ section (line 65) and modify it to the following.

location ~ \.php$ {
            root           /usr/share/nginx/html;
            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 the file. Then start and enable php-fpm service with the following commands:

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

Step 5: Test PHP Processing

Create a test.php file in the web root .

sudo nano /usr/share/nginx/html/test.php

Add these lines to the file.


Save and close the file. Reload Nginx.

sudo systemctl reload nginx

Now in your browser address, type http://your-server-ip/test.php. You should see all your PHP info. If you are installing LEMP on your Arch Linux desktop or laptop, type or localhost/test.php.

Install (LEMP) Nginx, MariaDB, PHP7 on Arch Linux Server

The test.php file is for testing purpose only. For security reasons you can now remove it.

Enable Extensions

Edit /etc/php/php.ini config file.

sudo nano /etc/php/php.ini

Find the following two lines, remove semicolons to enable these two extensions.


Reload php-fpm service for the changes to take effect.

sudo systemctl reload php-fpm is used to connect PHP with MariaDB/MySQL database. is necessary to display Drupal sites. You may also need to enable imagemagick extension for PHP in order to crop and rotate images in CMS platforms such as WordPress.

Congrats! You have successfully installed Nginx, MariaDB and PHP7 on Arch Linux server!

Rate this tutorial
[Total: 22 Average: 4.7]

report this ad

2 Responses to “Install Nginx, MariaDB, PHP7 (LEMP) on Arch Linux Server

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • If my answer helped you, please consider supporting this site. Thanks :)