演示设备

硬件

aarch64 Android

1
2
~ $ uname -a
Linux localhost 4.4.153-perf-g31d46477eb90 #1 SMP PREEMPT Sun Mar 29 01:11:45 CST 2020 aarch64 Android

软件

Termux
需要开启root并安装Termux拟真工具。

环境要求

  • kodbox

  • nginx 1.20

  • php 7.4

  • MySQL 5.7 (可跳过,PHP内置轻量级数据库,适合小规模使用)

  • redis 6.2(可跳过,内置文件缓存方式)

kodbox

下载安装

官网

1
2
3
4
5
wget https://static.kodcloud.com/update/download/kodbox.1.33.zip
mkdir kodbox
mv kodbox.1.33.zip kodbox
cd kodbox
unzip kodbox.1.33.zip && chmod -Rf 777 ./*

nginx

下载安装

1
2
pkg install nginx -y
nginx -v

配置nginx

1
2
mv /data/data/com.termux/files/usr/etc/nginx/nginx.conf /data/data/com.termux/files/usr/etc/nginx/nginx.conf.old
vim /data/data/com.termux/files/usr/etc/nginx/nginx.conf

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
user  root;
worker_processes auto;
pid /data/data/com.termux/files/usr/var/run/nginx.pid;

events {
use epoll;
worker_connections 51200;
multi_accept on;
}

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"';

server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 10G;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;

fastcgi_connect_timeout 3600;
fastcgi_send_timeout 3600;
fastcgi_read_timeout 3600;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
server_tokens off;

server {
listen 80;
root /data/data/com.termux/files/home/kodbox/html; #改成自己的站点目录
index index.php;
server_name _;
error_log /data/data/com.termux/files/usr/var/log/nginx/kodbox_error.log notice;
# access_log /data/data/com.termux/files/usr/var/log/nginx/kodbox_access.log main;
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_pass unix:/data/data/com.termux/files/usr/var/run/php-fpm.sock;
fastcgi_index index.php;
set $path_info $fastcgi_path_info;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
location = /favicon.ico {
log_not_found off;
}
}
}

php

下载安装

1
2
3
apt install php
apt install php-fpm
php --version

配置PHP

php配置

1
vim /data/data/com.termux/files/usr/etc/php.ini

php.ini

1
2
3
4
5
6
post_max_size = 512M;
upload_max_filesize = 512M;
memory_limit = 1024M;
max_execution_time = 3600;
max_input_time = 3600;
cgi.fix_pathinfo=1

php-fpm配置

1
vim /data/data/com.termux/files/usr/etc/php-fpm.d/www.conf

www.conf

1
2
3
4
5
6
7
8
9
10
11
[www]
pm = static
user = root
group = root
listen = /data/data/com.termux/files/usr/var/run/php-fpm.sock
listen.owner = root
listen.group = root
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 35

mysql

如果您不考虑使用mysql,可以跳过此节。

下载安装

1
2
pkg install mariadb -y
mariadb --version

配置Mysql

1
vim /data/data/com.termux/files/usr/etc/my.cnf

my.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# This group is read both by the client and the server
# use it for options that affect everything
#
####[client-server]

#
# include *.cnf from the config directory
#
####!includedir /data/data/com.termux/files/usr/etc/my.cnf.d

binlog_cache_size = 192K
thread_stack = 384K
join_buffer_size = 4096K
key_buffer_size = 512M
sort_buffer_size = 2048K
read_buffer_size = 2048K
read_rnd_buffer_size = 1024K
thread_cache_size = 192
query_cache_size = 256M
tmp_table_size = 1024M
max_connections = 500
innodb_buffer_pool_size = 1024M
innodb_log_buffer_size = 512M
1
2
3
4
5
6
7
8
$ mysqld
$ grep 'temporary password' /var/log/mysqld.log ##获取临时密码
$ mysql_secure_installation ##根据提示步骤进行安全设置

$ mysql -uroot -p ##连上数据库,单独创建kodbox数据库和账号
CREATE DATABASE db_kodbox;
grant all privileges on db_kodbox.* to 'user_kodbox'@'%' identified by 'your_password';
flush privileges;

redis

如果选择使用文件缓存,可以跳过此节。

下载安装

1
2
pkg install redis -y
apt install php-redis

启动kodbox

1
2
3
su root #切换至root用户
nginx
php-fpm -R