Article directory
- overview
- Install Raspberry Pi OS using Raspberry Pi Imager
- Set up the Apache web server
- test web site
- Install the static sample site
- Publish the web site to the public network
- Install Cpolar Intranet Penetration
- cpolar for token authentication
- Generate cpolar random domain URL
- Generate cpolar second-level subdomain
- Save parameters to cpolar configuration file
- Test the modified configuration file
- Configure the cpolar service to start automatically at boot
overview
This is great for setting up your first website and learning not only to manage a wordpress site but also to learn Linux. You will need a Raspberry Pi, a few hours, and a computer to download the image. The Raspberry Pi (RPI) is the perfect device to learn this stuff.
Also check out the official RaspberryPi project site
Source: https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress
Install Raspberry Pi OS using Raspberry Pi Imager
Download the Raspberry Pi image tool for your operating system. It supports most operating systems (Windows, Mac and Linux).
https://www.raspberrypi.org/downloads/
- Run and install Raspberry Pi image tool
- Select Raspberry Pi OS -> Raspberry Pi OS (32-bit)
- Insert the SD card into the computer
- Click the Write button
Set up the Apache web server
Apache is a popular web server application that you can install on a Raspberry Pi to allow it to serve web pages.
Apache itself can serve HTML files over HTTP. With additional modules, it can provide dynamic web pages using scripting languages such as PHP.
sudo apt-get install apache2 -y
sudo service apache2 restart
test web site
By default, Apache places a test HTML file in the web folder, which you can view from your Pi or from another computer on the 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 in your browser window:
Install the static sample site
In order to make the content of the site more meaningful, we deploy a simple static demo site – meditation and 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
Re-open in the browser and refresh the site: http://localhost
This is a small tool site for meditation, you can use it to help yourself relax for 2-10 minutes after work.
It can choose different meditation scenarios and relaxation time (2-5-10 minutes).
Publish the web site to the public network
Currently, this site can only be accessed on a local site, and cannot be accessed by public network users. In order for everyone to visit the beautiful site you created, we need to do the following things.
Install Cpolar Intranet Penetration
cpolar official website: https://www.cpolar.com/
cpolar is an intranet penetration tool, which can expose your intranet site to the public network, so that everyone can visit 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:
cpolar for token authentication
If you do not have a cpolar account yet, please go to the cpolar official website to register and log in to the background to obtain an authentication token
cpolar authtoken xxxxxxxxxxxxxxxxxx
Generate cpolar random domain URL
cpolar http -region=cn_vip 80
The picture above shows that cpolar published the intranet site to a random domain name URL: https://711d7522.vip.cpolar.cn
- Let's open the browser and try: https://711d7522.vip.cpolar.cn
Now, we have released the web site of the intranet to the public network, and anyone can visit it.
Go back to the terminal window, CTRL+C
press the key , and exit cpolar
At this point, the public address can no longer be accessed.
Generate cpolar second-level subdomain
Although it has been released to the public network, the domain name changes randomly and is only suitable for temporary testing. If it is to be used for a long time, we need to configure a second-level subdomain name.
Steps:
- Upgrade to cpolar Basic Package
- Log in to the cpolar background –> Reserve –> reserve the second-level subdomain, such as adding
dev9
, selectingVIP China
a region
Test the domain name in the foreground terminal
cpolar http -subdomain=dev9 -region=cn_vip 80
If the display is normal, it means that we have already configured it.
Use the new domain name to visit in the browser: https://dev9.vip.cpolar.cn
If it is normal, it means that our fixed second-level subdomain name is configured.
Save parameters to cpolar configuration file
Just now we run the cpolar program in the foreground. After closing it, the domain name disappears. Now we save the parameters to the configuration file. To support self-starting operation in the background after booting.
- edit configuration file
nano /usr/local/etc/cpolar/cpolar.yml
As shown in the picture:
The figure above is a sample configuration file, which configures two default tunnels: an ssh tunnel and a website tunnel.
Parameter Description:
authtoken: xxxxxxxxxxxx #认证token
tunnels:
ssh: #隧道名称,表示ssh,名称可以自定义
addr: 22 #端口号为22
proto: tcp #协议tcp
region: cn_vip #地区,cn_vip,可选:us,hk,cn,cn_vip
website: #隧道名称,用户可以自定义,但多隧道时,不可重复
addr: 8080 #本地Web站点端口
proto: http #协议http
region: cn_vip #地区,cn_vip,可选:us,hk,cn,cn_vip
In this example, we need to modify the following:
- Change the default
8080
port of the website tunnel to80
- add a line
subdomain: "你的二级子域名"
The modified effect is shown in the figure:
Note: config files are yaml
formatted, indentation sensitive, and cannot have TAB键
.
Then press CTRL+X
, exit, prompt you whether to save, answer Y
, confirm the save file path,回车
Test the modified configuration file
Start all tunnel tests in the foreground
cpolar start-all
As shown in the above figure, it is normal, press CTRL+C to exit
If an error is reported, it will prompt that there is an error in a certain line of the configuration file, please modify it again. Until the correct output is similar to the above picture.
Configure the cpolar service to start automatically at boot
- Configure cpolar to start automatically at boot
sudo systemctl enable cpolar
- Daemon mode, start cpolar
sudo systemctl start cpolar
- View cpolar daemon status
sudo systemctl status cpolar
As shown in the figure, the startup status is successful
- Restart
sudo reboot
After restarting, check if the cpolar tunnel is still online
Visit the background –> status https://dashboard.cpolar.com/status
As shown in the figure, the configuration is successful
Reprinted from the article of cpolar: Building a Web site on the Raspberry Pi