Last Updated on 23rd May 2026 by peppe8o

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
- PHP – Server-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 Computer Board (including proper power supply or using a smartphone micro USB charger with at least 3A)
- high-speed micro SD card (at least 16 GB, at least class 10)

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 datawww: 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:

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:

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):

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:

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

- Select Yes to configure the database for phpMyAdmin with dbconfig-common

- Insert your favourite phpMyAdmin password and press Ok

- Insert your phpMyAdmin password again to confirm and press Ok

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/”:

Use “phpmyadmin” as the username, and the password you set during phpMyAdmin installation.
You will reach the phpMyAdmin dashboard:

Next Steps
From here, you can:
- Secure your web server connections with Let’s Encrypt or self-signed certificates
- Get free domains with No-IP
Resources
- https://peppe8o.com/install-raspberry-pi-os-lite-in-your-raspberry-pi/#assign-static-ip
- https://peppe8o.com/how-to-configure-no-ip-duc-service-in-your-raspberry-pi/
- https://peppe8o.com/use-lets-encrypt-and-certbot-to-secure-raspberry-pi-hosted-websites-automatically/
- https://peppe8o.com/self-signed-certificate-https-in-raspberry-pi-with-apache/
- https://peppe8o.com/raspberry-pi-os-lite-vs-desktop/
- https://hub.docker.com/
- https://peppe8o.com/docker-raspberry-pi-portainer/
- https://httpd.apache.org/
- https://mariadb.org/
- https://www.phpmyadmin.net/
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!

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.








Thank you very much, it was a great help! Written very understandable. Greetings, Ronaldi.
You are welcome, Ronaldi.
If you like this content, please share it with your friends! đ
Clear, concise, correct and complete instructions.
Thank you, Wim
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.
I wasn’t able to reproduce your issue, as I just re-installed it from fresh OS. It seems strange, as also latest phpmyadmin version requires only php7.2.5 or newer (please refer to https://docs.phpmyadmin.net/en/latest/require.html#php) and apt currently installs php 7.3. However, if you strictly need php7.4, you can try with a trick included in my Grocy tutorial (Manage your home stocks like a pro with Grocy and Raspberry PI)
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.
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
Thank you very much. This made it all work!
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?
Hi Naamal,
you can both write here in comment area or email me at giuseppe@peppe8o.com to let me know what are the errors you are getting or what is the expected output you can’t get
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
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…
yes sir, i have have a XAMPP
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?
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
precise instructions. …Installed LAMP. Thanks a lot!!.
Wish to have some ideas on how to tweak the system.
Thank you for your feedback, Manaoj. Some tricks to improve system performance are available from my article
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?
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)
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.
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
Outstanding.
My forum has been up and running great. It’s all thanks to your excellent tutorials! Thank you so much and Merry Christmas!
Thank you Hans, enjoy your forum on Raspberry PI!