RackNerd Billboard Banner

How to Install Nginx, PHP, MariaDB, and PhpMyAdmin (LEMP) on Arch Linux

If you’re running Arch Linux and want a fast, reliable web stack, the LEMP setup is a great choice.
LEMP stands for Linux, Nginx, MariaDB, and PHP, and it’s a lightweight alternative to the more common Apache-based stacks.

In this guide, we’ll walk through installing and configuring:

  • Nginx – web server
  • PHP – dynamic content
  • MariaDB – database
  • phpMyAdmin – database management interface

Step 1 – Update Your System

Before installing anything, make sure your system is up to date:

sudo pacman -Syu

Step 2 – Install Nginx

sudo pacman -S nginx

Enable and start Nginx:

sudo systemctl enable nginx
sudo systemctl start nginx

Check if it’s running by visiting http://localhost in your browser. You should see the “Welcome to Nginx” page.


Step 3 – Install PHP (PHP-FPM) and Extensions

We’ll use PHP-FPM for better performance with Nginx.

sudo pacman -S php php-fpm php-gd php-intl php-mysql php-curl php-zip

Enable and start PHP-FPM:

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

Edit the PHP-FPM config to use the unix socket:

sudo nano /etc/php/php.ini
  • Uncomment or set:
cgi.fix_pathinfo=0

Then edit PHP-FPM pool config:

sudo nano /etc/php/php-fpm.d/www.conf
  • Change:
listen = /run/php-fpm/php-fpm.sock
  • Ensure:
listen.owner = http
listen.group = http
listen.mode = 0660

Restart PHP-FPM:

sudo systemctl restart php-fpm

Step 4 – Configure Nginx to Work with PHP

Open the default server block:

sudo nano /etc/nginx/sites-available/default

If sites-available doesn’t exist (Arch often keeps configs in /etc/nginx/conf.d), create a file:

sudo nano /etc/nginx/conf.d/default.conf

Example configuration:

server {
    listen 80;
    server_name localhost;
    root /usr/share/nginx/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Test the Nginx configuration:

sudo nginx -t

Reload Nginx:

sudo systemctl reload nginx

Step 5 – Install and Configure MariaDB

sudo pacman -S mariadb

Initialize the database:

sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Enable and start MariaDB:

sudo systemctl enable mariadb
sudo systemctl start mariadb

Run the secure installation script:

sudo mysql_secure_installation

Follow the prompts to set a root password and secure the server.


Step 6 – Install phpMyAdmin

sudo pacman -S phpmyadmin

Link phpMyAdmin into your Nginx document root:

sudo ln -s /usr/share/webapps/phpMyAdmin /usr/share/nginx/html/phpmyadmin

Edit your PHP configuration for phpMyAdmin support:

sudo nano /etc/php/php.ini

Uncomment or add:

extension=mysqli
extension=pdo_mysql

Restart PHP-FPM and Nginx:

sudo systemctl restart php-fpm
sudo systemctl restart nginx

Now you can access phpMyAdmin at:

http://localhost/phpmyadmin

Step 7 – Test PHP

Create a test file:

echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php

Open:

http://localhost/info.php

If you see the PHP info page, PHP is working.


Step 8 – Final Security Tips

  • Remove the info.php file after testing:
sudo rm /usr/share/nginx/html/info.php
  • Use strong passwords for MariaDB and phpMyAdmin.
  • Consider enabling HTTPS with Let’s Encrypt.

Conclusion

You now have a fully working LEMP stack with phpMyAdmin on Arch Linux.
This setup is fast, lightweight, and ready for your PHP-based projects.

If you run into permission errors, check file ownership:

sudo chown -R http:http /usr/share/nginx/html

That’s it — you’re ready to start building and deploying web apps.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
RackNerd Billboard Banner
© 2025 Computer Everywhere
Your Everyday Guide to the Digital World.
Terms of Service | Privacy Policy
Copy link