LAMP is an acronym that stands for Linux Apache, MySQL/MariaDB and PHP. i have LAMP installation post for PiHome but i see lots and lots of people are looking for setting up php 7 with phpMyAdmin and MariaDB on raspberry pi and there isn’t any comprehensive set of instruction that covers this all for PHP 7, MariaDB on raspberry pi.
If you are looking for Raspberry pi SD card image for LAMP (Apache, PHP 7.0 and MySQL/MariaDB on a Raspberry Pi with phpMyAdmin) pre installed then check out Download section.
Follow OS (Raspbian Jessie) Installation and WiFi Configuration posts to install and get WiFi configured without any screen connected to Raspberry pi.
Note: if you are here for some troubleshoot Raspberry Pi LAMP (PHP 7.0 and MySQL/MariaDB on a Raspberry Pi with phpMyAdmin) then check out troubleshooting post on Raspberry Pi LAMP
Update System
Issue following commands to update your raspberry pi.
1 2 |
sudo apt-get update sudo apt-get upgrade |
Repository Sources for Raspbian Stretch
Modify /etc/apt/sources.list and uncomment stretch sources.
1 2 |
# Uncomment line below then 'apt-get update' to enable 'apt-get source' deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi |
Install Apache Server
Lets install Apache 2 web server on raspberry pi alone with common packages, you can add extra packages as your need.
1 |
apt-get install apache2 apache2-doc apache2-utils php7.0-zip |
Now you are test your apache2 installation. In your browser visit the IP address of your raspberry pi, you should see default Debian page.
Add New Repository Sources
As to date PHP 7.0 hasn’t added to the official repository sources, so you need to add one which provides the PHP 7.0 packages. You have to determine which version of raspbian you have installed.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cat /etc/os-release root@pihome:~# cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)" NAME="Raspbian GNU/Linux" VERSION_ID="8" VERSION="8 (jessie)" ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs" root@pihome:~# |
After figuring out which version, choose the one for jessie or the one for stretch. Make sure you choose the correct repository for the version of raspbian. Modify /etc/apt/sources.list file, my sources.list files look like this for Raspbian jessie.
1 2 3 |
deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free #deb-src http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi |
Now add some certificates to use the sources we just added with apt-get.
1 2 3 |
sudo gpg --keyserver pgpkeys.mit.edu --recv-key CCD91D6111A06851 sudo su gpg --armor --export CCD91D6111A06851 | apt-key add - |
After successfully adding source and certificates now time to update packages list.
1 |
sudo apt-get update |
Install PHP 7 on Raspberry Pi
We are ready to install PHP 7 along with some common packages that you may need for web application.
1 |
apt-get install libapache2-mod-php7.0 php7.0 php7.0-opcache php7.0-mbstring php7.0-mysql php7.0-curl php7.0-gd |
Once Php 7 get installed successfully you can test php and Apache installation.
1 2 3 4 5 6 7 |
Test PHP and Apache Install root@raspberrypi:~# php -v PHP 7.0.25-1+0~20171027135525.8+jessie~1.gbp75b787 (cli) (built: Oct 30 2017 19:44:10) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.25-1+0~20171027135525.8+jessie~1.gbp75b787, Copyright (c) 1999-2017, by Zend Technologies root@raspberrypi:~# |
Install MariaDB Server on Raspbian
With the new version of Raspbian MariaDB is now present in the official repositories, To install it, you just need to run the following command
1 |
sudo apt-get install mariadb-server mariadb-client |
During MariaDB Server installation you will be asked to set password for the MariaDB Administrative root user.
Note: if you don’t get option to enter password for MySQL/MariaDB simply run sudo mysql_secure_installation and enter root credentials for MySQL/MariaDB.
Confirm password for Administrative root user.
Install phpMyAdmin on Pi with PHP 7 and MariaDB Server
phpMyAdmin isn’t required but it will make your life easier if you need to do any troubleshooting for MariaDB/MySQL Database server.
Select apache2 for phpmyadmin installation and hit ok
1 2 |
sudo bash apt-get install phpmyadmin |
Apache Configuration for phpMyAdmin
Configure Apache to work with phpMyAdmin. Edit /etc/apache2/apache2.conf and go to end of file.
1 |
nano /etc/apache2/apache2.conf |
Add following line and then CTRL+O to save changes and then CTRL+X to exit.
1 |
Include /etc/phpmyadmin/apache.conf |
Now restart Apache web server, if everything was correct Apache service should start successfully.
1 |
/etc/init.d/apache2 restart |
Now you can test phpmyadmin from your browser http://<pi ip address>/phpmyadmin
Change Document Root Folder
By default Apache server installed with document root pointing to /var/www/html, you need to change this in /etc/apache2/sites-available/000-default.conf for PiHome to work.
1 |
DocumentRoot /var/www/html |
To
1 |
DocumentRoot /var/www/ |
Restart Apache Service
1 |
/etc/init.d/apache2 restart |
24 comments
Thank you for the effort. I have already done this and it installs all elements OK. I was hoping you could find a reason and a fix to the fact that phpMyAdmin installs with NO privileges and is de facto unusable.
If you can fix this you would be the first.
I’m having the same problem
looked all over the net and still no joy
sorry guys been very busy with other project and job and study, i will try to replicate your issues over next few days…
I have planned to buy pi3 as currently I’m using pi2. any tips for optimization to load my site faster?
Hello, good tutorial
i am traying to install LAMP and PHPMyadmin, but i have this error when adding New Repository Sources:
gpg: failed to start the dirmngr ‘/usr/bin/dirmngr’: No such file or directory
gpg: connecting dirmngr at ‘/root/.gnupg/S.dirmngr’ failed: No such file or directory
gpg: keyserver receive failed: No dirmngr
Please can you Help Me? thanks
I went to the http://repozytorium.mati75.eu. You have to determine which version of raspbian you have installed.
cat /etc/os-release https://www.meccanismocomplesso.org/en/how-to-raspberry-checking-raspbian-version-update-upgrade/
After figuring out which version choose the one for jessie or the one for stretch. Make sure you choose the correct repository for the version of raspbian.
During MariaDB Server installation you will be asked to set password for the MariaDB Administrative root user.
This did not happen just installed and went back to
root@raspberrypi:~#
has something changed and how do i get root access password ?
hi,
can you share logs of your installation?
Admin
Just run this command and follow steps:
sudo mysql_secure_installation
thanks a lot!
It helps for me.
you welcome.
PHPMyAdmin main screen no “User Tab” and Under “Database Tab” Create DataBase – “No Privileges ” . What can I do to Get the “User Tab” and Privileges??? Help Please… Thanks Joe
Hi Joe,
can you run following command ?
sudo mysql_secure_installation
First Thanks for the Reply I went through the “sudo mysql_secure_installation”. I was able to get into “PHPMyAdmin” with user Name”phpmyadmin” and the Password I set in the installation. But I still don’t have any Privileges or User Abilities. I have to tell you I just reinstalled everythin for the 5 Time. I’m saying OS Raspbian Debian 9 Stretch, Apache2, PHP, MariaDB and with your help MyPHPAdmin. I just can’t get any privileges or User Create Abilities with this combo. Thanks for Trying I guess I have to keep Looking.
Thanks
Joe
Hi All,
i have added Troubleshooting post where all LAMP related issues are.
Looks nices! Thanks!
Hi,
Same issue as richy, getting the error:
gpg: failed to start the dirmngr ‘/usr/bin/dirmngr’: No such file or directory
gpg: connecting dirmngr at ‘/root/.gnupg/S.dirmngr’ failed: No such file or directory
gpg: keyserver receive failed: No dirmngr
I believe it’s down to how I set up the repository, as it’s not clear whether I should be leaving existing text in the file, or replacing it. Also, as per the comment by Johnathan I went to the repository website and saw the text it said i should put in is different to what’s in this guide. I feel like I’ve tried every combination of these but nothing seems to work!
Thanks
Update:
Figured it out. Turns out that I needed to install dirmngr
Hello,
I have tried to follow the installation tutorial but I get stuck on the root authorization probably and I am not able to access the DB from webbrowser.
In order to check I have tried to download the img file with no success.
I don’t understand if it is my problem but when I try to download the LAMP pi home img file it often does never ends the download and whenever it ends the resulting file is a .zip file with a size of 302 KB, this size is a bit to small for an img and infact it does not work.
Can you check that?
Many thanks for your very interesting project.
Hi baklanovic,
sorry for this, i have fixed the link in product and added dropbox link for download. can you try to get product from site and you’ll get link in email and on final page.