Skip to content

Web Development

Overview

Stacks for Web Development

Web Servers

Databases & Data stores

Web development - Programming & Frameworks

How do I run DietPi-Software and install optimised software ?

To install any of the DietPi optimised software listed below run from the command line:

dietpi-software

Choose Software Optimised and select one or more items. Finally click on Install. DietPi will do all the necessary steps to install and start these software items.

DietPi software

To see all the DietPi configurations options, review DietPi Tools section.

Return to the Optimised Software list

Stacks for Web Development

DietPi offers an one-click-installation of the following web development stacks:

Meaning of the acronyms LAMP, LASP, LEMP, LESP, LLMP, LLSP

  • OS: L for Linux / DietPi
  • Webserver: A for Apache2, E for Nginx, L for Lighttpd
  • Database: M for MariaDB, S for SQLite
  • Scripting language: P for PHP

All stacks come with PHP caches (APCu and OPcache), being optimized based on a share of the total memory.

Which Web Application Stack is best for you ?

Apache2

  • Memory use = High | Multithreaded = Yes

It is feature-rich and popular. It is recommended for beginners and users who are looking to follow Apache2 based guides.

Nginx

  • Memory use = Medium | Multithreaded = Yes

It is a lightweight alternative to Apache2 and claims4 faster webserver performance compared to Apache2. It is ideal for medium-high traffic situations where Lighttpd will suffer.

Lighttpd

  • Memory use = Low | Multithreaded = Optional - Some drawbacks

It is extremely lightweight and is generally considered to offer the “best” webserver performance on Linux for SBCs (single board computers). It is recommended for users who expect low webserver traffic and/or personal use.

Although the DietPi installation of Lighttpd is set to single threaded, do not be put off by this, in low usage scenarios (<10 users) it will still outperform Nginx and Apache2. Activation of multithreading is described in the Lighttpd package description.

DietPi - Webserver Preference

The DietPi webserver preference screen allows you to choose your favourite webserver for use in DietPi installations. Check more the Web Preference in the Advanced configuration.

MariaDB
It is an open source RDBMS (relational data base management system). It is application compatible to MySQL, i.e. it can be used as a drop in replacement for MySQL. It has more features, fewer bugs, and a better performance compared to MySQL.

SQLite
It is an RDBMS, also compatible to MySQL. It offers a broader language support (i.e. more bindings to programming languages) compared to MariaDB. SQLite has a very small footprint. As drawbacks, it has no multi user capabilities and a couple of SQL features are missing.


How to install ?

DietPi contains the option to choose the web stack of your favourite. Basically choosing the web stack resp. webserver, you have two options within dietpi-software:

  • Selection via Software Optimized or
  • Selection via Webserver Preference

The latter is used only in the case of the first webserver background installation.

DietPi webserver selection software optimized

Using this option you select the complete web stack for installation. Just select the web stack you want to install and do the installation via the Install execution within dietpi-software.

Unless you specifically need a web stack, it is recommended that you allow DietPi to install the default web stack automatically. This ensures compatibility and stability of your system.

DietPi webserver selection webserver preference

Using this option you only select the webserver for use in DietPi installations.
When you select any software for installation that requires a webserver (e.g. Pi-hole, Nextcloud, Webmin, installed via Software Optimized), DietPi will automatically install, configure and optimize your chosen webserver preference. DietPi will also install MariaDB / SQLite as required, depending on your software selections. Basically, you will never need to manually select/install a webserver stack again. DietPi will do it all for you.

No webserver change if already installed

This setting “Webserver Preference* can NOT be changed if an existing webserver is installed on the system.


YouTube video tutorial: DietPi Web Server Tutorial | Host a website from Home | Raspberry Pi.


LAMP Web Stack

LAMP stack is a popular open source web platform commonly used to run dynamic web sites and servers. It is considered by many, as the platform of choice for development and deployment of high performance web applications which require a solid and reliable foundation.

dietpi-webstack-lamp

Access website:

  • URL = http://<your.IP> or http://<your.host.name>
  • Local directory = /var/www

Access PHP info page:

  • URL = http://<your.IP>/phpinfo.php

Access memory cache info:

  • APCu = http://<your.IP>/apc.php
  • OPcache = http://<your.IP>/opcache.php

For database, check MariaDB details.

Let’s Encrypt is highly recommended - see here how to install. This will automate the creation and setup of your free SSL cert.

Alternative way: Manually enable HTTP/SSL by installing a self-signed SSL certificate

This method is recommended only in case Let’s encrypt is not a viable option.

Step 1. Create key

mkdir -p /etc/apache2/ssl
openssl req -x509 -nodes -days 1000 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Step 2. Enable SSL config and restart Apache

chmod 600 /etc/apache2/ssl/*
cat << _EOF_ > /etc/apache2/sites-enabled/default-ssl.conf

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
            ServerAdmin webmaster@localhost
            ServerName example.com:443
            DocumentRoot /var/www

            LogLevel error
            ErrorLog ${APACHE_LOG_DIR}/error.log
            #CustomLog ${APACHE_LOG_DIR}/access.log combined

            SSLEngine on

            SSLCertificateFile /etc/apache2/ssl/apache.crt
            SSLCertificateKeyFile /etc/apache2/ssl/apache.key

            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                            SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                            SSLOptions +StdEnvVars
            </Directory>
        </VirtualHost>
    </IfModule>
'_EOF_'

a2enmod ssl
service apache2 restart

Access website:

  • URL = https://<your.IP> or https://<your.host.name>

LASP Web Stack

LASP is a variation of the popular open source LAMP web stack, providing SQLite instead of MariaDB.

SQLite is an embedded relational database engine. It is popular and together with Apache2 and PHP could be a good candidate for single board computer.

Access website:

  • URL = http://<your.IP> or http://<your.host.name>
  • Local directory = /var/www

Access memory cache info:

  • APCu = http://<your.IP>/apc.php
  • OPcache = http://<your.IP>/opcache.php

Let’s Encrypt is highly recommended - see here how to install. This will automate the creation and setup of your free SSL cert.

Alternative way: Manually enable HTTP/SSL by installing a self-signed SSL certificate

This method is recommended only in case Let’s encrypt is not a viable option.

Step 1. Create key

mkdir -p /etc/apache2/ssl
openssl req -x509 -nodes -days 1000 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Step 2. Enable SSL config and restart Apache

chmod 600 /etc/apache2/ssl/*
cat << _EOF_ > /etc/apache2/sites-enabled/default-ssl.conf

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
            ServerAdmin webmaster@localhost
            ServerName example.com:443
            DocumentRoot /var/www

            LogLevel error
            ErrorLog ${APACHE_LOG_DIR}/error.log
            #CustomLog ${APACHE_LOG_DIR}/access.log combined

            SSLEngine on

            SSLCertificateFile /etc/apache2/ssl/apache.crt
            SSLCertificateKeyFile /etc/apache2/ssl/apache.key

            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                            SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                            SSLOptions +StdEnvVars
            </Directory>
        </VirtualHost>
    </IfModule>
'_EOF_'

a2enmod ssl
service apache2 restart

Access website:

  • URL = https://<your.IP> or https://<your.host.name>

LEMP Web Stack

LEMP is a variation of the popular open source LAMP web stack, providing Nginx instead of Apache2 web server.

Nginx is a popular choice, thanks to its lightweight utilization of resources and its flexibility to scale simply even with minimal equipment.

Access website:

  • URL = http://<your.IP> or http://<your.host.name>

Access PHP info page:

  • URL = http://<your.IP>/phpinfo.php

Access memory cache info:

  • APCu = http://<your.IP>/apc.php
  • OPcache = http://<your.IP>/opcache.php

For database, check MariaDB details.

Let’s Encrypt is highly recommended - see here how to install. This will automate the creation and setup of your free SSL cert.

Alternative way: Manually enable HTTP/SSL by installing a self-signed SSL certificate

This method is recommended only in case Let’s encrypt is not a viable option.

Step 1. Create key

mkdir -p /etc/apache2/ssl
openssl req -x509 -nodes -days 1000 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Step 2. Enable SSL config and restart Apache

chmod 600 /etc/apache2/ssl/*
cat << _EOF_ > /etc/apache2/sites-enabled/default-ssl.conf

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
            ServerAdmin webmaster@localhost
            ServerName example.com:443
            DocumentRoot /var/www

            LogLevel error
            ErrorLog ${APACHE_LOG_DIR}/error.log
            #CustomLog ${APACHE_LOG_DIR}/access.log combined

            SSLEngine on

            SSLCertificateFile /etc/apache2/ssl/apache.crt
            SSLCertificateKeyFile /etc/apache2/ssl/apache.key

            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                            SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                            SSLOptions +StdEnvVars
            </Directory>
        </VirtualHost>
    </IfModule>
'_EOF_'

a2enmod ssl
service apache2 restart

Access website:

  • URL = https://<your.IP> or https://<your.host.name>

LESP Web Stack

LESP is a variation of the popular open source LAMP web stack, providing Nginx instead of Apache2 web server, and SQLite instead of MariaDB.

Nginx is a popular choice, thanks to its lightweight utilization of resources and its flexibility to scale simply even with minimal equipment.

Access website:

  • URL = http://<your.IP> or http://<your.host.name>

Access memory cache info:

  • APCu = http://<your.IP>/apc.php
  • OPcache = http://<your.IP>/opcache.php

Let’s Encrypt is highly recommended - see here how to install. This will automate the creation and setup of your free SSL cert.

Access website:

  • URL = https://<your.IP> or https://<your.host.name>

LLMP Web Stack

LLMP is a variation of the popular open source LAMP web stack, providing Lighttpd instead of Apache2 web server.

Access website:

  • URL = http://<your.IP> or http://<your.host.name>
  • Local directory = /var/www

Access PHP info page:

  • URL = http://<your.IP>/phpinfo.php

Access memory cache info:

  • APCu = http://<your.IP>/apc.php
  • OPcache = http://<your.IP>/opcache.php

For database, check MariaDB details.

Let’s Encrypt is highly recommended - see here how to install. This will automate the creation and setup of your free SSL cert.

Access website:

  • URL = https://<your.IP> or https://<your.host.name>

LLSP web stack

LLSP is a variation of the popular open source LAMP web stack, providing Lighttpd instead of Apache2 web server and SQLite instead of MariaDB.

Access website:

  • URL = http://<your.IP> or http://<your.host.name>
  • Local directory = /var/www

Access PHP info page:

  • URL = http://<your.IP>/phpinfo.php

Access memory cache info:

  • APCu = http://<your.IP>/apc.php
  • OPcache = http://<your.IP>/opcache.php

For database, check MariaDB details.

Let’s Encrypt is highly recommended - see here how to install. This will automate the creation and setup of your free SSL cert.

Access website:

  • URL = https://<your.IP> or https://<your.host.name>

The web development stack could be also individually installed. This option offers more flexibility giving the opportunity to select:

  • Webserver

Depending on your needs, you may choose the web server that fits best your needs. In case Lighttpd is not the right choice, you could continue with Apache Web Server, Nginx or Tomcat webserver.

  • Database

You may choose to install MariaDB or other available databases like InfluxDB, Redis, SQLite.

WebServers

Apache2

Apache is open source and it is the most commonly used Web server on Linux systems.

DietPi Webstack software Apache2 logo

Web servers are used to serve Web pages requested by client computers. Clients typically request and view Web pages using Web browser applications such as Firefox, Opera, Chromium, Microsoft Edge, Internet Explorer etc.

Apache is a Apache Software Foundation project. The goal is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.


Official documentation: https://httpd.apache.org/docs

Nginx

Nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server. It was released in 2004 to address the problem of increased web traffic. It has earned an excellent reputation and it is used in top million busiest sites - some of the success stories are: Dropbox, Netflix, Wordpress.com, FastMail.FM.1

DietPi Webstack software Nginx logo

The innovation of Nginx compared to earlier servers such as Apache was to use an asynchronous, event-driven architecture. Nginx is blazing fast, being extremely efficient when it comes to hardware utilization, allowing servers to get more speed out of their limited CPU and RAM. As a result, it is one of the fastest web server options for serving static content.


Official documentation: https://www.nginx.com

Lighttpd

Lighttpd is a web server for UNIX/Linux and Windows operating systems. It is an alternative to Apache web server. It is also called Lighty.

DietPi Webstack software Lighttpd logo

Source: Fair use, https://en.wikipedia.org/w/index.php?curid=10881730.

It is designed to be secure, fast, standards-compliant, and flexible while being optimized for speed-critical environments. Its low memory footprint compared to other web servers, light CPU load and its speed goals make Lighttpd a perfect candidate for SBCs.

After the installation, check if Lighttpd service is running on http://<your.IP>.

Multithreading is supported by Lighttpd and can be enabled in the configuration file /etc/lighttpd/lighttpd.conf. Change the value of 4 to your total core count:

server.max-worker = 4

Then restart services:

systemctl restart lighttpd

Official documentation: https://www.lighttpd.net

Tomcat

What is Apache Tomcat? Essentially it’s an open-source Java servlet and Java Server Page container that lets developers implement an array of enterprise Java applications. Tomcat also runs a HTTP web server environment in which Java code can run.

DietPi Webstack software Tomcat logo

Source: The Apache Software Foundation, Apache License 2.0.

After the installation, check if Tomcat service is running on http://<your.IP>:8080.


Official documentation: https://tomcat.apache.org

Databases & Data stores

MariaDB

MariaDB Server is one of the most popular open source relational databases. It’s made by the original developers of MySQL and guaranteed to stay open source 2. It is part of most cloud offerings and the default in most Linux distributions.

DietPi Webstack software MariaDB logo

Source: MariaDB, LGPL.

As root user, run mariadb from command line, no separate authentication required. But note that this won’t work via sudo, but an interactive root user shell session is required.

  • Username = root
  • Password = The same as your root login password, default is dietpi

Official documentation: https://mariadb.org
Getting started documentation: https://mariadb.org/documentation/#getting-started

phpMyAdmin

DietPi Webstack software phpMyAdmin logo

phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL / MariaDB over the Web.

Frequently used operations (such as: managing databases, tables, columns, relations, indexes etc.) can be performed via the web user interface. Using the same application you could also directly execute any SQL statement.

  • URL = http://<your.IP>/phpmyadmin
  • Username = phpmyadmin
  • Password = The same as your root login password, default is dietpi

Website: https://www.phpmyadmin.net
Official documentation: https://www.phpmyadmin.net/docs/

SQLite

DietPi Webstack software SQLite logo

Source: Part of the SQLite documentation, which has been released by author D. Richard Hipp to the public domain. SVG conversion by Mike Toews. Public Domain

SQLite is an embedded relational database engine. It it a self-contained, high-reliability and full-featured SQL database engine. It is very popular and there are hundreds of millions copies worldwide in use today 3.

To create a database and run commands, use the quick start documentation.


Website: https://www.sqlite.org/index.html
Official documentation: https://www.sqlite.org/docs.html

Redis

A non-SQL based data store.

DietPi Webstack software Redis logo

Source: Carlos Prioglio, licence.

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.

Redis is in the family of databases called key-value stores. The essence of a key-value store is the ability to store some data, called a value, inside a key. This data can later be retrieved only if we know the exact key used to store it.

The first thing to do in order to check Redis is working properly is sending a PING command:

redis-cli ping

For more commands and an introduction to Redis data types and commands, read the quick start documentation.


Website: https://redis.io
Official documentation: https://redis.io/documentation
Commands: https://redis.io/commands

InfluxDB

DietPi Webstack software InfluxDB logo

Source: InfluxData, Public Domain.

InfluxDB is a time series database designed to handle high write and query loads. InfluxDB is not only a time series platform, but it provides also an Web UI and dashboard tools, background processing and monitoring agent.

After the installation, the data transfers are made via the HTTP requests, and are handled directly by the InfluxDB service running on http://<your.IP>:8086.

  • Create a database using influxdb via command line tool.

    influx -execute 'create database myfirstdb'
    

  • Create a database using a HTTP request and curl tool:

    curl -i -XPOST http://<your.IP>:8086/query --data-urlencode "q=CREATE DATABASE myfirstdb"
    

  • Post data

    curl -i -XPOST 'http://<your.IP>:8086/write?db=myfirstdb' --data-binary 'temperature value=20.12'
    

  • Retrieve and display data from the database

    influx -database myfirstdb -execute 'SELECT * FROM temperature'
    

Create users and authorizations from influx CLI

influx -username admin -password admin01
CREATE USER admin WITH PASSWORD 'admin01' WITH ALL PRIVILEGES
CREATE USER test_user WITH PASSWORD 'test_user01'
GRANT ALL ON mydb TO test_user  
exit

How to enabled secured access (HTTPS)

By default the HTTP authentication is disabled. To enable it, follow next two steps:

  1. Change next setting in the configuration file /etc/influxdb/influxdb.conf:
    auth-enabled = true
    
  2. Restart service
    systemctl restart influxdb
    

Website: https://www.influxdata.com/products/influxdb
Getting started: https://docs.influxdata.com/influxdb/v2.0/get-started/#set-up-influxdb

Web development - Programming & Frameworks

PHP

DietPi Webstack software PHP logo

Source: Colin Viebrock, CC BY-SA 4.0.

First introduced by Rasmus Lerdorf, PHP is an open-source, server-side general scripting language that has now become a de-facto coding standard in the web development industry.

  • There are many tutorials - here is the official Getting started from PHP documentation.

Website: https://www.php.net
Official documentation: https://www.php.net/manual/en/index.php

Flask

Flask is a lightweight web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications and it has become one of the most popular Python web application frameworks.

In order to use Flask it is first required first to install the Python Package Manager - see Python Pip 3. Then run the next command.

pip3 install -U Flask

Website: https://palletsprojects.com/p/flask
Official documentation: https://flask.palletsprojects.com/en/1.1.x
PyPI package page: https://pypi.org/project/Flask

Return to the Optimised Software list