Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.

lamp-server-raspberry-pi-featured-image

LAMP server on Raspberry PI

4.9
(31)

Last Updated on 23rd May 2026 by peppe8o

lamp-server-raspberry-pi-peppe8o-badge

This tutorial will show you how to install a LAMP server on a Raspberry PI computer board, giving you all the terminal commands to get it up and running.

A LAMP is a server composed of the following elements (each one composing the LAMP acronym):

  • Linux – Operating System – to manage hardware integration and general software operations
  • Apache – Web Server Application – to expose HTML pages
  • MySQL – Database – to store records and data which need to be managed with appropriate structures
  • PHPServer-side Scripting – to create dynamic pages

Before Using a LAMP server…

Besides installing a LAMP server to publish a website, you also need to set some networking configurations.

The very first thing to configure is to ensure that your Raspberry PI will always acquire the same local IP address on every boot. This can be achieved by setting a static IP address on the Raspberry PI and configuring your router to leave the same IP address associated with the Raspberry Pi’s MAC address (this part depends on your router model).

If you want to publish your web page on the internet, you also need to configure your router’s port forwarding. You must forward external ports 80 (for HTTP) and/or 443 (for HTTPS) to the Raspberry PI. You should also use a domain, being able to start with a free No-IP domain (please refer to my No-IP DUC guide for the last part).

In this tutorial, I’m going to show you how to install a LAMP server on your Raspberry PI. I’m going to use a Raspberry PI 4 Model B, but this guide will apply to all Raspberry PI boards.

What We Need

As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if to continue with the project or remove them from the shopping cart. So, hardware will be only:

raspberry-pi-5-model-b-board

Step-by-Step Procedure

Prepare the Operating System

The first step is to install the Raspberry PI OS Lite to get a fast and lightweight operating system (headless). If you need a desktop environment, you can also use the Raspberry PI OS Desktop, in which case you will work from its terminal app. Please find the differences between the 2 OS versions in my Raspberry PI OS Lite vs Desktop article.

Please make sure that your Operating System is up to date. From your terminal, use the following command:

sudo apt update -y && sudo apt full-upgrade -y

We can use 2 different methods to install a LAMP server on a Raspberry PI. We can use Docker, which simplifies the software management and keeps the Raspberry PI OS clean when uninstalling. But this procedure is working only for those Raspberry PI computer boards supporting the 64-bit OS. For 32-bit boards, we can manually install the packages.

In the following chapters, I will provide both the methods; you can use one of them according to your needs.

Install LAMP Server on Raspberry PI with Docker

With Docker, we can use existing container images available from the Docker Hub to setup the LAMP infrastructure from a single yml file, including the complete infrastructure. We’ll have 3 containers:

  • PHP + Apache
  • MariaDB
  • PHPmyAdmin

Please start installing Docker on Raspberry PI by using the linked tutorial.

Create a folder which will include all the required files, and enter it:

mkdir lamp
cd lamp

Create a Docker Compose file:

nano docker-compose.yml

And fill it with the following content. Please change the database user and passwords to your preferred ones (in the db environment section):

services:
  web:
    image: php:apache
    container_name: lamp_web
    restart: unless-stopped
    ports:
      - "80:80"
    volumes:
      - ./www:/var/www/html
    depends_on:
      - db

  db:
    image: mariadb:latest
    container_name: lamp_mariadb
    restart: unless-stopped
    environment:
      MARIADB_ROOT_PASSWORD: supersecret_root
      MARIADB_DATABASE: mydb
      MARIADB_USER: myuser
      MARIADB_PASSWORD: mypass
    volumes:
      - ./db-data:/var/lib/mysql
    ports:
      - "3306:3306"

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: lamp_phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: db
    ports:
      - "8080:80"
    depends_on:
      - db

Save and close. This configuration file creates 2 folders (in the current path) where persistent data is stored:

  • db-data: which includes the MariaDB data
  • www: which includes the web server files (Apache/PHP)

Now, you can run your LAMP server with the following command:

docker compose up -d

It will download the required images and create the services. After you get the prompt back, please check the server logs with the following terminal command:

docker compose logs

The container installation and configuration could take a very few minutes, so wait to get something like the following in your logs:

...
lamp_mariadb     | 2026-05-22 17:07:57 0 [Note] Server socket created on IP: '0.0.0.0', port: '3306'.
lamp_mariadb     | 2026-05-22 17:07:57 0 [Note] Server socket created on IP: '::', port: '3306'.
lamp_mariadb     | 2026-05-22 17:07:57 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
lamp_mariadb     | 2026-05-22 17:07:57 0 [Note] mariadbd: ready for connections.
...

At this point, our LAMP server on Raspberry PI is up and running. We must only create a file in the www folder to be provided when someone accesses the server from a browser.

Create it:

sudo nano www/index.php

And fill it with the following line:

<?php phpinfo(); ?>

Save and close.

From a remote browser, please use your Raspberry PI’s IP address as URL (in my case, 192.168.1.14). The LAMP server will automatically run the index.php file and will return information about your PHP installation:

lamp-server-raspberry-pi-php-info-docker

Moreover, if you add the “8080” port to the URL (in my case, 192.168.1.14:8080) you will reach your PHPMyAdmin login page:

lamp-server-raspberry-pi-phpmyadmin-login-docker

Here, the default credentials are Username: myuser / Password: mypass. Please change them once logged in.

Install LAMP Server on Raspberry PI with packages

In this case, we must install all the parts one by one. The Aptitude package manager (apt) also makes this method easy, even if this will require more steps compared to the Docker method.

Install the Apache Web Server

From the terminal, issue the following command:

sudo apt install apache2 -y

Once the installation is finished, you can check that Apache is working by using your web browser with your Raspberry PI’s IP address as the URL. The following picture shows the expected result (in my case, 192.168.1.14):

lamp-server-raspberry-pi-apache-welcome-page

In this case, the published files are available in the folder /var/www/html/ in your Raspberry PI.

Install PHP

To proceed with the PHP installation, use the following from the terminal:

sudo apt install php -y

To check if the installation finished correctly, you can use the php -v command from the terminal, and you will get something like the following:

pi@raspberrypi:~ $ php -v
PHP 8.4.21 (cli) (built: May  8 2026 05:56:48) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.21, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.21, Copyright (c), by Zend Technologies

You can also test PHP and get the related info page by creating a simple PHP page on your web server. From the terminal, create test.php in /var/www/html/ folder with the following command:

sudo nano /var/www/html/test.php

Add the following line:

<?php phpinfo(); ?>

Save and exit. Back to your browser, append the “/test.php” string to the Raspberry PI’s IP address, so getting the following result:

lamp-server-raspberry-pi-php-info

This is a useful page as it gives you fast access to the PHP modules and settings enabled in your board.

Install Database – MariaDB instead of MySQL

From the database side, I suggest using MariaDB instead of MySQL. MariaDB is a fork of MySQL, resulting in lighter software (which better fits Raspberry PI resources) and keeping the same MySQL commands valid. We’ll install it together with the PHP connector so that MariaDB and PHP will be able to communicate. From terminal:

sudo apt install mariadb-server php-mysql -y

Once finished, a common best practice for a database is securing it. MariaDB gives you a procedure to set the main configurations. From terminal:

sudo mariadb-secure-installation

The following questions will be asked (followed by my suggested answers):

  • Enter current password for root (enter for none): root password in fresh installation is empty, so con simply press the ENTER key (or input your root password if you already changed it)
  • Switch to unix_socket authentication [Y/n]: I answered no
  • Change the root password? [Y/n]: I suggest answering Y (yes)
  • New password: type your new root password
  • Re-enter new password: type your new root password again
  • Remove anonymous users? [Y/n]: I suggest answering Y (yes)
  • Disallow root login remotely? [Y/n]: I suggest answering Y (yes)
  • Remove test database and access to it? [Y/n]: I suggest answering Y (yes)
  • Reload privilege tables now? [Y/n]: Answer yes to make your answers effective

Your LAMP server is now ready and complete!

Simplify the Database management – phpMyAdmin

A useful tool to manage databases in LAMP servers is phpMyAdmin. It can be installed with the following terminal command:

sudo apt install phpmyadmin -y

In the phpMyAdmin setup screens, I suggest the following:

  • Select Apache (mandatory) with the space key and press Ok
lamp-server-raspberry-pi-phpmyadmin-setup-01
  • Select Yes to configure the database for phpMyAdmin with dbconfig-common
lamp-server-raspberry-pi-phpmyadmin-setup-02
  • Insert your favourite phpMyAdmin password and press Ok
lamp-server-raspberry-pi-phpmyadmin-setup-03
  • Insert your phpMyAdmin password again to confirm and press Ok
lamp-server-raspberry-pi-phpmyadmin-setup-04

Grant phpMyAdmin user DB privileges to manage DBs

We’ll connect to MariaDB with the root user (the default password is the one set before) to grant permissions. In the following terminal commands, please remember to use semicolons at the end of each command row:

sudo mysql -uroot -p
grant all privileges on *.* to 'phpmyadmin'@'localhost';
flush privileges;
quit

From here, use your web browser to reach the phpMyAdmin login page by using the Raspberry PI’s IP address followed by “/phpmyadmin/”:

lamp-server-raspberry-pi-phpmyadmin-login

Use “phpmyadmin” as the username, and the password you set during phpMyAdmin installation.

You will reach the phpMyAdmin dashboard:

lamp-server-raspberry-pi-phpmyadmin-dashboard

Next Steps

From here, you can:

Resources

What’s Next

If you want to discover many other projects for your Raspberry PI, you can take a look at peppe8o’s Raspberry PI tutorials.

Enjoy!

peppe8o author image
peppe8o (Giuseppe Cassibba)

Open source and Raspberry PI lover, writes tutorials for beginners since 2019. He's an ICT expert, with a strong experience in supporting medium to big companies and public administrations to manage their ICT infrastructures. He's supporting the Italian public administration in digital transformation projects.

websitexfacebookinstagramlinkedinyoutubepinterest

How useful was this post?

Click on a star to rate it anonymously!

Average rating 4.9 / 5. Vote count: 31

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

24 thoughts on “LAMP server on Raspberry PI”

  1. Thankyou for the guide.
    Currently there appears to be an issue with versions phpMyAdmin and PHP, arising from the “sudo apt install phpmyadmin” command installing an older version that throws errors with PHP 7.3.
    Hopefully the packages will be updated soon.

  2. Hey, really good description, thank you!

    Before I could access phpmyadmin in the browser, I had to make following steps:

    edit the “Apache2.conf” file:
    sudo nano /etc/apache2/apache2.conf
    add the following line to the bottom of this file:
    Include /etc/phpmyadmin/apache.conf
    Exit with crtl+X
    Now we need to restart the Apache service:
    sudo service apache2 restart

    And so will work phpmyadmin.

    1. Thank you for your notes. Sometimes package updates can change or add some additional configurations. I’ll test your edit notes and add them in my tutorial soon

  3. Lord, I was able to follow you. Thanks a lot. All my attempts to activate a PHP website to the Raspberry Pi local host failed, can you help me?

      1. Sir. Thanks you so much for seeing the quick response,
        As an XMPPP Home Server for Windows I currently have the RFID Attendance Systems PHP website. I want to set it up as a Raspberry Pi home server, that website is taken from the internet. I will post its link here. I do not know how to connect this site to the lamp server. Can you explain the step-by-step procedure?

        This is the website download link
        https://drive.google.com/file/d/1P5c8MwKc_BlDYW9ApiZG-tF7qUJABQSx/view

        1. Sorry, for this week I can’t test on my Raspberry PI computer boards as I’m on holiday and I’ve only a Raspberry PI Pico with me. But let me have a clear overview of what you have.
          First of all, I want to ask you if you have an XMPP server or a XAMPP server, as the two things are quite different, just to be sure we are on same page.
          Also consider that Windows computers usually have x64 or x86 CPU architecture, while RPI has an ARM CPU architecture. It is not always granted that you can perform this move without reinstalling some things. Another check is if your current php version on Windows server is compatible (or the same) with the two currently available from Raspberry PI OS repository (2.7 and 3.7, latter whould be better solution).
          The simplest way to verify if it works (if you are very very lucky) is copying the entire content from your Windows root publishing path (usually C:/xampp/htdocs/) into the LAMP root publishing path (/var/www/html/), then setting correct permissions to allow ownership to www-data:www-data.
          But if you had in past to install something and/or you use a database, this won’t give a working result…

          1. Sir, I know that the web version is stored in the htdocs folder in Xampp, but the htdocs folder is not found in the lamp server, how do I find it?

  4. when I run;
    [ grant all privileges on *.* to ‘phpmyadmin’@’localhost’; ]

    I keep getting this error.

    ERROR 1133 (28000): Can’t find any matching row in the user table

    everything else has been working just fine

  5. Manoj Kumar Manmathan

    precise instructions. …Installed LAMP. Thanks a lot!!.
    Wish to have some ideas on how to tweak the system.

  6. When I go to access the server via IP in google chrome, it tells me that the certificate is invalid. Yet, in firefox it opens as expected. Any idea as to why?

    1. Hi John,
      yes, it’s normal because you haven’t a certificate installed and modern browsers warn you that it can be a security issue. You can just tell the browser to proceed as you’re sure that the IP matches your Raspberry PI in your local network. Moreover, you can use self-signed certificates (if your Raspberry PI needs to stay within your local network) or you can use Let’s Encrypt (if you can add a forward route from your internet router)

  7. At the early step of securing the database, I received this error; “mysql_secure_installation: command not found”. Looking elsewhere on the web, I found the new command to use;

    sudo mariadb-secure-installation

    I haven’t finished up yet, the goal is a self-hosted PHPBB forum, but this is the first error I have encountered. Excellent tutorials! Thank you so much.

    1. Thank you for your feedback, Hans. I’ll update the tutorial by this week end. By the way, you can find also a tutorial about installing phpBB forum in my blog

      1. Outstanding.
        My forum has been up and running great. It’s all thanks to your excellent tutorials! Thank you so much and Merry Christmas!

Leave a Comment

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

×