First, you need to understand that to set up a server, you need a public IP address, which means others can directly access your address. Previously, IPv4 addresses were used, but there are only 4.2 billion addresses globally, which is simply not enough. Therefore, many people share a single IP.
In simple terms, you get an IP, and then you can use a router to distribute countless IPs for others to access the internet. This is the principle, but because many people share the same IP, setting up a server becomes impossible.
Thus, IPv6 was born, which is said to be able to assign an address to every grain of sand on Earth. The number of such addresses is so vast that unless we enter an interstellar age, it is impossible to exhaust them.
Now, IPv6 is almost universally adopted, but the current network environment in the country is really complex. Many people are still using old routers or do not know how to set them up, which prevents many from accessing IPv6 websites normally.
Currently, almost all broadband providers support IPv6. The reason you cannot access it is that your router is too old or not set up for IPv6. However, you can try connecting your computer directly to the optical modem. For mobile phones, you can turn off Wi-Fi and use mobile data to access IPv6 websites.
Of course, there is also bad news. In some areas, providers have blocked ports 80 and 443, which are dedicated ports for websites. If these ports are blocked, it becomes troublesome. For example, I normally access my blog at http://jxyblog.top.
If the ports are blocked, I have to change the port to http://jxyblog.top:89. Browsers must include the port number, which is quite inconvenient.
Additionally, some optical modems have firewalls set up internally, preventing external access to your website. You need to obtain the super password for the optical modem to disable the firewall or change to bridge mode to dial directly with the router. Both situations require the super password for the optical modem.
So, pray that the internal firewall of your optical modem is set to off by default, so you don't have to deal with the hassle and can connect directly.
A Few Necessary Preparations After You Have an OpenWRT Router#
First, you need to obtain an IPv6 address. My network uses the optical modem to dial, not the router. My computer is directly connected to one port of the optical modem, and the router is connected to another port. Both my computer and the router can obtain an IPv6 address.
Ensure the router can connect to the internet. First, connect the computer to the router's LAN port, then log in to the router management interface at 192.168.1.1. First, install Chinese support and set the system time zone.
Upon first login, you will be prompted to change the default password. Just change it directly; do not change the username; keep it as root.
Then click on the second system tab at the top, select the software option, and finally click the update opkg button. This step requires a normal internet connection.
After a moment, when the update is complete, you will see all the installable software packages. In the first box, enter luci-i18n-base-zh-cn to install the OpenWRT Chinese package, and refreshing will change the interface to Chinese.
Next, enter zoneinfo-asia to install the system time zone support package. After installation, click on the top system - system to set the time zone to Asia/Shanghai.
As a secondary router, it is best to change the LAN port address of the router. Click on the top network - interfaces, there is a green LAN port. Click edit on the right, and change the IPv4 address from 192.168.1.1 to 192.168.2.1.
Then click save and apply in the lower right corner. The router will restart, and you will need to log in to manage the router using 192.168.2.1.
After Your Router is Ready, Let's Install the Lighttpd Server#
Before everything starts, we need a tool called WinSCP. Of course, you can download it from the official website, but it seems the official version is in English. Here, I provide a Chinese version.
WinSCP Chinese version.rar, extraction code: 9tsm, size: 6.18Mb
We will only need this tool throughout the process. It allows you to copy files directly to the router and modify configuration files without using the command line. Download it as a backup.
To allow access to the website on port 80, we need to change the router's port; otherwise, there will be a port conflict that prevents Lighttpd from starting. Open /etc/config/ and find the uhttpd file. Right-click to edit and change the following four entries to this:
list listen_http '0.0.0.0:8080'
list listen_http '[::]:8080'
list listen_https '0.0.0.0:444'
list listen_https '[::]:444'
This changes the management interface port of the router to 8080. We will use the address 192.168.2.1:8080 to manage the router later.
Let me explain uhttpd. It is a web server just like Lighttpd. We log into the router management interface via a web page, which is implemented by it. To avoid conflicts between the two servers, we need to change the port. Of course, some experts can deploy directly using uhttpd + PHP without installing Lighttpd.
Next, click on the router system - reboot. After the router restarts, enter http://192.168.2.1:8080 in the browser to log into the router.
Log into the router, click on system - packages, and first update the software packages. After updating, enter lighttpd in the filter and click install. It will automatically install other dependency packages.
After installation, also install lighttpd-mod-fastcgi and lighttpd-mod-rewrite. Fastcgi is the interface for connecting to PHP, which is essential.
Rewrite is a rewriting component used for pseudo-static websites. It can be installed or not; actually, this component only has one configuration file, less than 1Kb in size, so it can be installed as a backup.
Next, we will need the WinSCP tool mentioned above. Open the software, and a new site creation box will pop up.
File protocol: scp
Hostname: 192.168.2.1 Port: 22 # Router management address
Username: root Password: 123456 # Your router's account and password
Then click save, check the box to save the password, and then click login. This way, you can see all the files in the router.
Next, we will modify the configuration file. Open /etc/lighttpd/lighttpd.conf and right-click to edit lighttpd.conf.
Modify the following entries; the latter is the directory where your website files are stored, which can be modified as you wish. Note: Unless your router has enough space, it is better to store it in RAM. If the ROM space is sufficient or you have an external USB drive, ignore this. The tmp directory is in RAM, and once the power is cut, all data inside is lost. I created a www directory to store website files.
var.server_root = "/tmp/www/"
After modifying, do not change anything else, and then add the following entries:
server.use-ipv6 = "enable"
server.port = 80
$SERVER["socket"] == "0.0.0.0:80"
These three lines mean enabling IPv6, listening on port 80, and being able to listen to both IPv6 and IPv4 simultaneously. After modifying, click save in the upper left corner.
After modifying, you need to restart Lighttpd. You can find Lighttpd in the router - system - startup items and click restart.
Then click on the router - status - system processes to check if the following task is running:
2954 http /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
If it is running, it means the web server has started successfully. We can copy an index.html file to /tmp/www/ and then access it via the browser at http://192.168.2.1.
If the webpage displays normally, it means the web server has been set up successfully. At this point, only static files can be placed; PHP cannot run yet, but this will be gradually written out later.
Lighttpd is Installed, Now Let's Install PHP and SQLite, and Set Up Website Upload#
Still, click on the router's system - packages, and in the text box, enter php.
There are two main packages to install: php8 and php8-cgi. After installing these two, install all the following support packages:
php8-mod-bcmath
php8-mod-calendar
php8-mod-ctype
php8-mod-dom
php8-mod-filter
php8-mod-iconv
php8-mod-mbstring
php8-mod-session
php8-mod-sockets
php8-mod-sqlite3
php8-mod-tokenizer
php8-mod-xml
After installing all the above, we also need to install the database libsqlite3-0. Once everything is installed, all preparations are complete, and we just need to modify the configuration file.
PHP Configuration File Modification
Using WinSCP, open the /etc directory and find php.ini to right-click and edit.
We only need to modify two places:
cgi.fix_pathinfo = 1
doc_root = "/tmp/www"
Just modify the above two entries; do not change anything else. Then add the following timezone setting at the end and save and close.
date.timezone = Asia/Shanghai
PHP configuration modification is complete.
Next is the FastCGI setting for Lighttpd.
Using WinSCP, right-click to edit the /etc/lighttpd/conf.d/30-fastcgi.conf file and add the following code at the bottom:
fastcgi.server = ( ".php" =>
((
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php8-cgi",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "2",
"PHP_FCGI_MAX_REQUESTS" => "100",
),
"max-procs" => 1,
"broken-scriptfilename" => "enable",
)
)
)
Then save and close. After that, click on the router's system - startup items and click restart Lighttpd.
Then click on the router's status - system processes to see if the following programs are running:
/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
/usr/bin/php8-cgi
There should be three php8-cgi processes because I set only three processes due to the low configuration of the router.
At this point, the setup is complete.
The server is set up. Download the latest Typecho files and use WinSCP to copy them to /tmp/www/, ensuring that index.php is in the www directory.
Then right-click the www folder, click properties, and modify the file permissions, checking the following:
√R √W √X
√R √W √X
√R √W √X
Octal table 0777
√ Set group, owner, and permissions recursively.
After completion, open the browser and enter http://192.168.2.1.
At this point, the Typecho installation interface should open, and you can follow the prompts to install it. The website is now fully set up.
Next, if your router has an IPv6 address and is bound to a domain name, then set the inbound data for the WAN port in the router's firewall.
Click on the router's network - firewall and open the WAN port.
Then click save and apply. At this point, you should be able to access it using your mobile phone.