5

Repurpose an abandoned Android phone as a web server

Environmental preparation

First, we need to install a Linux environment on the phone. Choose Termux here, Termux is a terminal emulator for Android

download link

  • You may need to choose the appropriate version according to your phone model
  • After downloading, find a way to send the installation package to the mobile phone, and the Bluetooth I choose to send

Remote link mobile phone

Using the terminal on the phone is a real pain, so we connect remotely via ssh for a better experience
  1. install ssh tool

     # 手机上Termux窗口中直接执行
      # 安装openssh
      pkg install openssh
    
      # 设置登录密码  这里会让输入两次密码以确认
      passwd
    
      # 启动它 [简单的启动不需要任何参数]
      sshd
  2. Set a static IP for your phone

    Usually the wifi connection ip is dynamic, which is not conducive to our remote connection and memory
    • settings - wifi - ip settings
  3. PC terminal connection

    bash command
     # 默认情况下Termux的端口是8022, 这里需要根据你的实际IP来连接
      ssh -p 8022 root@192.168.1.11
    
      #输入密码后连接成功

start a service

Here we use node as service
 # 安装node  
  pkg install nodejs

  # 查看安装信息
  node -v
  npm -v

  # 安装一个静态服务库
  npm install http-server -g

  # 创建服务根目录以及文件
  cd ../
  mkdir ./code
  touch ./code/index.html

  # 写入hello world
  echo "<html><head></head><body>helld world</body></html>" >> ./code/index.html
  
  # 启动服务 
  http-server ./code

  # http://192.168.1.11:8080  [这里访问手机ip+端口]

future

At present, this is still an intranet access, only LAN access, the next article will introduce the external network

ottfe


Riki一二三
6.1k 声望1.2k 粉丝