Installing a LAMP stack on the Raspberry Pi

Parallel PiI have been doing more with MySQL and I wanted to have a stable environment to test with. I have a working (virtualized) LAMP stack on my Dell 3050, but I don’t want to play around on the live server environment… The obvious solution? Add a LAMP stack to my Raspberry Pi (running Raspbian). I already SSH into that box all the time and it’s always on.

What is a LAMP stack, you ask?
A LAMP stack is an open source web platform used to host dynamic web sites and servers. It consists of: Linux, Apache, MySQL, and PHP/Python/Perl.

Step one, SSH into Raspberry Pi:

ssh username@hostname:22

Step two, update apt and install LAMP packages:

sudo apt-get update
sudo apt-get install apache2 mysql-server mysql-client php5 python perl phpmyadmin

And answer the on-screen prompts for passwords.

You can test that Apache is working by browsing to: http://hostname

001-apacheI opened up a browser and verified the Apache install was working.

Now that Apache is working it is time to test that PHP is working by making a simple page:

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

Copy/Paste this line into the blank ‘phptest.php’ file: (brackets and all):

<?php phpinfo(); ?>

Next, point a browser to the http://hostname/phptest.php file to verify it is working.

Now we want to enable MySQL support in PHP by editing the ‘php.ini’ file:

 sudo nano /etc/php5/apache2/php.ini

and change the following line:


To (NOTE: it changes from ‘msql’ to ‘mysql’):

And restart Apache:

 sudo /etc/init.d/apache2 restart

Verify that PHPMyAdmin is working by browsing to: http://hostname/phpmyadmin/
004-phpEverything is working as expected, yay!

If you get a 404 error when visiting http://hostname/phpmyadmin/, you will want to configure ‘apache2.conf’ to work with PHPMyAdmin (I didn’t have this problem, but the internet suggests this fix):

 sudo nano /etc/apache2/apache2.conf

Add the following line at the bottom of the file:

 Include /etc/phpmyadmin/apache.conf

Then restart Apache:

 sudo /etc/init.d/apache2 restart

Browse to: http://hostname/phpmyadmin/ and hopefully, you now see this:
004-phpCongratulations, you have successfully installed a working LAMP stack on your Pi!

pythonNow that you have the LAMP stack running, you can use it to: Host a website or a WordPress blog, learn PHP or HTML / CSS / Javascript in a live server environment, brush up on your MySQL (like me), or perhaps do some Python programming using Nano or your favorite editor. Whatever you decide to do, have fun doing it!

2 thoughts on “Installing a LAMP stack on the Raspberry Pi”

  1. if you are installing on a PI 4 running Buster you will be receiving PHP7.
    I have followed the steps , except for the because the line did not exists in the PHP.ini file. it works great

Leave a Reply

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

12 + three =

This site uses Akismet to reduce spam. Learn how your comment data is processed.