[Java] You can do anything with an Android smartphone or tablet! Summary of moving with Termux

5 minute read

“There are unused Android smartphones and tablets.” “Can this be a server?”

That dream can be fulfilled**. **

It’s a little awkward, but if you do it you can do it.

How to move

Android has an application called “Termux”. You can use it to run Linux. The packages are also managed by APT and are abundant.


You may also find it inconvenient to use a keyboard such as GBoard. “Hacker’s Keyboard” is recommended.



Those who have been familiar with Linux will be accustomed to it.

First, you need to grant permissions to allow Termux to access files in your terminal.

$ termux-setup-storage

If you execute this, a permission dialog will appear on Android 8 or later, so please allow it.

Termux provides a “pkg” command as an alias for apt.

Command Description
pkg update apt update and then apt upgrade
pkg install <package…> apt install <package…>
pkg remove apt remove <package…>

There are other commands. You can get help by just running ```pkg


Let's get the package up to date.

$ pkg update

Once the update is complete, the preparation is over.

Termux basics


Within Termux, the root directory is /data/data/com.termux/files/usr. This can be represented by ```$PREFIX


Here is an example:

|Original directory path|Termux path|
|/etc |$PREFIX/etc |
|/usr/share |$PREFIX/share|
|/bin |$PREFIX/bin |

## Editor
nano is included as standard.

$ nano filename

You can start with.

Here are the keyboard operations that are often used.

Keyboard input Meaning
Ctrl + X Exit
Ctrl + O Save

Restricted ports that can be used

Termux can be used in the range of 1024-65535. Since 80 and 443 cannot be used, port conversion may be necessary when publishing to the Internet.

This and that

Enter shell from PC (telnet)

**Originally, Telnet should not be published online. Let’s just use it locally. **

$ pkg install busybox

After installing busybox

$ busybox telnetd -p 5888

will do. The ``` -p number

is the port number.

It can be accessed using TeraTerm.

## Build HTTP server
### Package installation
Termux also has apache2 (httpd) and nginx packages, so you can install it.
If you also want to use PHP, you need ```php``` and ```php-apache
#### **` for apache2.`**

For nginx you need php and ```php-fpm


[For apache2]

$ pkg install apache2 php php-apache

[For nginx]

$ pkg install nginx php php-fpm

change settings (apache2)

The configuration file is ```$PREFIX/etc/apache2/httpd.conf


If you use PHP, you need to change the settings.

$ nano $PREFIX/etc/apache2/httpd.conf

Start the editor with.

First, I think there is an item called ```ServerRoot “…”

at the beginning.

On the next line

HostnameLookups On

Is described. This is the setting to display the host name in the log.


LoadModule mpm_worker_module xxxxxxxx

There should be a line that says. Comment it out.
Instead, one above that line

LoadModule mpm_prefork_module xxxxxxx

Uncomment out (remove the #)

Next, as you go down, you'll see the ```DocumentRoot "..."
#### **` line.`**

Around it

Options Indexes FollowSymLinks

Line, add ```ExecCGI


 When I add more

Options Indexes FollowSymLinks ExecCGI

Will be.
Below that

DirectoryIndex index


DirectoryIndex index.php index.html index.htm

Change to.

Finally, on the last line of the file

LoadModule php7_module libexec/apache2/libphp7.so AddHandler php7-script .php

Is added.
** Remember to save with Ctrl+O! **

### change settings (nginx)
It may be a little more troublesome than httpd.

The configuration file is ```$PREFIX/etc/nginx/nginx.conf
#### **`.`**
$ nano $PREFIX/etc/apache2/httpd.conf

Start the editor with.


location / {

I think there is a line. In it

index index.html index.htm;


index index.php index.html index.htm;

I will.


# pass the PHP script
location ~ \.php$ {

I think there is a line. It should have been commented out, so remove that part.

Then replace that part with

location ~ \.php$ {
 root (any directory);
 fastcgi_pass unix:/data/data/com.termux/files/usr/var/run/php-fpm.sock;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;

Save with Ctrl+X** and exit the editor.

Next, set PHP.

$ nano $PREFIX/etc/php-fpm.d/www.conf

Start the editor with.

As you scroll, you will see the line ```listen = ….



listen = /data/data/com.termux/files/usr/var/run/php-fpm.sock

Save with Ctrl+O** and you're done.

### start httpd
To start httpd


$ httpd

It’s just good. It emits some logs, but you don’t have to worry about it. When you stop

$ httpd -k stop


$ killall httpd


start nginx


$ nginx

And just

If you use PHP, before executing nginx


Should be run.

When you stop

$ killall nginx


Move DiscordBot (Python)

If you created a bot in Python, you can run it in Termux as well.

Python can install 3.8.

$ pkg install python make automake autoconf clang build-essential git

This installation work consumes about 500MB. Make sure there is 2GB or more free space in the storage.


$ pip install wheel requests
$ pip install -U "discord.py[voice]"

Run. Build of PyNaCl is done on the way. Depending on the performance of your smartphone/tablet, it may take 2-5 minutes to complete. Please make sure you have enough time.

Since I also installed git, you can drop the program from the repository.

Remove the program from GitHub

I don’t think anyone who is accustomed to using Git needs any explanation. Therefore, describe the command as if you know how to use it in advance.

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
$ git config --global crediential.helper "cache"
$ git clone https://github.com/xxxx/xxxx.git

start bot

While in the directory containing the program you want to launch

$python filename.py

will do.## Build a server for Minecraft (PC version) How, Termux can run Java.

Let’s install it right away. Here I will use the ones of the volunteers. It will be OpenJDK 8.

$ pkg install wget && wget https://raw.githubusercontent.com/MasterDevX/java/master/installjava && bash installjava

It may take some time for the download to finish. I patiently wait. After that, if you get help by typing ```java

, you are done.

### download server.jar

You can download the server from https://mcversions.net/.
I will omit about the usage.
Download the server program that matches the version you want to build.

| Version | URL |

Copy the above URL,


$ cd ~
$ mkdir mcserver
$ cd mcserver
$ wget copied URL

Run. You can paste it by long-pressing anywhere on the screen and pressing “PASTE”. If you can download

$ echo "eula=true"> eula.txt
$ java -jar server.jar

will do. Various logs are output and the world is generated. Note that if the performance is too low, it may cause a crash.

Also, with Android 8 or later

$ java -jar server.jar
Bad system call

Before executing this command,

$ proot -0

Please run the.

in conclusion

How was it? There were quite a few things I could do. There are more details written on the internet, so please try it. Have a nice Termux life!