Installing Nginx MariaDB and PHP in Arch Linux

Installing Nginx MariaDB and PHP in Arch Linux

Installing Nginx MariaDB and PHP in Arch Linux

No Comments on Installing Nginx MariaDB and PHP in Arch Linux

I wanted to reinstall my Arch system, (where did my day go?). I had procrastinated long about it since it would require to reinstall and reconfigure my entire developer setup. (Android studio, Laravel, composer, php etc), but buying a new computer can really get your motivation going. Out with the old partition and in the brand new arch install. With a fresh install in mind, I wanted to start with the web server.

This tutorial will install Nginx MariaDB Php-fpm called a LEMP or LNMP stack. This means we use Linux, Nginx (pronounced Engine x), MariaDB, and PHP-fpm.


Before we start anything, lets update the system

sudo pacman -Syu

Depending on how old your system is, this will take a while. When its done we can proceed with the LEMP stack installation.

1) Installing NGINX

Lets start by installing the web server. We could use Apache and everything would just fine, but in this tutorial we will be looking at install a LEMP stack. Fire up a new terminal and issue this command

sudo pacman -S nginx




Now that the web-server is installed, we should test the server to see if the defaults work. To start the web server

sudo systemctl start nginx.service

sudo systemctl enable nginx.service

then go to and you should see this:


If for some reason there is not anything to display, check that the nginx service is running by using

sudo systemctl status nginx



to change the settings you need to choose your favorite editor, to showcase I just used nano. We will come back to this config file later.

sudo nano /etc/nginx/nginx.conf

2) Installing MariaDB

Next up we need to install the SQL database. As said before, we go with MariaDB. MariaDB is a open source drop in replacement for mySQL database that uses the same statements. The command is still mysql, in Arch linux the default database is just MariaDB, but the pacman command hasn’t changed. You will be asked if you want to install either MariaDB or Percona server. In this tutorial we go with MariaDB.

sudo pacman -S mysql




Now we need to create a administrator user and data directory to store the database in.

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



now enable and start the database

sudo systemctl enable mysqld
sudo systemctl start mysqld

and if there are any issues, check that the database is running correctly with

systemctl status mysqld



Now that the data directory and user have been created and the server started. We need to put up a password for the root user. It will ask some questions, just follow along here and we will get through it.


when you start the script it will ask you for the current password, but since we just installed this database, there is nothing to enter. Just press enter here and continue to the setup the new root password. After the password have been set, you will be asked more questions. Gene really just press enter until the setup is complete, the default answers are fine for this setup.


In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

3) Installing PHP-fpm

Its time to make the server understand scripting. Lets install PHP

sudo pacman -S php-fpm

When the php have installed, we need to tell our nginx server to use it. lets go back to the conf file and change some stuff.

sudo nano /etc/nginx/nginx.conf



Depending on your setup, it might be easier to use a gui editor, but for showcasing i just contuinue with nano. As you can see in the above picture, the default conf file includes the section, just commented out. I just made a new line and pasted the code.

location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
root /usr/share/nginx/html;
include fastcgi.conf;

save the conf file, start and enable php-fpm

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

Enable PHP Nginx


The easiest test to see if its working is to create a simple php script with the phpinfo() function.

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

and write




Safe and close the php file and restart teh nginx server.

systemctl restart nginx

When everything is said and done. you should go to and see this



if you see this, this means that you have followed the tutorial correctly and now have a working nginx server with MariaDB and PHP

for more detailed instructions try the arch wiki where i got most of my information to make this tutorial.


Martin Jørgensen

Martin Jørgensen

Got my degree from EAL in 2012 as an IT-Technologist with specialty in network. I enjoy living in a century where I can earn a living doing my hobby. Material I publish here are often part of my small projects.
Martin Jørgensen

Latest posts by Martin Jørgensen (see all)

Related Posts

Back to Top