A LAMP stack is a suite of development tools, which stands for Linux, Apache, MySQL and PHP. Each of these components serves its own purpose: Linux is the operating system, Apache is the web server, MySQL is the database and PHP is the programming language.
In this quick tutorial we’ll cover how to install a LAMP stack on a Raspberry Pi.
Note that I am using the latest (at the time of writing this) version of Raspbian: Stretch. If you are using older versions of Raspbian you may need to tweak some of these steps slightly, or upgrade your distribution.
1.) Update Raspbian Operating System
Type these commands in the terminal:
sudo apt-get update sudo apt-get upgrade
Note that each of these commands will take a while to process. Especially on wifi. The upgrade in particular can take more than an hour, so go do some laundry or something and just keep checking back in.
2.) Install Apache
sudo apt-get install apache2 –y
3.) Test the Web Server
On successful installation, a default HTML page will appear in the root web folder:
/var/www/html
You can navigate to that directory in the terminal by typing:
cd /var/www/html
And then typing in the following command to see the files in that directory:
ls
You should then see the index.html file listed.
You can view this page on a web browser either from the Pi itself or from another computer on the same network.
From the Pi, open the web browser and type http://localhost in the address bar.
From another computer on the same network, type in the Pi’s IP address in the address bar of your web browser.
If you don’t know your Pi’s IP address, check out my quick tutorial on how to do this.
If everything went right, you should see a page like this:
4.) Install PHP
Run this command in the terminal:
sudo apt-get install php libapache2-mod-php –y
5.) Install MySQL
Run this command in the terminal:
sudo apt-get install mysql-server php5-mysql -y
6.) Restart Apache
sudo service apache2 restart
That’s it!
You now have your own local Raspberry Pi web server you can use to develop your web projects or tinker around.
If you have questions, let me know in the comments.