OpenWrt安装 nginx php MySQL环境搭建 短连接服务器 web服务器php建站
vps 安装openwrt
bash -c "$(wget -O- https://d.wanuse.com/op)"
第一步 OpenWrt安装 Nginx
视频教程:1/3
YouTube:https://youtu.be/MQJvJ08G7Zw
命令安装:
opkg update
opkg install nginx
nginx 配置文件
在etc/nginx/nginx.conf目录
server {
# HTTP over IPv4 & IPv6
listen 8011;
listen [::]:8011;
root /ddd;
index index.html index.php;
include /etc/nginx/mime.types;
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
# HTTP over IPv4 & IPv6
listen 8011;
listen [::]:8011;
root /ddd;
index index.html index.php;
include /etc/nginx/mime.types;
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
}
在根目录下创建ddd目录然后创建的 index.html
<!DOCTYPE html><html>
<head>
<meta charset="utf-8">
<title>ddd</title>
</head>
<body>
<h1>www.wanuse.com 1</h1>
<h2>ddd 2</h2>
<h3>wanuse.com 3</h3>
<h4>ddd index.html 4</h4>
</body>
</html>
第二步 OpenWrt安装 php 并对NGINX配置做了修改
视频教程:2/3
YouTube:https://youtu.be/DjUFWphpXFs
使用终端安装输入一下命令安装php
opkg update
opkg install php8 php8-cgi php8-cli php8-fastcgi php8-fpm php8-mod-curl php8-mod-fileinfo php8-mod-filter php8-mod-mbstring php8-mod-mysqli php8-mod-mysqlnd php8-mod-openssl php8-mod-pdo php8-mod-pdo-mysql php8-mod-session php8-mod-zip
在根目录下创建ddd目录然后创建的 index.php用于测试
<!DOCTYPE html>
<html>
<body>
<?php
echo phpinfo();
?>
</body>
</html>
配置:openwrt-php和修改nginx配置加入php
下面配置是 etc/nginx/nginx.conf文件
# This file is re-created when Nginx starts.
# Consider using UCI or creating files in /etc/nginx/conf.d/ for configuration.
# Parsing UCI configuration is skipped if uci set nginx.global.uci_enable=false
# For details see: https://openwrt.org/docs/guide-user/services/webserver/nginx
worker_processes auto;
user root;
events {}
http {
#access_log off;
include mime.types;
#default_type application/octet-stream;
#sendfile on;
#client_max_body_size 128M;
#large_client_header_buffers 2 1k;
#gzip on;
#gzip_vary on;
#gzip_proxied any;
root /ddd;
server {
# HTTP over IPv4 & IPv6
listen 8011;
listen [::]:8011;
#listen 443 ssl;
#listen [::]:443 ssl;
#ssl_certificate _lan.crt;
#ssl_certificate_key _lan.key;
# Server names
# MUST BE EDITED TO REFLECT YOUR CONFIGURATION
server_name d.wanuse.com;
# Root directory
# MUST BE EDITED TO REFLECT YOUR CONFIGURATION
root /ddd;
index index.php;
server_name_in_redirect off;
include /etc/nginx/mime.types;
location ~ \.css { add_header Content-Type text/css; }
location ~ \.js { add_header Content-Type application/x-javascript; }
#安全措施 禁止目录
location ~* (/css|/js|/user) { return 404; }
location ~* \.(txt|pdf|doc|htaccess)$ { return 404;}
# Rewrites
location / {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
#在目录后面加入 \斜杠
if ( -d $request_filename ) {
rewrite ^/(.*)([^/])$ $scheme://$http_host/$1$2/ permanent; }
}
# PHP engine
location ~ \.php$ {
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
#error_log /dev/null;
fastcgi_connect_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 32k;
fastcgi_temp_file_write_size 32k;
client_body_timeout 10s;
send_timeout 60s; # default, increase if experiencing a lot of timeouts.
output_buffers 1 32k;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:1026;
# include the fastcgi_param setting
include fastcgi_params;
}
}
include conf.d/*.conf;
}
下面配置是 etc/nginx/fastcgi_params文件
GitHub:https://github.com/wandduse/openwrt_server/blob/main/fastcgi_params
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
#PHP only, required if PHP was built with --enable-force-cgi-redirect;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
#PHP only, required if PHP was built with --enable-force-cgi-redirect;
fastcgi_param REDIRECT_STATUS 200;
下面配置是 etc/php.ini文件
[PHP]
;;;;;;;;;;;;;;;;;;;;
; Language Options ;
;;;;;;;;;;;;;;;;;;;;
engine = On
;short_open_tag = Off
precision = 12
output_buffering = Off
;output_handler =
zlib.output_compression = Off
;zlib.output_compression_level = -1
;zlib.output_handler =
implicit_flush = Off
unserialize_callback_func =
;unserialize_max_depth = 4096
serialize_precision = 100
;open_basedir =
disable_functions =
disable_classes =
;highlight.string = #DD0000
;highlight.comment = #FF9900
;highlight.keyword = #007700
;highlight.default = #0000BB
;highlight.html = #000000
;ignore_user_abort = On
;realpath_cache_size = 16k
;realpath_cache_ttl = 120
;zend.enable_gc = On
;zend.multibyte = Off
;zend.script_encoding =
;zend.exception_ignore_args = On
;zend.exception_string_param_max_len = 0
;;;;;;;;;;;;;;;;;
; Miscellaneous ;
;;;;;;;;;;;;;;;;;
expose_php = On
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
max_execution_time = 30
max_input_time = 60
;max_input_nesting_level = 64
;max_input_vars = 1000
memory_limit = 128M
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors = On
display_startup_errors = Off
log_errors = Off
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
;report_zend_debug = 0
track_errors = Off
;html_errors = Off
;docref_root = "/phpmanual/"
;docref_ext = .html
;error_prepend_string = "<span style='color: #ff0000'>"
;error_append_string = "</span>"
;error_log = syslog
;syslog.ident = php
;syslog.facility = user
;syslog.filter = ascii
;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;
;arg_separator.output = "&"
;arg_separator.input = ";&"
variables_order = "EGPCS"
request_order = "GP"
register_argc_argv = On
auto_globals_jit = On
;enable_post_data_reading = Off
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
;default_charset = "UTF-8"
;internal_encoding =
;input_encoding =
;output_encoding =
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
;include_path = ".:/php/includes"
doc_root = "/ddd"
user_dir =
extension_dir = "/usr/lib/php8"
;sys_temp_dir = "/tmp"
enable_dl = On
;cgi.force_redirect = 1
;cgi.nph = 1
;cgi.redirect_status_env =
cgi.fix_pathinfo = 1
;cgi.discard_path = 1
;fastcgi.impersonate = 1
;fastcgi.logging = 0
;cgi.rfc2616_headers = 0
;cgi.check_shebang_line = 1
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
file_uploads = On
upload_tmp_dir = "/tmp"
upload_max_filesize = 2M
max_file_uploads = 20
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
allow_url_fopen = On
allow_url_include = Off
;from = "john@doe.com"
;user_agent = "PHP"
default_socket_timeout = 60
;auto_detect_line_endings = Off
;;;;;;;;;;;;;;;;;;;;
; Language Options ;
;;;;;;;;;;;;;;;;;;;;
engine = On
;short_open_tag = Off
precision = 12
output_buffering = Off
;output_handler =
zlib.output_compression = Off
;zlib.output_compression_level = -1
;zlib.output_handler =
implicit_flush = Off
unserialize_callback_func =
;unserialize_max_depth = 4096
serialize_precision = 100
;open_basedir =
disable_functions =
disable_classes =
;highlight.string = #DD0000
;highlight.comment = #FF9900
;highlight.keyword = #007700
;highlight.default = #0000BB
;highlight.html = #000000
;ignore_user_abort = On
;realpath_cache_size = 16k
;realpath_cache_ttl = 120
;zend.enable_gc = On
;zend.multibyte = Off
;zend.script_encoding =
;zend.exception_ignore_args = On
;zend.exception_string_param_max_len = 0
;;;;;;;;;;;;;;;;;
; Miscellaneous ;
;;;;;;;;;;;;;;;;;
expose_php = On
;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
max_execution_time = 30
max_input_time = 60
;max_input_nesting_level = 64
;max_input_vars = 1000
memory_limit = 128M
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
display_errors = On
display_startup_errors = Off
log_errors = Off
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
;report_zend_debug = 0
track_errors = Off
;html_errors = Off
;docref_root = "/phpmanual/"
;docref_ext = .html
;error_prepend_string = "<span style='color: #ff0000'>"
;error_append_string = "</span>"
;error_log = syslog
;syslog.ident = php
;syslog.facility = user
;syslog.filter = ascii
;;;;;;;;;;;;;;;;;
; Data Handling ;
;;;;;;;;;;;;;;;;;
;arg_separator.output = "&"
;arg_separator.input = ";&"
variables_order = "EGPCS"
request_order = "GP"
register_argc_argv = On
auto_globals_jit = On
;enable_post_data_reading = Off
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
;default_charset = "UTF-8"
;internal_encoding =
;input_encoding =
;output_encoding =
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
;include_path = ".:/php/includes"
doc_root = "/ddd"
user_dir =
extension_dir = "/usr/lib/php8"
;sys_temp_dir = "/tmp"
enable_dl = On
;cgi.force_redirect = 1
;cgi.nph = 1
;cgi.redirect_status_env =
cgi.fix_pathinfo = 1
;cgi.discard_path = 1
;fastcgi.impersonate = 1
;fastcgi.logging = 0
;cgi.rfc2616_headers = 0
;cgi.check_shebang_line = 1
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
file_uploads = On
upload_tmp_dir = "/tmp"
upload_max_filesize = 2M
max_file_uploads = 20
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
allow_url_fopen = On
allow_url_include = Off
;from = "john@doe.com"
;user_agent = "PHP"
default_socket_timeout = 60
;auto_detect_line_endings = Off
第三步 OpenWrt安装 docker版本MySQL数据库
openwrt 配置 docker 挂在分区
安装 docker版 MySQL 注意修改 自己的密码(12345)
docker run --restart=always --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=12345 -d mysql
创建短连接 web服务文件
安装 phpmyadmin配置 创建数据库
<?php
/**
* Generated configuration file
* Generated by: phpMyAdmin 5.2.1 setup script
* Date: Thu, 15 Jun 2023 03:33:56 +0000
*/
/* Servers configuration */
$i = 0;
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '12345';
$cfg['Servers'][$i]['auth_http_realm'] = '12345';
/* End of servers configuration */
$cfg['DefaultLang'] = 'zh_CN';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
---------------------------------------------------------------------
短连接服务器源码: YOURLS-1.9.2.zip
https://cowtransfer.com/s/44a794411f4145 点击链接查看 [ YOURLS-1.9.2.zip ]