Deploy a Web App Built with Laravel+Node.JS+Redis on Android Termux

In this post, the steps to deploy a Web App built with Laravel+Node.JS+Redis on Android Termux environment are described.

Table of Contents

The Web App to deploy

The web app is built with PHP/Laravel, node.js and redis.

The code will be deployed in $HOME/firstchart.

https://drive.google.com/file/d/1IUFCGSBIXxbmRrx_neX9PDLcM4C_Ctak/view?usp=sharing

https://github.com/maximus1127/neweyechart

Install termux.app

Get and install the APK from Google Play or F-Droid.

You can get the links from the website.

https://termux.com/

Install packages in termux

After starting termux app, you can run commands in the terminal.

System Info

1
2
3
4

whoami # the user name in use

ifconfig # find the IP address

info

Utility packages

  • Package wget and curl are used to download files from HTTP servers.

  • Package vim is a editor.

1
pkg install wget curl vim

SSH

1
pkg install sshd

Start SSH server

1
sshd

The SSH server in termux can only be logged in with a key files. Go to https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html and get putty.exe & puttygen.exe.

  • putty.exe: a SSH client
  • puttygen.exe: a RSA and DSA key generation utility

Use puttygen.exe to generate key files

puttygen.png

Add public key to ~/.ssh/autherized_keys

To move termux.pub to Android, you can host the file on a HTTP or FTP server in local network. Then download it with wget.

1
wget http://192.168.1.106:8000/termux.pub # Use your own address

Just append the content into ~/.ssh/autherized_keys

1
cat termux.pub >> ~/.ssh/autherized_keys

Use putty.exe to login

putty_1.png

putty_2.png

putty_3.png

putty_4.png

putty_5.png

proot

1
pkg install proot # Nginx needs chroot to work

After installing proot, you can use command termux-chroot to enter simulated root environment.

1
termux-chroot

Git (optional)

1
pkg install git # To get code from Github

Python (optional)

1
pkg install python2 # To build code when installing node modules

clang (optional)

1
pkg install clang # g++ to build code

redis

1
pkg install redis

node.js

1
pkg install node

PHP

1
pkg install php

Nginx

1
pkg install nginx

php-fpm

1
pkg install php-fpm

Configuration

Update /etc/nginx/nginx.conf

You can get the file from nginx.conf.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 8080;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

root /data/data/com.termux/files/home/firstchart/public;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data/data/com.termux/files/usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

Update /etc/php-fpm.d/www.conf

Edit the listen address.

1
listen = 127.0.0.1

You can also get the file from www.conf.

node modules

After upload code in $HOME/firstchart, you need to install the node modules.

1
2
3
4
5
6
7
cd $HOME/firstchart

npm install --production

# or

NODE_ENV=production npm install

Laravel

If the code does contains vendor files, install composer and packages.

  • composer
1
2
3
4
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
  • packages
1
php composer.phar install

Startup script

Edit ~/.bashrc. You can also get it from .bashrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# bootstrap
if [ "XXX$HOME" = "XXX/home" ]
then
uname -a

# redis
pgrep redis-server || (redis-server &)

# node
cd /home/firstchart
pgrep node || (node server.js &)
cd /home

# php-fpm
pgrep php-fpm || php-fpm

# NGINX
pgrep nginx || nginx
else
# chroot if not in root environment
termux-chroot
fi

After updating .bashrc, make it in effect.

1
source ~/.bashrc

Visit the app

app

references

[1] https://getcomposer.org/download/

[2] https://www.sitepoint.com/android-elephpant-laravel-android-phone/

文章目录
  1. 1. The Web App to deploy
  2. 2. Install termux.app
  3. 3. Install packages in termux
    1. 3.1. System Info
    2. 3.2. Utility packages
    3. 3.3. SSH
      1. 3.3.1. Start SSH server
      2. 3.3.2. Use puttygen.exe to generate key files
      3. 3.3.3. Add public key to ~/.ssh/autherized_keys
      4. 3.3.4. Use putty.exe to login
    4. 3.4. proot
    5. 3.5. Git (optional)
    6. 3.6. Python (optional)
    7. 3.7. clang (optional)
    8. 3.8. redis
    9. 3.9. node.js
    10. 3.10. PHP
    11. 3.11. Nginx
    12. 3.12. php-fpm
  4. 4. Configuration
    1. 4.1. Update /etc/nginx/nginx.conf
    2. 4.2. Update /etc/php-fpm.d/www.conf
    3. 4.3. node modules
    4. 4.4. Laravel
    5. 4.5. Startup script
  5. 5. Visit the app
  6. 6. references
,