{"id":432692,"date":"2022-02-04T08:57:42","date_gmt":"2022-02-04T06:57:42","guid":{"rendered":"https:\/\/mybroadband.co.za\/news\/?p=432692"},"modified":"2022-02-04T09:02:33","modified_gmt":"2022-02-04T07:02:33","slug":"i-built-a-web-server-using-a-raspberry-pi-and-hosted-my-own-website-on-it","status":"publish","type":"post","link":"https:\/\/mybroadband.co.za\/news\/hardware\/432692-i-built-a-web-server-using-a-raspberry-pi-and-hosted-my-own-website-on-it.html","title":{"rendered":"I built a web server using a Raspberry Pi \u2014 and hosted my own website on it"},"content":{"rendered":"<p>A Raspberry Pi is a versatile computing device with many functions, including using it as a webserver to host your own website.<\/p>\n<p>Raspberry Pis are single-board computers widely used in DIY electronics projects and as a learning tool.<\/p>\n<p>We decided to put the device to the test as a web server.<\/p>\n<p>To create a web server using Raspberry Pi, you need the basic board, a MicroSD card with 8GB or higher capacity, a power supply, and an Internet connection.<\/p>\n<p>Due to the global chip shortage, finding a new Raspberry Pi board proved difficult. Luckily, we had one available from a previous experiment.<\/p>\n<p>We used a Raspberry Pi 3 Model B+ for this project and powered it with a Micro USB cable from a charging brick.<\/p>\n<p><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Loose-parts.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-432698\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Loose-parts.jpg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Loose-parts.jpg 800w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Loose-parts-533x400.jpg 533w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Loose-parts-573x430.jpg 573w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Loose-parts-768x576.jpg 768w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>We started building a web server by installing the 64-bit headless version of Raspbian onto our MicroSD card.<\/p>\n<p>This can be done with the tool downloadable from the Raspberry Pi website.<\/p>\n<p><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Installation.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-432702 size-large\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Installation-640x425.jpg\" alt=\"\" width=\"640\" height=\"425\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Installation-640x425.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Installation.jpg 679w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>After installing the operating system, we created an empty file named &#8220;ssh&#8221; on the boot volume to enable the SSH server.<\/p>\n<p>The network configuration can also be done on the memory card, but we opted to connect directly to the Pi with an Ethernet cable and continue the setup through SSH.<\/p>\n<p><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/First-login.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-432704 size-large\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/First-login-640x407.jpg\" alt=\"\" width=\"640\" height=\"407\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/First-login-640x407.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/First-login-600x381.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/First-login.jpg 658w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>We used Putty to connect to the Pi. After logging in, we changed the default password and continued with the standard setup.<\/p>\n<p>We worked through the options available in the raspi-config menu and ran the &#8220;apt update&#8221; and &#8220;apt upgrade&#8221;.<\/p>\n<p><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Config.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-432706 size-large\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Config-640x359.jpg\" alt=\"\" width=\"640\" height=\"359\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Config-640x359.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Config-600x336.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Config.jpg 658w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Once the Pi was configured, we followed online guides to install Nginx for the webserver and Node.js for the JavaScript application we wanted to test.<\/p>\n<p>We also set up a static private IP for the Pi on our network and forwarded port 80 on the router to make the server visible on the Internet.<\/p>\n<p>To host the device on a mobile connection, you must use the unrestricted APN for the specific network.<\/p>\n<p>These are available at request for Vodacom and Cell C customers and is enabled by default for most Telkom Mobile and Afrihost Air Mobile connections.<\/p>\n<p>An online port checking tool can be used to manage connections to your server. Alternatively, you can start the Nginx server and browse your network&#8217;s public IP address using a device on a different network.<\/p>\n<p>You should be greeted with the default Nginx page if everything went well.<\/p>\n<p><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/NGinx.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-432708 size-large\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/NGinx-640x249.jpg\" alt=\"\" width=\"640\" height=\"249\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/NGinx-640x249.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/NGinx-600x233.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/NGinx-768x298.jpg 768w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/NGinx.jpg 919w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Since we used a regular consumer Internet connection without a static public IP, we needed a Dynamic Domain Name System (DDNS) service.<\/p>\n<p>This will keep a domain name up to date with our actual IP so that the website is easily accessible to the public.<\/p>\n<p>We used No-IP as it offers a free service and a guide to using it on a Raspberry Pi.<\/p>\n<p>We verified that everything was working by browsing to the hostname we set up and getting the expected Nginx welcome page.<\/p>\n<p>As this server was set up to show off the possibilities, the next order of business was to find an open-source game that we could host.<\/p>\n<p>After a short search, we came upon a <strong><a href=\"https:\/\/codepen.io\/CaioPaiola\/pen\/nojJmQ\" target=\"_blank\" rel=\"noopener\">Snake Game by Caio Paiola<\/a><\/strong> on Codepen and downloaded the source code.<\/p>\n<p>We copied the source code onto the Pi and got it running after some troubleshooting.<\/p>\n<p>All that was left to do was set up crontab to automatically restart the server on a reboot. This is not necessary but saves you the trouble of manually restarting the server <strong><a href=\"https:\/\/mybroadband.co.za\/news\/energy\/432454-eskom-power-cuts-are-back.html\">after a power outage<\/a><\/strong>.<\/p>\n<p>The site loads quickly, and after playing the snake game for a minute, it is easy to forget that it is hosted on a Raspberry Pi standing on my desk.<\/p>\n<p><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Website.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-432710 size-full\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Website.jpg\" alt=\"\" width=\"640\" height=\"735\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Website.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Website-348x400.jpg 348w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2022\/02\/Website-374x430.jpg 374w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>This is a perfect afternoon project for someone learning about web development, where they can put newly-learned skills into practice.<\/p>\n<p>Using a Raspberry Pi also simplified the project as technical support is readily available and easy to find using Google.<\/p>\n<ul>\n<li>You can access the website hosted on the Raspberry Pi here &#8211; <a href=\"http:\/\/mbbtestserver.ddns.net\" target=\"_blank\" rel=\"noopener\"><strong>mbbtestserver.ddns.net<\/strong><\/a><\/li>\n<\/ul>\n<p>The website will be available for a few days. It should be noted that the server will be down when the mobile data connection drops or there is a power outage.<\/p>\n<h3 class=\"my-4\">Now read: <a href=\"https:\/\/mybroadband.co.za\/news\/hardware\/429670-i-built-an-ambient-backlight-system-for-my-computer-screen-for-r600.html\">I built an ambient backlight system for my computer screen for R600<\/a><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>We built a web server using a Raspberry Pi, connected it to the Internet using an LTE connection, and hosted a website on it. Here is how we did it.<\/p>\n","protected":false},"author":341074,"featured_media":432696,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_sma_x_autopost_status":"idle","_sma_x_autopost_error":"","_sma_x_post_id":"","_sma_facebook_post_id":"","_sma_instagram_post_id":"","_sma_threads_post_id":"","_sma_x_attempts":0,"footnotes":""},"categories":[15,18],"tags":[35,8043,44308],"class_list":["post-432692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hardware","category-internet","tag-headline","tag-raspberry-pi","tag-raspberry-pi-3-model-b"],"_links":{"self":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/432692"}],"collection":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/users\/341074"}],"replies":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/comments?post=432692"}],"version-history":[{"count":2,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/432692\/revisions"}],"predecessor-version":[{"id":432742,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/432692\/revisions\/432742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/media\/432696"}],"wp:attachment":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/media?parent=432692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/categories?post=432692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/tags?post=432692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}