This article covers installation and configuration of LEMP (Linux + NGINX + MySQL + PHP) on Arch Linux.

Installation

Linux

See this guide.

NGINX

There are 2 versions of NGINX available in the repo: mainline and stable. NGINX blog recommends installing the mainline version. This can be done with:

pacman -S nginx-mainline

MySQL

Install mariadb with:

pacman -S mariadb

PHP

Install php and php-fpm with:

pacman -S php php-fpm

Configuration

  1. Uncomment in /etc/php/php.ini:

    extension=mysqli.so
    
  2. Add a server in NGINX (assuming document root is /srv/http/localhost):

    server {
        listen              80;
        listen              443 ssl;
        server_name         localhost;
    
        root                /srv/http/localhost;
        index               index.php;
    
        location ~ \.php$ {
            include         fastcgi.conf;
            fastcgi_index   index.php;
            fastcgi_pass    unix:/run/php-fpm/php-fpm.sock;
        }
    }
    

    Some people may notice that: in /etc/nginx, there is another file fastcgi_params very similar to fastcgi.conf. The difference is explained here. In general, using fastcgi.conf is recommended because it sets fastcgi parameter SCRIPT_FILENAME for you.

Test

  1. Create document root:

    mkdir -p /srv/http/localhost
    
  2. Add file index.php in document root:

    <?php
    $host = "localhost";
    $user = "root";
    $passwd = "";
    
    $conn = new mysqli($host, $user, $passwd);
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";
    $conn->close();
    ?>
    
  3. Start systemd services:

    systemctl start mysqld
    systemctl start php-fpm
    systemctl start nginx
    
  4. Open browser at http://localhost/. You should be able to see a line:

    Connected successfully