Deploy LEMP on Arch Linux
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
-
Uncomment in
/etc/php/php.ini
:extension=mysqli.so
-
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 filefastcgi_params
very similar tofastcgi.conf
. The difference is explained here. In general, usingfastcgi.conf
is recommended because it sets fastcgi parameterSCRIPT_FILENAME
for you.
Test
-
Create document root:
mkdir -p /srv/http/localhost
-
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(); ?>
-
Start systemd services:
systemctl start mysqld systemctl start php-fpm systemctl start nginx
-
Open browser at
http://localhost/
. You should be able to see a line:Connected successfully