Building a Personal Server Using an Android Device
Android devices, with their Linux-based kernel, can be repurposed as personal servers. This guide covers setting up a server environment, enabling remote access, connecting a MySQL database, and deploying a simple blog.
Setting Up the Server Environment
Download and install KSWEB from your browser. After installation, add two ports: 8080 for local access and another for external connections. Access the server locally via http://localhost:8080 on your device, and from a computer using http://[device-ip]:8080.
Note: Ensure both devices are on the same local network for initial acess.
Enabling Remote Access via Tunneling
To allow access from different networks, use an internal network tunneling service like Sunny-Ngrok. Register on their site, complete real-name verification (costs 2 yuan), and create a tunnel. Select HTTP protocol, set a custom subdomain, and note the tunnel ID and provided public domain.
Installing Python on Android
Download Termux from its GitHub releases page (e.g., arm64 version). Install it, then run:
pkg install python
If downloads are slow, try switching mirrors by searching for "python mirror Termux."
Granting File Access Permissions
Run:
termux-setup-storage
Follow prompts to allow Termux access to device storage.
Running the Tunneling Client
Download the Python client from Sunny-Ngrok. Move sunny.py to /storage/emulated/0/Download. In Termux, navigate to that directory:
cd /storage/emulated/0/Download
Execute:
python sunny.py
When prompted, enter the tunnel ID. Refer to Sunny-Ngrok's Android documentation for details.
Troubleshooting Common Issues
- If
cdcommands fail, navigate step-by-step usingcd ..to reach the root directory, then proceed. - For errors like
ImportError: dlopen failed: library "libssl.so.3" not found, install OpenSSL:
pkg install openssl-tool
Then rerun sunny.py.
Connecting a MySQL Database
Use phpMyAdmin for database management. Download it from the official site or a mirror if slow. Extract the files, locate config.sample.inc.php, copy it, and rename to config.inc.php. Modify the following sections:
$cfg['blowfish_secret'] = 'random_32_character_string_here';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
Transfer the folder to /ksweb/tools on your device. In KSWEB, create a new host in LIGHTTPD, set the port (e.g., 8001), and point the host address to the phpMyAdmin folder location. Access via http://[device-ip]:8001 from a computer.
Deploying a Simple Personal Blog
Download Typecho from its official site. Extract the files and move them to the htdocs directory on your device, which serves content on port 8080. Access http://[device-ip]:8080 and follow the setup instructions to configure the blog. After completion, you can customize the blog by adding personal pages to the Typecho directory.
Self-built servers may lack the robustness of commercial solutions like Alibaba Cloud in handling attacks or high traffic. Performance depends on the old device's capabilities. For issues not covered, search online for solutions—learning to find answers efficiently is key in tech.