First, you need to understand that to set up a server, you need a public IP address that others can directly access. Previously, IPv4 addresses were used, but there are only about 4.2 billion of them globally, which is simply not enough. As a result, many people share a single IP.
In simple terms, you get an IP address, and then you can use a router to distribute countless IPs for others to access the internet. This is the principle behind it, 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 domestic network environment is really complex. Many people are still using old routers or do not know how to set them up, resulting in many being unable to access 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 some 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 port is 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 internal firewalls, making it impossible to access your website from the outside. 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 all that hassle and can connect directly.
A Few Essential Preparations After You Have an OpenWRT Router#
First, you need to obtain an IPv6 address. My network uses the optical modem for dialing, not the router. My computer is connected directly 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 that the router can connect to the internet normally. First, connect your computer to the LAN port of the router, then log in to the router management interface at 192.168.1.1. First, install Chinese support and set the system timezone.
Upon first login, you will be prompted to change the default password; just change it directly, and do not change the username, which should remain 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 timezone support package. After installation, click on "system" at the top, and you can set the timezone to Asia/Shanghai.
As a secondary router, it is best to change the LAN port address of the router. Click on "network" - "interfaces" at the top, and 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" at the bottom right. The router will restart, and you will need to log in to manage the router using 192.168.2.1 in the future.
After Your Router is Ready, Let's Install the Lighttpd Server#
Before we start, we need a tool called WinSCP. You can download it from the official website, but it seems the official version is in English, so here is 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 for 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 preventing Lighttpd from starting. Open /etc/config/ and find the uhttpd file. Right-click to edit it 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 router's management interface port 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 like Lighttpd, and when we log into the router's management interface via the web page, it is implemented by uhttpd. To avoid conflicts between the two servers, we need to change the port. Of course, some experts can directly use uhttpd + PHP to deploy without installing Lighttpd.
Next, click on "system" - "reboot" on the router. After the router restarts, enter http://192.168.2.1:8080 in the browser to log into the router.
Once logged in, click on "system" - "packages," and we will first update the software packages. After updating, enter lighttpd in the filter box 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 that connects to PHP, and this is essential.
Rewrite is a rewriting component used for pseudo-static websites. It is optional, but this component only has one configuration file, which is less than 1Kb in size, so it can be installed for backup.
Next, we will use WinSCP as mentioned above. Open the software, and a new site dialog 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 click login. You will then 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, where the back part is the directory where your website files are stored, which can be modified freely.
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, you can 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 modification, 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 http://192.168.2.1 in the browser.
If the webpage displays normally, it means the web server has been set up successfully. At this point, only static files can be placed, and PHP cannot run yet; I will gradually write about that 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.
You need to install two main packages: 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
Once all of the above are installed, we will finally install the database libsqlite3-0.
After everything is installed and ready, we just need to modify the configuration file.
PHP Configuration File Modification
Using WinSCP, open the /etc directory and find php.ini to edit it.
We only need to modify two places:
cgi.fix_pathinfo = 1
doc_root = "/tmp/www"
Just modify the above two entries, and do not change anything else.
Then add the following timezone setting at the end and save it:
date.timezone = Asia/Shanghai
PHP configuration modification is complete.
Next is the FastCGI settings 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 it.
After that, click on the router's system - startup items and restart Lighttpd.
Then click on the router's status - system processes to check 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 router's low configuration.
At this point, the server setup is complete. 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 completing this, 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.
Thus, the website is completely set up.
Next, if your router has an IPv6 address and is bound to a domain name, then set up the inbound data for the WAN port in the router's firewall.
Click on the router's network - firewall to open the WAN port.
Then click save and apply. At this point, you should be able to access it from your mobile phone.