Welcome to another Raspberry Pi Tutorial! Today's lesson is pretty simple: How to install Apache on a Raspberry Pi.
In the last tutorial, I showed you how to turn on an LED using two different libraries. How would you like to do that from a browser? That could open possibilities such as creating a web application to turn an LED on and off.
Well, consider this tutorial to be the first in a series of four videos (maybe 4, I haven't made the others yet as of this publish date). In the next few tutorials, I plan to show you how to install Flask on your pi, then how to run Flask behind Apache, then finally, we'll create a quick application that we can access and control and LED on a Pi.
So first thing is first. let's install Apache. If you want to skip the video below for the steps, then feel free to follow these steps. This tutorial assumes you already know how to run your Pi in Headless mode.
If you have a fresh install of Raspbian, run the following command to update and upgrade all of your software:
sudo apt update && sudo apt upgrade -y
Once everything is updated, let's install apache with:
sudo apt install apache2 -y
It may take a few minutes but once it's done, you're all done with installing Apache! It's that easy.
The default directory for all of your files sould be located in
/var/www/html. To access it do:
cd /var/www/html ls
ls command will show you that there's a lone
index.html file. To take a look at the contents and to confirm that Apache is running, use your browser to access the IP address of your Pi (e.g. http://192.168.1.196 in my case).
Couple more friendly commands:
To check the status of Apache:
service apache2 status
We don't need to do sudo because we are only reading. To start Apache if it's off:
sudo service apache2 start
To turn it off:
sudo service apache2 stop
To restart it in one command:
sudo service apache2 restart
That's all! Have questions about the tutorial? Ask below, I welcome all questions and comments.Come back for the next few tutorials to learn more. And be sure to subscribe in order to stay up to date. On Pi Day (3.14.19), i gave away 4 Raspberry Pi Zero Ws to my subscribers! I didn't announce this anywhere else. So subscribe to stay up to date on all news.
Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!