Host a Raspberry Pi Web Server on the Internet

Bought Raspberry PI 3 for a home project year ago. But haven’t utilized the Raspberry PI much, so thought to create my personal website. Like to share my learning on how to host raspberry pi web-server over the internet.

Steps

We all know that we can access any website through browser using DNS name. DNS name should have been mapped with our web server IP address(A record). Once IP address mapped, we need web server running to listen and reply on the IP and port. Find the below steps will dive deep into the each step

Getting Free DNS

To get the free domain name, I used the website named freenom.com. Search for the domain name you want and get the free one. As of now we can use the free domain up to one year.

Searching for domain
pick free domain

Above screenshot illustrates how to search and pick the domain we want. Checkout and get the domain. Need to register before we purchase the domain but this site never ask for the payment information if we purchase the free domain.

A Record

After getting the domain, need to add the ‘A’ record that should point the web server. Before that, we must find the domestic router external IP address to add ‘A’ record. Open the IP chicken website to find the same https://www.ipchicken.com/.

IP address

Next, Login to the freenom site. Under Services go to my domains and click manage domain for the dns name you want to change

my domains
manage domain

Add ‘A’ record with target as router IP address.

Install Web-server

Install web server using the following command

sudo apt install apache2 -y

For more details checkout the https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

HTML

Create a configuration for your domain name using following command and configure the Virtual host & doc path. Highlighted configuration changes in bold.

$ sudo cp /etc/apache2/sites-enabled/000-default.conf /etc/apache2/sites-enabled/{dnsName}.conf

configuration

<VirtualHost {dnsName}:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.{dnsName} #www.example.org
ServerName {dnsName} # example.org

ServerAdmin {emailAddress}
DocumentRoot /var/www/html

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

reload the configuration and restart the server

$ sudo a2ensite {dnsName}
$ sudo service apache2 reload
$ sudo systemctl daemon-reload
$ sudo service apache2 restart

Make sure that router/firewall not blocking the port 80. That’s it everything ready and hit the dns name created from freenom site. Sure it will hit our raspberry apache2 server and load the index.html from DocumentRoot(/var/www/html) specified in conf file.

Here is the part 2 article to configure https SSL encryption to your site
https://saravanastar.medium.com/ssl-encryption-for-website-using-cloudflare-5529ef9d6cd4

References:

The Startup

Get smarter at building your thing. Join The Startup’s +786K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +786K followers.

Saravanakumar Arunachalam

Written by

Software Enginner

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +786K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store