Building a Web site on a Raspberry Pi [no public IP needed].

Time:2024-6-7

catalogs

1. Overview

2. Install Raspberry Pi OS with Raspberry Pi Imager

3. Setting up the Apache Web server

3.1 Testing the web site

3.2 Installing a static sample site

3.3 Publishing web sites to the public network

3.4 Installing Cpolar

3.5cpolar for token authentication

3.6 Generate cpolar random domain URLs

3.7 Generating cpolar second-level subdomains

3.8 Save parameters to the cpolar configuration file

3.9 Testing the modified configuration file

3.10 Configuring the cpolar service power-on self-starter

1. Overview

This is perfect for setting up your first website and learning not only to manage a wordpress site, but Linux as well.You will need a Raspberry Pi, a couple of hours and a computer to download the images. The Raspberry Pi is the perfect device for learning these things. Also check out the official RaspberryPi project site! Source.https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress

2. Install Raspberry Pi OS with Raspberry Pi Imager

Download the Raspberry Pi Image Tool for your operating system. It supports most operating systems (Windows, Mac and Linux). Raspberry Pi OS – Raspberry Pi
  • Run and install the Raspberry Pi Image Tool
  • Select Raspberry Pi OS -> Raspberry Pi OS (32-bit)
  • Insert the SD card into the computer
  • Click the Write button
Building a Web site on a Raspberry Pi [no public IP needed].

3. Setting up the Apache Web server

Apache is a popular web server application that you can install on your Raspberry Pi to allow it to serve web pages. Apache itself can serve HTML files over HTTP. With add-on modules, it can serve dynamic web pages using scripting languages such as PHP.
sudo apt-get install apache2 -y
sudo service apache2 restart

3.1 Testing the web site

By default, Apache places the test HTML file in the web folder, where you can view the page from your Pi or another computer on your network. Open the Apache default web page on the Raspberry Pi:
  • Open Chromium by selecting Internet > Chromium Web Browser from the menu.
  • Enter the address http://localhost
You should see it in your browser window:
Building a Web site on a Raspberry Pi [no public IP needed].

3.2 Installing a static sample site

To make sense of the site’s content, we deploy a simple static demo site – the Meditation Relaxation site.
cd /var/www/html/
sudo rm *
sudo wget https://www.cpolar.com/static/downloads/meditation-app-master.tar.gz
sudo tar xzf meditation-app-master.tar.gz
sudo mv meditation-app-master/* .
sudo rm -rf meditation-app-master meditation-app-master.tar.gz
Reopen in your browser and refresh the site: http://localhost
Building a Web site on a Raspberry Pi [no public IP needed].
This is a gadget site for meditation that can be used to help yourself relax for 2-10 minutes after work. It allows you to choose different meditation scenarios and relaxation times (2-5-10 minutes).

3.3 Publishing web sites to the public network

Currently, this site can only be accessed on the LAN station, it is not accessible to public network users. In order for everyone to access the beautiful site you created, we need to do the following.

3.4 Installing Cpolar

cpolar is an intranet penetration tool that exposes your intranet site to the public web so that everyone can access your site.
  • cpolar one-click installation script: (domestic users)
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
  • or short link installation method: (foreign users)
curl -sL https://git.io/cpolar | sudo bash
  • View cpolar version information
cpolar version
If it is displayed normally, the installation is successful, as shown in the figure:
Building a Web site on a Raspberry Pi [no public IP needed].

3.5cpolar for token authentication

If you don’t have a cpolar account yet, go to thecpolar Official websiteregister andlog inBackstage AccessAuthentication token
cpolar authtoken xxxxxxxxxxxxxxxxxx

3.6 Generate cpolar random domain URLs

cpolar http -region=cn_vip 80
Building a Web site on a Raspberry Pi [no public IP needed].
The image above shows that cpolar took the intranet site and posted it to a random domain URL: https://711d7522.vip.cpolar.cn
  • Let’s try this with an open browser: https://711d7522.vip.cpolar.cn
Building a Web site on a Raspberry Pi [no public IP needed].
Now that we have published the intranet web site to the public network, anyone can access it. To return to the terminal window, pressCTRL+Ckey to exit cpolar At this point, the public address is no longer accessible.

3.7 Generating cpolar second-level subdomains

Although it has been published to the public network, the domain name is randomly changing and is only suitable for temporary test use. If we want to use it for a long time, we have to configure a second-level subdomain. Operational Steps:
  • Upgrade to cpolar basic package
  • Log in to the cpolar backend -> Reservations -> Reserve second level subdomains, e.g. adddev9Selection of regionsVIP Chinaas suffix city name, means prefecture or county (area administered by a prefecture level city or county level city)
Test the domain name in the front end
cpolar http -subdomain=dev9 -region=cn_vip 80
If the display is normal, then we have configured it.
Building a Web site on a Raspberry Pi [no public IP needed].
Go to: https://dev9.vip.cpolar.cn in your browser with your new domain name Normal means that our fixed second-level subdomain is configured.

3.8 Save parameters to the cpolar configuration file

Just now we ran the cpolar program in the foreground, turned it off and the domain name disappeared, now we save the parameters to the configuration file. to support boot background self-start running.
  • Edit Configuration File
nano /usr/local/etc/cpolar/cpolar.yml
As pictured:
Building a Web site on a Raspberry Pi [no public IP needed].
The image above shows a sample configuration file that will configure two default tunnels: an ssh tunnel and a website tunnel. Parameter Description:
authtoken: xxxxxxxxxxxx # Authentication token

tunnels:
  ssh: # tunnel name for ssh, name can be customized
    addr: 22 # port number 22
    proto: tcp # Protocol tcp
    region: cn_vip #region, cn_vip, optional:us,hk,cn,cn_vip
  website: #Tunnel name, user-definable, but not repeatable for multiple tunnels.
    addr: 8080 #local web site port
    proto: http # Protocol http
    region: cn_vip #region, cn_vip, optional: us,hk,cn,cn_vip
In this example, we need to change the following:
  • Setting the website tunnel’s default8080The port is modified to80
  • Add a linesubdomain: "Your second-level subdomain"
The modified effect is shown in the figure:
Building a Web site on a Raspberry Pi [no public IP needed].
Caution: The configuration file isyamlformatted, indentation-sensitive, and there can be noTAB key。 and then pressCTRL+X, exit, prompting you to save or not, answerY, confirming the save file path.enter (computer key)

3.9 Testing the modified configuration file

Start all tunnel tests in the foreground
cpolar start-all
Building a Web site on a Raspberry Pi [no public IP needed].
As shown above, it is normal, press CTRL+C to exit If an error is reported, it will indicate that there is an error in a line of the configuration file, so please modify it again. Until similar to the above figure correct output.

3.10 Configuring the cpolar service power-on self-starter

  • Configure cpolar to boot up
sudo systemctl enable cpolar
  • Daemon mode, start cpolar
sudo systemctl start cpolar
  • View cpolar daemon status
sudo systemctl status cpolar
As illustrated in the figure, the startup state is successful
Building a Web site on a Raspberry Pi [no public IP needed].
  • reboot
sudo reboot
After rebooting, check if the cpolar tunnel is still online Access Backend->Status https://dashboard.cpolar.com/status As shown in the figure, the configuration is successful
Building a Web site on a Raspberry Pi [no public IP needed].