Hosting on a Pi!
After almost 3 years of deciding on whether to get a Raspi or not, its finally here. Having worked with Arduinos I always imagined the Raspi as an elder brother to the Uno, just another microcontroller. Oh boy was I wrong!
The pros of an Uno? Easier to program, harder to break! The Uno is a nifty little microcontroller for beginners. Its best suited for working with sensors, actuators and other devices. It works well with most of the current computers and has a steep learning curve. (Join this thread if you want to argue on 'steep learning curve')
"What should I do with it?" ¯\_(ツ)_/¯
All this would have been really simple had the setup been as easy going as for the Uno: Plug-n-Play. Now I miss the Uno :(
"'Headless Pi Setup'.. thats what you need to Google for!" (-_- )
Heads up, this post is just describing how I did things, feel free to use the almighty Google to tinker around and come up with better solutions which I know surely exist.To start Google Chorme on my laptop, I hit the power button (if I ever accidently shut down my laptop), login to Windows (yeah, bite me! I do VMs) and open Chrome. So the Pi is also a computer: Which OS does it have? Wheres the screen?? Oh wait, where the hell is the power button!?!
Lets break it down.
What we will be doing here is called a Headless Setup. Who came up with this terminology? Who asumed the screen to be the head of a computer? Anyways..
What all do I really need to get the a server running?
- A computer with a power source(I have the Pi)
A screen to look at.
Who am i kidding? I know SSH now B) , without a screen ought to work.
- An operating system
- Internet connection
- A way to connect to the Pi without connected any hardware.
- A HTTP web server
Powering up the PiWhy did I even bother, I still dont have an OS to run or any storage on the Pi nor a way to connect to it.
The Operating SystemRaspberry Pi has a microSD card slot on the back side. This is where the SD card with your OS will reside and also most of the data. You can hook up an external storage device as well into one of the 4 USB ports, but thats only for extra storage; OS stays on the card.
First format a microSD card on your computer and write the desired OS image using something like Win32DiskImager (for Windows). I had a 32GB Class 10 that came with the Raspberry Pi.
Now this card has to be loaded with your favoutite Linux distro. The official Raspi website has a good selection of images to download. I went with Raspbian Stretch Lite which is based on Debian Stretch. (Will probably shift to Arch Linux in my next update). Writing an image to the formatted microSD card is pretty easy with Win32DiskImager.
Select the 'Image File' by navigating to the location where you extracted the downloaded image files and select the 'Device' that represents your microSD card (E:/ for me). Hit Write!
Once its done without errors you are done with the OS installation!
If you are reading this, I assume you have an internet connection. What I meant here was connecting the Pi to the internet. Earlier versions of Raspberry Pi could connect to the internet only using ethernet. All hail the Pi 3 B with on board WiFi!
Now I remembered why I chose Raspbian as my OS: DHCPC daemon!
dhcpcd is a opensource Dynamic Host Configuration Protocol client daemon. IKR, too verbose,but equally important. It runs on Raspbian on boot and this is what helps connect to your WiFi. And we need to configure this serivce to connect to the Wifi on startup by using a file called wpa_supplicant.conf
Open the freshly cooked microSD card drive and add the following
wpa_supplicant.conf file to the
/boot/ directory (where you land when you open your microSD drive on Windows).
This part has set up the Pi to conneccted to your Wifi on boot.
Activating SSH for your Pi
SSH is disabled in RaspberryPi/Raspbian in the latest versions. To enable it, simply place an empty file called
ssh (yes, without any extension) in the same place as the
wpa_supplicant.conf file. Now you can SSH into the Pi from any computer on the same network on which the Pi is connected.
Power up the RaspberryPi!
What IP address do I SSH into?
Time to move to your Wifi-Router for the last part of the setup. Wait for a couple of minutes to give the Pi time to connect to the WiFi. Open the Web Management portal for your router. Open your routers IP address in any web browser. Its
192.168.0.1 for most of the new routers or you can have a look at the back of your router to find its address, also have a look for the username and password of the portal. For my TP-LINK router its the good old default
Open the DHCP tab (for TP-LINK routers) and check the DHCP Client List for a list of all the devices connected to your router. *fingers crossed* If all goes well, you should see your RaspberryPi in the list. Make a note of its IP address, thats your only 'headless' point of entry into the Pi. You probably wont be having a 'Permanent' Lease Time on your first connection, nor is it required. I'll cover that in my next post.
SSH into the Pi
Non Windows users can start with the terminal and Windows users may have to resort to Putty or even better (and my fav) Bash On Windows for SSH-ing. Use
pi as the user and SSH into the Pi's IP address you found in your router. The default password is
$ ssh email@example.com
Aaaaand we are done! Kind of.
There's still a lot of scope in changing raspi-configurations, changing password and creating users, update packages and a lot more customization. But the steps here are enough for a basic setup to get up and running with Pi.
The last step is setting up the actual HTTP server on the Pi. I'll take that up in the next one.