LEMP on Raspberry Pi

Raspberry Pi is a single board ARM based computer developed in the UK by the Raspberry Pi foundation.

Raspberry Pi can be a good web server for development/production environment, setting up a LEMP (Linux NGINX MariaDB PHP) stack on a Raspberry Pi running Arch Linux ARM is easy.

Why Arch Linux ARM?

Arch Linux ARM comes with the latest stable packages and the most recent firmware available for the Raspberry Pi. Arch Linux ARM is also the least memory consuming OS for Raspberry Pi.

I am assuming you have your Raspberry Pi running Arch Linux ARM with access via SSH.

Installing

Updating your Raspberry Pi.

sudo pacman -Syu

Once the update is done, we can now start installing NGINX Web Server.

sudo pacman -S nginx

Installing PHP and php extensions

This will install php-fpm and other PHP extensions. This will also install Composer.

sudo pacman -S php-fpm php-mysql php-sqlite php-xsl php-tidy php-pspell php-mcrypt php-snmp php-mongo php-pear php-composer php-embed php-enchant php-gd php-intl php-ldap php-odbc xdebug

Installing MariaDB (MariaDB 10).

sudo pacman -S mariadb

Now we need to edit our NGINX configuration to pass files through PHP-FPM, I will be using nano but you can use any editor of your choice.

nano /etc/nginx/nginx.conf

Once you have the file opened in nano or you preferred editor, replaces the content with the following code block.

# nginx.conf for 1.6.xworker_processes 1; # Number of nginx process events { worker_connections 5000; } http { server { listen 80; server_name localhost; location / { root /srv/http; index index.php index.html; } location ~ \.php$ { root /srv/http; try_files $uri = 404; fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } } } 

Enabling NGINX. PHP-FPM, MariaDB to run at the startup of the Raspberry Pi

systemctl enable mysqld.service; systemctl enable nginx.service; systemctl enable php-fpm.service

Now we can reboot your Raspberry Pi.

reboot

Your web-root or the place where your PHP files are stored is
/srv/http.

Getting inside the web-root.

cd /srv/http

Now we can create an index.php file

touch index.php

Add the following lines inside the index.php file.

<?php phpinfo(); ?>

Now visit your Raspberry Pi IP address. This should display a web page displaying LEMP stack information and list of PHP plugins and plugin configurations

Done, Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *