项目构建 – 永夜 https://www.shuijingwanwq.com 没有不值得去解决的问题,也没有不值得去学习的技术! Mon, 25 May 2026 09:13:54 +0000 zh-Hans hourly 1 https://wordpress.org/?v=7.0 解决 WordPress + Polylang 批量处理标签时遇到的 Redis OOM 错误 https://www.shuijingwanwq.com/2026/05/24/13504/ https://www.shuijingwanwq.com/2026/05/24/13504/#respond Sun, 24 May 2026 12:09:01 +0000 https://www.shuijingwanwq.com/?p=13504 浏览量: 25

一、问题背景

我运营着一个基于 WordPress 的双语网站(中文/英文),使用了 Polylang 插件来管理多语言内容。为了批量给已有的中文分类/标签创建对应的英文翻译,我写了一个 PHP 脚本 polylang-batch-zh-to-en-tags.php

然而,在执行脚本时,终端突然报出致命错误:

[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# php polylang-batch-zh-to-en-tags.php
PHP Fatal error:  Uncaught RedisException: OOM command not allowed when used memory > 'maxmemory'. in /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/w3-total-cache/Cache_Redis.php:150
Stack trace:
#0 /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/w3-total-cache/Cache_Redis.php(150): Redis->setex()
#1 /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php(253): W3TC\Cache_Redis->set()
#2 /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/w3-total-cache/DbCache_WpdbNew.php(216): W3TC\DbCache_WpdbInjection_QueryCaching->query()
#3 /data/wwwroot/www.shuijingwanwq.com/wp-includes/class-wpdb.php(3150): W3TC\DbCache_WpdbNew->query()
#4 /data/wwwroot/www.shuijingwanwq.com/wp-includes/taxonomy.php(4123): wpdb->get_results()
#5 /data/wwwroot/www.shuijingwanwq.com/wp-includes/class-wp-term-query.php(825): _prime_term_caches()
#6 /data/wwwroot/www.shuijingwanwq.com/wp-includes/class-wp-term-query.php(308): WP_Term_Query->get_terms()
#7 /data/wwwroot/www.shuijingwanwq.com/wp-includes/taxonomy.php(1357): WP_Term_Query->query()
#8 /data/wwwroot/www.shuijingwanwq.com/wp-includes/taxonomy.php(2338): get_terms()
#9 /data/wwwroot/www.shuijingwanwq.com/wp-includes/taxonomy.php(3856): wp_get_object_terms()
#10 /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/polylang/src/translated-term.php(250): update_object_term_cache()
#11 /data/wwwroot/www.shuijingwanwq.com/wp-includes/class-wp-hook.php(343): PLL_Translated_Term->_prime_terms_cache()
#12 /data/wwwroot/www.shuijingwanwq.com/wp-includes/plugin.php(205): WP_Hook->apply_filters()
#13 /data/wwwroot/www.shuijingwanwq.com/wp-includes/taxonomy.php(1379): apply_filters()
#14 /data/wwwroot/www.shuijingwanwq.com/polylang-batch-zh-to-en-tags.php(28): get_terms()
#15 {main}
  thrown in /data/wwwroot/www.shuijingwanwq.com/wp-content/plugins/w3-total-cache/Cache_Redis.php on line 150

脚本直接崩溃,无法继续处理。如图1

脚本直接崩溃,无法继续处理。如图1

二、错误分析

从错误信息可以看出:

  • 抛出位置:W3 Total Cache 插件的 Redis 缓存驱动。
  • 直接原因:Redis 返回了 OOM command not allowed,表示 Redis 的内存使用已超过 maxmemory 限制,并且配置策略为 禁止任何写入noeviction)。
  • 间接原因:脚本执行过程中会触发 WordPress 的术语缓存更新(_prime_term_caches),进而调用了 W3 Total Cache 的对象缓存,向 Redis 写入数据。

关键线索:Redis 的内存淘汰策略为 noeviction。这意味着一旦内存占用达到上限,所有写操作都会被拒绝,直到内存被手动清理。

三、排查步骤

1. 检查 Redis 当前内存状态

检查 Redis 当前内存状态
redis-cli INFO memory | grep -E "maxmemory|used_memory|maxmemory_policy"

输出如下:

used_memory:33107888
used_memory_human:31.57M
maxmemory:120000000
maxmemory_human:114.44M
maxmemory_policy:noeviction

可以看到:

  • 最大内存仅为 114 MB(对于现代 WordPress + 多插件环境来说明显偏小)。
  • 淘汰策略为 noeviction(罪魁祸首)。

2. 查看服务器整体内存情况

查看服务器整体内存情况
free -h

结果:

              total        used        free      shared  buff/cache   available
Mem:          1.9Gi       321Mi       184Mi        90Mi       1.4Gi       1.3Gi
Swap:         2.0Gi       130Mi       1.9Gi

服务器总内存约 2GB,可用物理内存充足(1.3GB),完全可以分配给 Redis 更多空间。

四、解决方案

1. 临时修复(立即生效,无需重启)

redis-cli CONFIG SET maxmemory 1024mb
redis-cli CONFIG SET maxmemory-policy allkeys-lru
  • maxmemory 1024mb:将 Redis 最大内存提升至 1GB。
  • maxmemory-policy allkeys-lru:当内存用满时,自动淘汰 最近最少使用 的键。

2. 永久生效(修改配置文件)

由于我的 Redis 是通过 OneinStack 编译安装的,配置文件位于 /usr/local/redis/etc/redis.conf

vim /usr/local/redis/etc/redis.conf

找到或添加以下两行:

找到或添加以下两行:
maxmemory 1024mb
maxmemory-policy allkeys-lru

保存后重启 Redis(OneinStack 的服务名是 redis-server):

service redis-server restart

3. 验证修改

redis-cli CONFIG GET maxmemory
# 输出:1073741824 (即 1GB)

redis-cli CONFIG GET maxmemory-policy
# 输出:allkeys-lru

五、最终结果

再次执行批量处理脚本:

php polylang-batch-zh-to-en-tags.php

输出:

🚀 开始批量处理所有zh标签,自动添加en翻译(分页模式)...
📊 正在处理第 1 - 1000 个标签...
📊 正在处理第 1001 - 2000 个标签...
...
🎉 全部处理完成!
📊 统计:
   已处理新标签: 0
   已跳过已有翻译: 8289
✅ 所有标签都已经处理完毕,和手动添加的完全一样!

不再有任何 Redis 错误,脚本顺利运行完成!

六、经验总结

  1. Redis 默认的 noeviction 策略并不适合缓存场景,尤其是在有限内存环境下。推荐使用 allkeys-lruvolatile-lru
  2. WordPress + W3 Total Cache + Redis 对象缓存会大量消耗内存,务必根据服务器实际情况设置合理的 maxmemory
  3. OneinStack 安装的 Redis 服务名是 redis-server,而不是常见的 redisredis.service,管理时需要注意。
  4. 批量操作触发大量缓存写入时,可以临时禁用对象缓存(define('DONOTCACHEOBJECT', true);),但更好的做法是调整 Redis 策略让系统自动适应。

七、延伸建议

  • 若网站流量增长,可将 maxmemory 进一步提升至 1.5GB ~ 2GB(视总内存而定)。
  • 定期监控 Redis 内存使用:redis-cli --stat 或集成 redis_exporter + Prometheus。
  • W3 Total Cache 的对象缓存可适当缩短“垃圾回收间隔”(如 3600 秒),避免过期键堆积。

希望这篇博客能帮助到遇到类似问题的朋友。如果你们也有关于 Redis + WordPress 的踩坑经历,欢迎在评论区交流讨论!

]]>
https://www.shuijingwanwq.com/2026/05/24/13504/feed/ 0
我的个人博客,今天突然响应 504 的排查解决流程 https://www.shuijingwanwq.com/2026/02/25/9317/ https://www.shuijingwanwq.com/2026/02/25/9317/#comments Wed, 25 Feb 2026 09:47:46 +0000 https://www.shuijingwanwq.com/?p=9317 浏览量: 172

1、我的个人博客,今天突然响应 504 的排查解决流程。如图1

我的个人博客,今天突然响应 504

2、504 Gateway Timeout 说明 Nginx(或其他反向代理)等待后端(PHP-FPM)响应超时了。按以下顺序排查:

3、执行 top 命令,结果显示如下:问题很明确了,服务器严重过载。关键数据:负载 19.77(正常应该在 1-2 以下)、21 个进程在跑(太多了)、CPU 占用 87.4%、内存 1968MB 只剩 96MB 可用。这台是 2G 内存的小机器,已经被压垮了。如图2

执行 top 命令,结果显示如下:问题很明确了,服务器严重过载。关键数据:负载 19.77(正常应该在 1-2 以下)、21 个进程在跑(太多了)、CPU 占用 87.4%、内存 1968MB 只剩 96MB 可用。这台是 2G 内存的小机器,已经被压垮了。


top - 15:21:01 up 993 days,  3:25,  1 user,  load average: 18.68, 19.55, 19.55
Tasks: 139 total,  20 running, 119 sleeping,   0 stopped,   0 zombie
%Cpu(s): 88.0 us,  9.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  1.3 hi,  1.7 si,  0.0 st
MiB Mem :   1968.6 total,     76.8 free,   1481.2 used,    410.6 buff/cache
MiB Swap:   2048.0 total,   1816.6 free,    231.4 used.    262.7 avail Mem


3、退出 top,执行:ps aux –sort=-%cpu | head -20,看是什么进程在吃资源。原因找到了。15+ 个 PHP-FPM 子进程同时运行,每个占 110MB 内存,光 PHP-FPM 就吃掉了将近 1.6GB,服务器总共才 2GB 内存,直接撑爆了。



[root@iZ23wv7v5ggZ ~]# ps aux --sort=-%cpu | head -20
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
www      2097069  5.6  5.4 583184 109280 ?       S    14:41   2:29 php-fpm: pool www
www      2097086  5.6  5.3 583376 108720 ?       R    14:43   2:23 php-fpm: pool www
www      2097087  5.6  5.5 585100 111712 ?       R    14:43   2:22 php-fpm: pool www
www      2097088  5.6  5.4 583136 109108 ?       S    14:43   2:22 php-fpm: pool www
www      2097093  5.6  5.4 583132 109292 ?       R    14:44   2:18 php-fpm: pool www
www      2097094  5.6  5.4 583132 109344 ?       R    14:44   2:18 php-fpm: pool www
www      2097109  5.6  5.4 583372 109752 ?       R    14:45   2:16 php-fpm: pool www
www      2097125  5.6  5.4 583116 109200 ?       R    14:47   2:09 php-fpm: pool www
www      2097162  5.6  5.4 583324 109732 ?       R    14:49   2:01 php-fpm: pool www
www      2097187  5.6  5.4 583244 109848 ?       R    14:53   1:48 php-fpm: pool www
www      2097281  5.6  5.4 583124 109308 ?       R    15:03   1:17 php-fpm: pool www
www      2097299  5.6  5.4 583052 109328 ?       R    15:05   1:09 php-fpm: pool www
www      2097341  5.6  5.4 583116 109408 ?       S    15:10   0:52 php-fpm: pool www
www      2097671  5.6  5.5 583052 112304 ?       R    15:18   0:24 php-fpm: pool www
www      2097746  5.5  5.5 582836 111876 ?       S    15:24   0:02 php-fpm: pool www
www      2097747  5.4  5.5 582852 111988 ?       R    15:25   0:01 php-fpm: pool www
root     1007745  3.2  1.0 154220 20344 ?        Ssl   2025 7458:44 /usr/local/aegis/aegis_client/aegis_12_81/AliYunDunMonitor
root     2097357  0.5  7.7 516416 156836 ?       RNs  15:11   0:04 /usr/libexec/platform-python /usr/bin/dnf makecache --timer
root     1007719  0.3  0.3  99308  6048 ?        Ssl   2025 756:25 /usr/local/aegis/aegis_client/aegis_12_81/AliYunDun
[root@iZ23wv7v5ggZ ~]#


4、先紧急恢复,再查根因。先看看一共有多少个 PHP-FPM 进程。总计 17 个。



[root@iZ23wv7v5ggZ ~]# ps aux | grep php-fpm | grep -v grep | wc -l
17


5、编辑 PHP-FPM 配置,服务器只有 2GB 内存,修改为跑 5 个子进程,编辑文件 /usr/local/php/etc/php-fpm.conf。如图3

编辑 PHP-FPM 配置,服务器只有 2GB 内存,修改为跑 5 个子进程,编辑文件 /usr/local/php/etc/php-fpm.conf

修改前:



pm = dynamic
pm.max_children = 16
pm.start_servers = 10
pm.min_spare_servers = 8
pm.max_spare_servers = 16
pm.max_requests = 2048


修改后:



pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500


6、保存后重启:执行命令:如图4

保存后重启:执行命令:


[root@iZ23wv7v5ggZ ~]# service php-fpm restart
[root@iZ23wv7v5ggZ ~]# sudo systemctl restart php-fpm


7、执行 top 命令,结果显示如下。内存恢复了,从 96MB 空闲涨到 1214MB,PHP-FPM 调整生效了。负载也在下降(19.77 → 7.97)。但 CPU 还是 85.4%,还有 8 个进程在跑,不正常。



top - 15:55:11 up 993 days,  3:59,  1 user,  load average: 7.97, 11.01, 15.32
Tasks: 124 total,   8 running, 116 sleeping,   0 stopped,   0 zombie
%Cpu(s): 85.4 us,  9.9 sy,  0.0 ni,  1.0 id,  0.0 wa,  1.0 hi,  2.6 si,  0.0 st
MiB Mem :   1968.6 total,   1214.1 free,    302.7 used,    451.8 buff/cache
MiB Swap:   2048.0 total,   1878.8 free,    169.2 used.   1469.1 avail Mem


8、 看看是什么在吃 CPU:执行命令:ps aux –sort=-%cpu | head -10 ,5 个 PHP-FPM 进程全部跑满了,说明有持续的大量请求在打我的服务器。



[root@iZ23wv7v5ggZ ~]# ps aux --sort=-%cpu | head -10
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
www      2098124 17.0  3.1 452724 63280 ?        R    15:57   0:06 php-fpm: pool www
www      2098123 16.8  2.9 452404 59716 ?        R    15:57   0:06 php-fpm: pool www
www      2098122 16.7  3.0 452868 61800 ?        R    15:57   0:06 php-fpm: pool www
www      2098125 16.7  2.9 452404 59712 ?        R    15:57   0:06 php-fpm: pool www
www      2098126 16.6  3.0 452732 60772 ?        R    15:57   0:06 php-fpm: pool www
root     1007745  3.2  1.0 154220 20160 ?        Ssl   2025 7460:16 /usr/local/aegis/aegis_client/aegis_12_81/AliYunDunMonitor
root     1007719  0.3  0.2  99308  5772 ?        Ssl   2025 756:31 /usr/local/aegis/aegis_client/aegis_12_81/AliYunDun
www      2040873  0.2  1.4 186640 29872 ?        R    Feb17  24:56 nginx: worker process
root         754  0.1  0.2 555732  4480 ?        Ssl   2023 2189:58 /usr/libexec/platform-python -Es /usr/sbin/tuned -l -P
[root@iZ23wv7v5ggZ ~]#


9、查我的博客的虚拟主机的访问日志,博客的单个 IP 访问量不大,但 IP 段很集中(222.167.251.x、143.20.219.x、66.92.14.x),看起来像是分布式爬虫。但每个 IP 才 2 次请求,不太可能是它们把服务器打爆。



[root@iZ23wv7v5ggZ ~]# tail -200 /data/wwwlogs/www.shuijingwanwq.com_nginx.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
2 66.92.14.197
2 222.167.251.94
2 222.167.251.83
2 222.167.251.69
2 222.167.251.248
2 222.167.251.161
2 222.167.251.155
2 222.167.251.100
2 143.20.219.38
2 143.20.219.227
2 143.20.219.208
2 143.20.219.199
2 136.0.94.36
2 13.53.45.144
1 66.92.14.92
1 66.92.14.90
1 66.92.14.85
1 66.92.14.8
1 66.92.14.77
1 66.92.14.75


10、可能是其他虚拟主机的流量导致的。 查一下:看哪个日志文件最近写入最频繁。主要流量集中在我的博客(21MB 日志)和 access_nginx.log(7MB)。



<h1>看哪个日志文件最近写入最频繁</h1>
ls -lt /data/wwwlogs/*.log | head -10

-rw-r--r-- 1 www root 21765969 Feb 25 16:01 /data/wwwlogs/www.shuijingwanwq.com_nginx.log
-rw-r--r-- 1 www root  7330312 Feb 25 16:01 /data/wwwlogs/access_nginx.log
-rw-r--r-- 1 www root     2189 Feb 25 15:47 /data/wwwlogs/error_nginx.log
-rw-r--r-- 1 www root    48532 Feb 25 15:40 /data/wwwlogs/learn-php-app-0605-prod.wangqiang.store_nginx.log
-rw-r--r-- 1 www root   213953 Feb 25 11:03 /data/wwwlogs/tym-jammerall.shuijingwanwq.com_nginx.log
-rw-r--r-- 1 www root        0 Jun 16  2023 /data/wwwlogs/learn-php-app-0605-prod.shuijingwanwq.com_nginx.log
-rw-r--r-- 1 www root        0 Jun  8  2023 /data/wwwlogs/fanxiapp-wangqiang-larabbs.shuijingwanwq.com_nginx.log



11、看 access_nginx.log 的流量来源,找到了!183.129.189.60 这个 IP 在疯狂刷我的服务器,200 条日志里它占了 177 条。先封掉这个 IP:



[root@iZ23wv7v5ggZ ~]# tail -200 /data/wwwlogs/access_nginx.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
177 183.129.189.60
10 121.196.223.20
2 77.83.39.167
2 45.153.34.187
2 38.46.221.123
2 204.76.203.69
1 47.99.50.249
1 43.156.202.34
1 43.130.31.17
1 43.130.16.212
1 205.210.31.11


12、在阿里云控制台的安全组里加一条规则:登录阿里云控制台 → ECS → 安全组 → 找到我实例对应的安全组 → 添加规则 → 方向选”入方向”、策略选”拒绝”、源地址填 183.129.189.60、端口范围填 -1/-1(全部端口)。如图5

在阿里云控制台的安全组里加一条规则:登录阿里云控制台 → ECS → 安全组 → 找到我实例对应的安全组 → 添加规则 → 方向选"入方向"、策略选"拒绝"、源地址填 183.129.189.60、端口范围填 -1/-1(全部端口)

13、看现在还有谁在大量请求,183.129.189.60 还在刷!安全组 规则可能没生效。立即用 iptables 封禁。如图6

看现在还有谁在大量请求,183.129.189.60 还在刷!安全组 规则可能没生效。立即用 iptables 封禁


[root@iZ23wv7v5ggZ ~]# tail -500 /data/wwwlogs/access_nginx.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10
473 183.129.189.60
10 121.196.223.20
3 81.29.142.6
2 77.83.39.167
2 45.153.34.187
2 38.46.221.123
2 204.76.203.69
1 47.99.50.249
1 43.156.202.34
1 43.130.31.17
[root@iZ23wv7v5ggZ ~]#


14、执行以下命令,返回 0,说明封禁成功了。



[root@iZ23wv7v5ggZ ~]# sleep 30 &amp;&amp; tail -100 /data/wwwlogs/access_nginx.log | grep "183.129.189.60" | wc -l
73


15、由于 iptables 不管用,在 Nginx 层面封。直接在 access_nginx.log 对应的那个虚拟主机配置里封。先找到是哪个虚拟主机。然后直接编辑 nginx.conf,保存后,重启 Nginx。如图7

由于 iptables 不管用,在 Nginx 层面封。直接在 access_nginx.log 对应的那个虚拟主机配置里封。先找到是哪个虚拟主机。然后直接编辑 nginx.conf,保存后,重启 Nginx。


[root@iZ23wv7v5ggZ ~]# grep -rl "access_nginx.log" /usr/local/nginx/conf/
/usr/local/nginx/conf/nginx.conf
[root@iZ23wv7v5ggZ ~]# vi /usr/local/nginx/conf/nginx.conf
[root@iZ23wv7v5ggZ ~]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
[root@iZ23wv7v5ggZ ~]#


16、实时监控,等30秒看有没有新的。如果没有任何输出,说明封禁已经生效了。确认已经生效。但是,负载仍然很高,博客仍然响应 504



[root@iZ23wv7v5ggZ ~]# timeout 30 tail -f /data/wwwlogs/access_nginx.log | grep "183.129.189.60"



17、负载稳在 7.6,没有继续下降。还有其他东西在吃资源。看看现在的情况:



<h1>当前 PHP-FPM 进程状态</h1>
[root@iZ23wv7v5ggZ ~]# ps aux | grep "php-fpm" | grep -v grep | wc -l
6
<h1>实时看有没有那个 IP 的新请求</h1>
[root@iZ23wv7v5ggZ ~]# tail -20 /data/wwwlogs/access_nginx.log | awk '{print $4, $1}'
[25/Feb/2026:15:26:57 121.196.223.20
[25/Feb/2026:15:26:57 121.196.223.20
[25/Feb/2026:15:26:57 121.196.223.20
[25/Feb/2026:15:26:57 121.196.223.20
[25/Feb/2026:15:27:07 121.196.223.20
[25/Feb/2026:15:27:07 121.196.223.20
[25/Feb/2026:15:27:17 121.196.223.20
[25/Feb/2026:15:27:17 121.196.223.20
[25/Feb/2026:15:28:33 47.99.50.249
[25/Feb/2026:15:34:01 45.153.34.187
[25/Feb/2026:15:49:35 43.156.202.34
[25/Feb/2026:15:56:04 38.46.221.123
[25/Feb/2026:16:01:12 38.46.221.123
[25/Feb/2026:16:12:08 81.29.142.6
[25/Feb/2026:16:12:12 81.29.142.6
[25/Feb/2026:16:12:16 81.29.142.6
[25/Feb/2026:16:20:52 185.242.226.113
[25/Feb/2026:16:45:12 34.158.168.101
[25/Feb/2026:16:45:13 34.158.168.101
[25/Feb/2026:16:45:14 34.158.168.101
<h1>博客最近的请求</h1>
[root@iZ23wv7v5ggZ ~]# tail -20 /data/wwwlogs/www.shuijingwanwq.com_nginx.log | awk '{print $4, $1, $7}' | tail -10
[25/Feb/2026:16:56:34 143.20.219.229 /robots.txt
[25/Feb/2026:16:56:34 143.20.219.183 /tag/develop
[25/Feb/2026:16:56:34 222.167.251.252 /robots.txt
[25/Feb/2026:16:56:34 66.92.14.190 /robots.txt
[25/Feb/2026:16:56:34 222.167.251.15 /robots.txt
[25/Feb/2026:16:56:34 66.92.14.195 /robots.txt
[25/Feb/2026:16:56:34 136.0.94.155 /robots.txt
[25/Feb/2026:16:56:34 66.92.14.151 /robots.txt
[25/Feb/2026:16:56:35 143.20.219.77 /robots.txt
[25/Feb/2026:16:56:35 136.0.94.158 /robots.txt
<h1>我的服务器是几核的</h1>
[root@iZ23wv7v5ggZ ~]# nproc
1
[root@iZ23wv7v5ggZ ~]#


18、找到根因了。单核 CPU + 大量分布式爬虫。我的博客同一秒内被十几个不同 IP 同时请求,这些 IP 段(143.20.219.x、222.167.251.x、66.92.14.x、136.0.94.x)是分布式爬虫。单核机器根本扛不住。在 Nginx 里批量封这些爬虫 IP 段:



deny 183.129.189.60;
deny 143.20.219.0/24;
deny 222.167.251.0/24;
deny 66.92.14.0/24;
deny 136.0.94.0/24;


19、最后重启 ECS,然后在最近几天观察一下情况了。是否 504 还会出现不。问题已经解决了。总结一下我做的事情:

PHP-FPM max_children 从 16 降到了 5(适配单核 2GB)
Nginx 封了 5 个恶意 IP 段
重启 ECS 清掉了积压的进程

20、这次事故总结如下:

直接原因
IP 183.129.189.60 对服务器发起了恶意安全扫描,暴力探测 /core/static/ 路径下的敏感文件(settings.ini、secret.sql、database.json 等)。同时四个分布式爬虫 IP 段(143.20.219.x、222.167.251.x、66.92.14.x、136.0.94.x)在同一秒内大量并发请求我的博客。这些请求全部经过 PHP-FPM 处理。
根本原因
我的服务器是单核 CPU、2GB 内存,但 PHP-FPM 配置了 max_children = 16、start_servers = 10。每个 PHP-FPM 子进程占用约 110MB 内存,16 个进程 = 1.76GB,几乎吃光了全部 2GB 内存。这个配置在过去 993 天里刚好能撑住正常流量,但一直处于”临界状态”,没有任何余量应对突发流量。
雪崩过程
恶意扫描 + 爬虫流量涌入 → 16 个 PHP-FPM 进程全部被占满 → 内存耗尽,系统开始使用 swap → swap 在磁盘上,IO 变慢 → 每个请求处理时间变长 → 进程无法及时释放 → 新请求排队等待 → Nginx 等待 PHP-FPM 响应超时 → 返回 504 Gateway Timeout。CPU 负载从正常的 0.5 飙到 19.77,形成恶性循环。
解决措施
PHP-FPM max_children 从 16 降到 5,适配单核 2GB 的硬件配置。Nginx 层面封禁了恶意扫描 IP 和四个爬虫 IP 段,被封的请求直接返回 403,不再占用 PHP-FPM 进程。重启 ECS 清掉了积压的卡死进程。
经验教训
PHP-FPM 的进程数必须匹配服务器的硬件资源,单核 2GB 的机器最多跑 5 个进程。993 天未重启、未调整配置,长期处于资源临界状态是最大的隐患。服务器应该有基本的防护措施,比如 Nginx 限流(limit_req_zone)和恶意 IP 自动封禁,而不是裸跑等出事。

]]>
https://www.shuijingwanwq.com/2026/02/25/9317/feed/ 1
在 LNMP 2.1 中 执行 lnmp nginx reload 时警告:Reload nginx… nginx: [warn] the “listen … http2” directive is deprecated, use the “http2” directive instead in /usr/local/nginx/conf/vhost/xxx.yyy.cn.conf:46 https://www.shuijingwanwq.com/2025/05/08/9011/ https://www.shuijingwanwq.com/2025/05/08/9011/#respond Thu, 08 May 2025 02:06:14 +0000 https://www.shuijingwanwq.com/?p=9011 浏览量: 75 1、在 LNMP 2.1 中 执行 lnmp nginx reload 时报错:Reload nginx… nginx: [warn] the “listen … http2” directive is deprecated, use the “http2” directive instead in /usr/local/nginx/conf/vhost/xxx.yyy.cn.conf:46。如图1
在 LNMP 2.1 中 执行 lnmp nginx reload 时报错:Reload nginx... nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/xxx.yyy.cn.conf:46

图1



[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# lnmp nginx reload
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Reload nginx... nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/xxx.yyy.cn.conf:46
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/xxxapi.yyy.cn.conf:46
 done



2、查看 Nginx 配置, listen 443 ssl http2; 修改为 listen 443 ssl; http2 on; 。如图2
查看 Nginx 配置, listen 443 ssl http2; 修改为 listen 443 ssl; http2 on;

图2



#listen 443 ssl http2;

listen 443 ssl;
http2 on;



2、查看 Nginx 配置, listen 443 ssl http2; 修改为 listen 443 ssl; http2 on; 。如图3
查看 Nginx 配置, listen 443 ssl http2; 修改为 listen 443 ssl; http2 on;

图3



#listen 443 ssl http2;

listen 443 ssl;
http2 on;


3、再次执行 lnmp nginx reload ,不再警告。


[root@iZ2zeaj7tnbv8d3gsoy1w5Z vhost]# lnmp nginx reload
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Reload nginx...  done



]]>
https://www.shuijingwanwq.com/2025/05/08/9011/feed/ 0
在 LNMP 2.1 中,删除掉默认的 default 虚拟主机的流程 https://www.shuijingwanwq.com/2025/05/06/9005/ https://www.shuijingwanwq.com/2025/05/06/9005/#respond Tue, 06 May 2025 11:47:33 +0000 https://www.shuijingwanwq.com/?p=9005 浏览量: 102 1、在 LNMP 2.1 中,删除掉默认的 default 虚拟主机的流程。查看目录,/home/wwwroot/default 中仅剩下 .user.ini,其他的文件已经被手动删除。如图1
在 LNMP 2.1 中,删除掉默认的 default 虚拟主机的流程。查看目录,/home/wwwroot/default 中仅剩下 .user.ini,其他的文件已经被手动删除。

图1



[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# cd default/
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# ls -la
total 4
drwxr-xr-x 2 www  www  23 Mar  8 19:17 .
drwxr-xr-x 4 root root 32 Mar  8 16:57 ..
-rw-r--r-- 1 root root 48 Mar  8 16:43 .user.ini
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# pwd
/home/wwwroot/default
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]#



2、参考:LNMP添加、删除虚拟主机及伪静态使用教程 https://lnmp.org/faq/lnmp-vhost-add-howto.html 。却不存在 default 虚拟主机。如图2
参考:LNMP添加、删除虚拟主机及伪静态使用教程 https://lnmp.org/faq/lnmp-vhost-add-howto.html 。却不存在 default 虚拟主机。

图2



[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# lnmp vhost list
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Nginx Virtualhost list:
objectapi.ikhw.cn
object.ikhw.cn



3、虽然存在文件 /usr/local/nginx/conf/nginx.conf ,其中包含 server server_name _; root /home/wwwroot/default;。决定删除掉此 server 相关的配置。如图3
虽然存在文件 /usr/local/nginx/conf/nginx.conf ,其中包含 server server_name _; root  /home/wwwroot/default;。决定删除掉此 server 相关的配置

图3

4、.user.ini文件无法直接修改,如要修或删除需要先执行:chattr -i /home/wwwroot/default/.user.ini。 rm -f /home/wwwroot/default/.user.ini 就可以。如图4
.user.ini文件无法直接修改,如要修或删除需要先执行:chattr -i /home/wwwroot/default/.user.ini。 rm -f /home/wwwroot/default/.user.ini 就可以。

图4



[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# chattr -i /home/wwwroot/default/.user.ini
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# ls -la
total 4
drwxr-xr-x 2 www  www  23 Mar  8 19:17 .
drwxr-xr-x 4 root root 32 Mar  8 16:57 ..
-rw-r--r-- 1 root root 48 Mar  8 16:43 .user.ini
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# rm -f /home/wwwroot/default/.user.ini
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# ls -la
total 0
drwxr-xr-x 2 www  www   6 Mar 18 10:41 .
drwxr-xr-x 4 root root 32 Mar  8 16:57 ..
[root@iZ2zeaj7tnbv8d3gsoy1w5Z default]# cd ..
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# ls -l
total 0
drwxr-xr-x 2 www  www   6 Mar 18 10:41 default
drwxr-xr-x 4 root root 64 Mar 11 14:56 object
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# rm -rf default/
[root@iZ2zeaj7tnbv8d3gsoy1w5Z wwwroot]# ls -la
total 0
drwxr-xr-x  3 root root 17 Mar 18 10:42 .
drwxr-xr-x. 5 root root 47 Mar  8 16:43 ..
drwxr-xr-x  4 root root 64 Mar 11 14:56 object



5、执行 lnmp nginx reload,重新加载 Nginx 配置。]]>
https://www.shuijingwanwq.com/2025/05/06/9005/feed/ 0
在 LNMP 2.1 中,安装并启用 PHP EXIF 扩展的流程 https://www.shuijingwanwq.com/2025/04/17/8973/ https://www.shuijingwanwq.com/2025/04/17/8973/#respond Thu, 17 Apr 2025 01:49:36 +0000 https://www.shuijingwanwq.com/?p=8973 浏览量: 66 1、报错:Call to undefined function common\models\exif_imagetype 错误表明 PHP 无法找到 exif_imagetype 函数。exif_imagetype 是 PHP 的 EXIF 扩展中的一个函数,用于检测图像文件的类型。如果该扩展未安装或未启用,就会导致此错误。 2、在 LNMP 2.1 中,安装并启用 PHP EXIF 扩展的流程。参考: lnmp之安装PHP模块/扩展(不需要重装PHP) 3、查看 phpinfo() 中的 extension_dir,以确认 扩展所在的目录:/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902。如图1
查看 phpinfo() 中的 extension_dir,以确认 扩展所在的目录:/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902

图1

4、进入 LNMP 安装目录:默认情况下,LNMP 安装在 /root/lnmp2.1 目录。进入该目录,行 addons.sh 脚本:使用以下命令安装 exif 扩展: 如图2
进入 LNMP 安装目录:默认情况下,LNMP 安装在 /root/lnmp2.1 目录。进入该目录,行 addons.sh 脚本:使用以下命令安装 exif 扩展

图2



cd /root/lnmp2.1
./addons.sh install exif


5、重启 PHP-FPM:安装完成后,重启 PHP-FPM 以应用更改:



[root@iZ2zeaj7tnbv8d3gsoy1w5Z lnmp2.1]# lnmp php-fpm restart
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@iZ2zeaj7tnbv8d3gsoy1w5Z lnmp2.1]#



6、验证扩展是否启用:查看 phpinfo() 。确认已经安装并启用。如图3
验证扩展是否启用:查看 phpinfo() 。确认已经安装并启用

图3

]]>
https://www.shuijingwanwq.com/2025/04/17/8973/feed/ 0
基于 LNMP 2.1 部署后,接口响应 500 ,原因在于 .user.ini 的配置 open_basedir 有误 https://www.shuijingwanwq.com/2025/04/14/8969/ https://www.shuijingwanwq.com/2025/04/14/8969/#respond Mon, 14 Apr 2025 01:58:39 +0000 https://www.shuijingwanwq.com/?p=8969 浏览量: 96 1、接口响应 500。如图1
接口响应 500

图1

2、查看 Nginx 的 error log。报错:PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s):如图2
查看 Nginx 的 error log。报错:PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s)

图2



2025/03/11 10:46:31 [error] 323148#0: *3 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/object/src/api/web/:/tmp/:/proc/) in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Warning:  require(/home/wwwroot/object/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/object/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/object/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: objectapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "objectapi.ikhw.cn"




3、参考:LNMP添加、删除虚拟主机及伪静态使用教程 防跨目录设置  查看 .user.ini 中的内容


[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# cat .user.ini
open_basedir=/home/wwwroot/object:/tmp/:/proc/



4、编辑 .user.ini。.user.ini文件无法直接修改,如要修或删除需要先执行:chattr -i /home/wwwroot/object/.user.ini


[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# cat .user.ini
open_basedir=/home/wwwroot/object/src:/tmp/:/proc/



5、仍然报错。最终决定删除掉 .user.ini。参考:LNMP下防跨站、跨目录安全设置,仅支持PHP 5.3.3以上版本 直接在 php.ini 中编辑


2025/03/11 10:53:59 [error] 323149#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/object/src/api/web/:/tmp/:/proc/) in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Warning:  require(/home/wwwroot/object/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/object/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/object/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: objectapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "objectapi.ikhw.cn"




2025/03/11 10:53:59 [error] 323149#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  require(): open_basedir restriction in effect. File(/home/wwwroot/object/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/object/src/api/web/:/tmp/:/proc/) in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Warning:  require(/home/wwwroot/object/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/object/src/api/web/index.php on line 6PHP message: PHP Fatal error:  require(): Failed opening required '/home/wwwroot/object/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/object/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: objectapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "objectapi.ikhw.cn"


]]>
https://www.shuijingwanwq.com/2025/04/14/8969/feed/ 0
基于 LNMP一键安装包 在 CentOS Stream 9 部署 LNMP 环境 https://www.shuijingwanwq.com/2025/04/09/8960/ https://www.shuijingwanwq.com/2025/04/09/8960/#respond Wed, 09 Apr 2025 06:34:34 +0000 https://www.shuijingwanwq.com/?p=8960 浏览量: 79 1、查看 /etc/os-release 文件 ,操作系统为 CentOS Stream 9 。


[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# cat /etc/os-release
NAME="CentOS Stream"
VERSION="9"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="9"
PLATFORM_ID="platform:el9"
PRETTY_NAME="CentOS Stream 9"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:centos:centos:9"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://issues.redhat.com/"
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream"


2、参考:https://lnmp.org/install.html 安装 使用putty或类似的SSH工具登陆VPS或服务器;登陆后运行:screen -S lnmp 如果提示screen: command not found 命令不存在可以执行:yum install screen 安装,提示:未找到。如图1
参考:https://lnmp.org/install.html 安装 使用putty或类似的SSH工具登陆VPS或服务器;登陆后运行:screen -S lnmp 如果提示screen: command not found 命令不存在可以执行:yum install screen 安装,提示:未找到

图1



[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# screen -S lnmp
-bash: screen: command not found
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# yum install screen
Last metadata expiration check: 0:47:49 ago on Sat 08 Mar 2025 03:00:17 PM CST.
No match for argument: screen
Error: Unable to find a match: screen
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# dnf install screen
Last metadata expiration check: 0:50:52 ago on Sat 08 Mar 2025 03:00:17 PM CST.
No match for argument: screen
Error: Unable to find a match: screen



3、screen 软件包通常位于 EPEL(Extra Packages for Enterprise Linux) 仓库中。安装 EPEL 仓库。再次安装 screen,安装成功。如图2
screen 软件包通常位于 EPEL(Extra Packages for Enterprise Linux) 仓库中。安装 EPEL 仓库。再次安装 screen,安装成功

图2



[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# yum install epel-release
Last metadata expiration check: 1:01:31 ago on Sat 08 Mar 2025 03:00:17 PM CST.
Dependencies resolved.
=======================================================================================================================================================================================================================================================================================================================
 Package                                                                           Architecture                                                           Version                                                                  Repository                                                                     Size
=======================================================================================================================================================================================================================================================================================================================
Installing:
 epel-release                                                                      noarch                                                                 9-7.el9                                                                  extras-common                                                                  19 k
Installing weak dependencies:
 epel-next-release                                                                 noarch                                                                 9-7.el9                                                                  extras-common                                                                 8.1 k

Transaction Summary
=======================================================================================================================================================================================================================================================================================================================
Install  2 Packages

Total download size: 27 k
Installed size: 29 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): epel-next-release-9-7.el9.noarch.rpm                                                                                                                                                                                                                                             71 kB/s | 8.1 kB     00:00
(2/2): epel-release-9-7.el9.noarch.rpm                                                                                                                                                                                                                                                 131 kB/s |  19 kB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                                                                  183 kB/s |  27 kB     00:00
CentOS Stream 9 - Extras packages                                                                                                                                                                                                                                                      2.0 MB/s | 2.1 kB     00:00
Importing GPG key 0x1D997668:
 Userid     : "CentOS Extras SIG (https://wiki.centos.org/SpecialInterestGroup) <security@centos.org>"
 Fingerprint: 363F C097 2F64 B699 AED3 968E 1FF6 A217 1D99 7668
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                                                                                               1/1
  Installing       : epel-release-9-7.el9.noarch                                                                                                                                                                                                                                                                   1/2
  Running scriptlet: epel-release-9-7.el9.noarch                                                                                                                                                                                                                                                                   1/2
Many EPEL packages require the CodeReady Builder (CRB) repository.
It is recommended that you run /usr/bin/crb enable to enable the CRB repository.

  Installing       : epel-next-release-9-7.el9.noarch                                                                                                                                                                                                                                                              2/2
  Running scriptlet: epel-next-release-9-7.el9.noarch                                                                                                                                                                                                                                                              2/2
  Verifying        : epel-next-release-9-7.el9.noarch                                                                                                                                                                                                                                                              1/2
  Verifying        : epel-release-9-7.el9.noarch                                                                                                                                                                                                                                                                   2/2

Installed:
  epel-next-release-9-7.el9.noarch                                                                                                                             epel-release-9-7.el9.noarch

Complete!
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# yum install screen
Extra Packages for Enterprise Linux 9 - x86_64                                                                                                                                                                                                                                          14 MB/s |  23 MB     00:01
Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64                                                                                                                                                                                                                   1.4 kB/s | 2.5 kB     00:01
Extra Packages for Enterprise Linux 9 - Next - x86_64                                                                                                                                                                                                                                  232 kB/s | 235 kB     00:01
Dependencies resolved.
=======================================================================================================================================================================================================================================================================================================================
 Package                                                                    Architecture                                                               Version                                                                          Repository                                                                Size
=======================================================================================================================================================================================================================================================================================================================
Installing:
 screen                                                                     x86_64                                                                     4.8.0-6.el9                                                                      epel                                                                     649 k

Transaction Summary
=======================================================================================================================================================================================================================================================================================================================
Install  1 Package

Total download size: 649 k
Installed size: 957 k
Is this ok [y/N]: y
Downloading Packages:
screen-4.8.0-6.el9.x86_64.rpm                                                                                                                                                                                                                                                          5.2 MB/s | 649 kB     00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                                                                  816 kB/s | 649 kB     00:00
Extra Packages for Enterprise Linux 9 - x86_64                                                                                                                                                                                                                                         1.6 MB/s | 1.6 kB     00:00
Importing GPG key 0x3228467C:
 Userid     : "Fedora (epel9) <epel@fedoraproject.org>"
 Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                                                                                               1/1
  Running scriptlet: screen-4.8.0-6.el9.x86_64                                                                                                                                                                                                                                                                     1/1
  Installing       : screen-4.8.0-6.el9.x86_64                                                                                                                                                                                                                                                                     1/1
  Running scriptlet: screen-4.8.0-6.el9.x86_64                                                                                                                                                                                                                                                                     1/1
  Verifying        : screen-4.8.0-6.el9.x86_64                                                                                                                                                                                                                                                                     1/1

Installed:
  screen-4.8.0-6.el9.x86_64

Complete!
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]#



4、安装LNMP稳定版


wget https://soft.lnmp.com/lnmp/lnmp2.1.tar.gz -O lnmp2.1.tar.gz && tar zxf lnmp2.1.tar.gz && cd lnmp2.1 && ./install.sh lnmp


5、LNMP添加、删除虚拟主机 参考:https://lnmp.org/faq/lnmp-vhost-add-howto.html


[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# lnmp vhost add
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): object.***.cn
 Your domain: object.***.cn
Enter more domain name(example: lnmp.org sub.lnmp.org):
 domain list: object.***.cn
Please enter the directory for the domain: object.***.cn
Default directory: /home/wwwroot/object.***.cn: /home/wwwroot/object
Virtual Host Directory: /home/wwwroot/object
Allow Rewrite rule? (y/n) y
Please enter the rewrite of programme,
wordpress,discuzx,typecho,thinkphp,laravel,codeigniter,yii2,zblog rewrite was exist.
(Default rewrite: other): yii2
You choose rewrite: yii2
Enable PHP Pathinfo? (y/n) y
Enable pathinfo.
Allow access log? (y/n) y
Enter access log filename(Default:object.***.cn.log): y
You access log filename: y.log
Enable IPv6? (y/n) n
Disabled IPv6 Support in current Virtualhost.
Add SSL Certificate (y/n) y
1: Use your own SSL Certificate and Key
2: Use Let's Encrypt to create SSL Certificate and Key
3: Use BuyPass to create SSL Certificate and Key
4: Use ZeroSSL to create SSL Certificate and Key
Enter 1, 2, 3 or 4: 2
Using 301 to Redirect HTTP to HTTPS? (y/n) y
Redirect http://object.***.cn to https://object.***.cn

Press any key to start create virtul host...

Create Virtul Host directory......
set permissions of Virtual Host directory......
chmod: changing permissions of '/home/wwwroot/object/.user.ini': Operation not permitted
chown: changing ownership of '/home/wwwroot/object/.user.ini': Operation not permitted
You select the exist rewrite rule:/usr/local/nginx/conf/rewrite/yii2.conf
Test Nginx configure file......
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/objectapi.***.cn.conf:45
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/objectapi.***.cn.conf:45
/usr/bin/lnmp: line 585: /home/wwwroot/object/.user.ini: Operation not permitted
chmod: changing permissions of '/home/wwwroot/object/.user.ini': Operation not permitted
Reload service php-fpm  done
/usr/local/acme.sh/acme.sh [found]
Generate ssl certificate using Let's Encrypt...
[Sat Mar  8 05:01:09 PM CST 2025] Using CA: https://acme-v02.api.letsencrypt.org/directory
[Sat Mar  8 05:01:09 PM CST 2025] Creating domain key
[Sat Mar  8 05:01:09 PM CST 2025] The domain key is here: /usr/local/nginx/conf/ssl/object.***.cn/object.***.cn.key
[Sat Mar  8 05:01:09 PM CST 2025] Single domain='object.***.cn'
[Sat Mar  8 05:01:09 PM CST 2025] Getting domain auth token for each domain
[Sat Mar  8 05:01:14 PM CST 2025] Getting webroot for domain='object.***.cn'
[Sat Mar  8 05:01:14 PM CST 2025] Verifying: object.***.cn
[Sat Mar  8 05:01:15 PM CST 2025] Pending, The CA is processing your order, please just wait. (1/30)
[Sat Mar  8 05:01:20 PM CST 2025] Pending, The CA is processing your order, please just wait. (2/30)
[Sat Mar  8 05:01:24 PM CST 2025] Success
[Sat Mar  8 05:01:24 PM CST 2025] Verify finished, start to sign.
[Sat Mar  8 05:01:24 PM CST 2025] Lets finalize the order.
[Sat Mar  8 05:01:24 PM CST 2025] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/2269553226/361405220756'
[Sat Mar  8 05:01:25 PM CST 2025] Downloading cert.
[Sat Mar  8 05:01:25 PM CST 2025] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/038e2b0873b6d47b9eec4e6117670e32abd9'
[Sat Mar  8 05:01:26 PM CST 2025] Cert success.
[Sat Mar  8 05:01:26 PM CST 2025] Your cert is in: /usr/local/nginx/conf/ssl/object.***.cn/object.***.cn.cer
[Sat Mar  8 05:01:26 PM CST 2025] Your cert key is in: /usr/local/nginx/conf/ssl/object.***.cn/object.***.cn.key
[Sat Mar  8 05:01:26 PM CST 2025] The intermediate CA cert is in: /usr/local/nginx/conf/ssl/object.***.cn/ca.cer
[Sat Mar  8 05:01:26 PM CST 2025] And the full chain certs is there: /usr/local/nginx/conf/ssl/object.***.cn/fullchain.cer
[Sat Mar  8 05:01:26 PM CST 2025] Run reload cmd: /etc/init.d/nginx reload
Reload nginx... nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/objectapi.***.cn.conf:45
 done
[Sat Mar  8 05:01:26 PM CST 2025] Reload success
Test Nginx configure file......
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/object.***.cn.conf:45
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/objectapi.***.cn.conf:45
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/object.***.cn.conf:45
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/objectapi.***.cn.conf:45
 Generate SSL Certificate successfully.
================================================
Virtualhost infomation:
Your domain: object.***.cn
Home Directory: /home/wwwroot/object
Rewrite: yii2
Enable log: yes
Create database: no
Create ftp account: no
Enable SSL: yes
  =>Let's Encrypt
IPv6 Support: Disabled
================================================



6、安装 Git,基于 Gitee 部署。配置 SSH 密钥 在服务器上生成 SSH 密钥:


[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# yum install git
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ssh-keygen -t rsa -b 4096 -C "root@server"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:7x7XrLbCPcTqfi3kw5aMg7NX2xXSRI4iOfr6VAZ4CO0 root@server
The key's randomart image is:
+---[RSA 4096]----+
|     ..       .. |
|      ..o .   o. |
|      .o * . .o. |
|       Eo + .. o |
|       .S  +  . .|
|        ..o =o  .|
|         =o@.=o. |
|        =.Bo#.o  |
|       .oO=*o=   |
+----[SHA256]-----+



7、将公钥添加到 Gitee:复制公钥:登录 Gitee,进入 个人设置 > SSH 公钥,添加公钥。如图3
将公钥添加到 Gitee:复制公钥:登录 Gitee,进入 个人设置 > SSH 公钥,添加公钥

图3



[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# cat ~/.ssh/id_rsa.pub



8、在项目目录中克隆 Gitee 仓库 失败。初始化 Git 仓库,添加远程仓库,拉取代码。如图4
在项目目录中克隆 Gitee 仓库 失败。初始化 Git 仓库,添加远程仓库,拉取代码

图4



[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git clone git@gitee.com:about/check-in-star-backend.git .
fatal: destination path '.' already exists and is not an empty directory.
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /home/wwwroot/object/.git/
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ls -l
total 0
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git remote add origin git@gitee.com:about/check-in-star-backend.git
fatal: detected dubious ownership in repository at '/home/wwwroot/object'
To add an exception for this directory, call:

        git config --global --add safe.directory /home/wwwroot/object
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ls -l
total 0
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git pull origin v1.0.0
fatal: detected dubious ownership in repository at '/home/wwwroot/object'
To add an exception for this directory, call:

        git config --global --add safe.directory /home/wwwroot/object
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ^C
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git config --global --add safe.directory /home/wwwroot/object
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git pull origin v1.0.0
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ^C
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ls -la
total 4
drwxr-xr-x 3 www  www   35 Mar  8 17:42 .
drwxr-xr-x 4 root root  32 Mar  8 16:57 ..
drwxr-xr-x 7 root root 137 Mar  8 17:44 .git
-rw-r--r-- 1 root root  44 Mar  8 16:57 .user.ini
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ^C
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git remote -v
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git remote add origin git@gitee.com:about/check-in-star-backend.git
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git remote -v
origin  git@gitee.com:about/check-in-star-backend.git (fetch)
origin  git@gitee.com:about/check-in-star-backend.git (push)
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# git pull origin v1.0.0
remote: Enumerating objects: 3941, done.
remote: Counting objects: 100% (3941/3941), done.
remote: Compressing objects: 100% (2626/2626), done.
remote: Total 3941 (delta 1980), reused 2851 (delta 1219), pack-reused 0 (from 0)
Receiving objects: 100% (3941/3941), 79.29 MiB | 10.42 MiB/s, done.
Resolving deltas: 100% (1980/1980), done.
From gitee.com:about/check-in-star-backend
 * tag               v1.0.0     -> FETCH_HEAD
fatal: update_ref failed for ref 'HEAD': cannot update ref 'refs/heads/master': trying to write non-commit object 7cefa5873aefc80530d576109a29df9b9a9cf161 to branch 'refs/heads/master'
[root@iZ2zeaj7tnbv8d3gsoy1w5Z object]# ls -la
total 12
drwxr-xr-x  4 www  www    81 Mar  8 17:48 .
drwxr-xr-x  4 root root   32 Mar  8 16:57 ..
drwxr-xr-x  7 root root  150 Mar  8 17:48 .git
-rw-r--r--  1 root root    7 Mar  8 17:48 .gitignore
-rw-r--r--  1 root root    0 Mar  8 17:48 README.md
drwxr-xr-x 11 root root 4096 Mar  8 17:48 src
-rw-r--r--  1 root root   44 Mar  8 16:57 .user.ini



   ]]>
https://www.shuijingwanwq.com/2025/04/09/8960/feed/ 0
将一个网站的域名切换为另一个域名的流程 https://www.shuijingwanwq.com/2023/07/21/7894/ https://www.shuijingwanwq.com/2023/07/21/7894/#respond Fri, 21 Jul 2023 01:12:00 +0000 https://www.shuijingwanwq.com/?p=7894 浏览量: 146 1、现在的域名是:https://learn-php-app-0605-prod.shuijingwanwq.com 。计划切换为:https://learn-php-app-0605-prod.wangqiang.store 。如图1
现在的域名是:https://learn-php-app-0605-prod.shuijingwanwq.com 。计划切换为:https://learn-php-app-0605-prod.wangqiang.store

图1

2、添加 learn-php-app-0605-prod.wangqiang.store 的 DNS 解析。如图2
添加 learn-php-app-0605-prod.wangqiang.store 的 DNS 解析

图2

3、基于 OneinStack 删除之前的虚拟主机:learn-php-app-0605-prod.shuijingwanwq.com ,目录不应该删除。


[root@iZ23wv7v5ggZ ~]# ~/oneinstack/vhost.sh --del

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

Virtualhost list:
learn-php-app-0605-prod.shuijingwanwq.com www.shuijingwanwq.com

Please input a domain you want to delete: learn-php-app-0605-prod.shuijingwanwq.com

Do you want to delete Virtul Host directory? [y/n]: n

Domain: learn-php-app-0605-prod.shuijingwanwq.com has been deleted.



4、基于 OneinStack 添加新的虚拟主机:learn-php-app-0605-prod.wangqiang.store,目录仍然沿用之前的虚拟主机的目录:/data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com


[root@iZ23wv7v5ggZ ~]# ~/oneinstack/vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Use HTTP Only
        2. Use your own SSL Certificate and Key
        3. Use Let's Encrypt to Create SSL Certificate and Key
        q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): learn-php-app-0605-prod.wangqiang.store
domain=learn-php-app-0605-prod.wangqiang.store

Please input the directory for the domain:learn-php-app-0605-prod.wangqiang.store :
(Default directory: /data/wwwroot/learn-php-app-0605-prod.wangqiang.store): /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please select domain cert key length.
Enter one of 2048, 3072, 4096, 8192 will issue a RSA cert.
Enter one of ec-256, ec-384, ec-521 will issue a ECC cert.

Please enter your cert key length (default 2048):
[Thu Jun 15 05:07:11 PM CST 2023] Using CA: https://acme.zerossl.com/v2/DV90
[Thu Jun 15 05:07:11 PM CST 2023] Creating domain key
[Thu Jun 15 05:07:11 PM CST 2023] The domain key is here: /root/.acme.sh/learn-php-app-0605-prod.wangqiang.store/learn-php-app-0605-prod.wangqiang.store.key
[Thu Jun 15 05:07:11 PM CST 2023] Single domain='learn-php-app-0605-prod.wangqiang.store'
[Thu Jun 15 05:07:11 PM CST 2023] Getting domain auth token for each domain
[Thu Jun 15 05:07:17 PM CST 2023] Getting webroot for domain='learn-php-app-0605-prod.wangqiang.store'
[Thu Jun 15 05:07:17 PM CST 2023] Verifying: learn-php-app-0605-prod.wangqiang.store
[Thu Jun 15 05:07:19 PM CST 2023] Processing, The CA is processing your order, please just wait. (1/30)
[Thu Jun 15 05:07:23 PM CST 2023] Success
[Thu Jun 15 05:07:23 PM CST 2023] Verify finished, start to sign.
[Thu Jun 15 05:07:23 PM CST 2023] Lets finalize the order.
[Thu Jun 15 05:07:23 PM CST 2023] Le_OrderFinalize='https://acme.zerossl.com/v2/DV90/order/HvpQ_zj63S9ys7pI8RtvAw/finalize'
[Thu Jun 15 05:07:25 PM CST 2023] Order status is processing, lets sleep and retry.
[Thu Jun 15 05:07:25 PM CST 2023] Retry after: 15
[Thu Jun 15 05:07:41 PM CST 2023] Polling order status: https://acme.zerossl.com/v2/DV90/order/HvpQ_zj63S9ys7pI8RtvAw
[Thu Jun 15 05:07:42 PM CST 2023] Downloading cert.
[Thu Jun 15 05:07:42 PM CST 2023] Le_LinkCert='https://acme.zerossl.com/v2/DV90/cert/34xe1tRFLIZFO436TLz-7Q'
[Thu Jun 15 05:07:44 PM CST 2023] Cert success.
-----BEGIN CERTIFICATE-----
**********************************
-----END CERTIFICATE-----
[Thu Jun 15 05:07:44 PM CST 2023] Your cert is in: /root/.acme.sh/learn-php-app-0605-prod.wangqiang.store/learn-php-app-0605-prod.wangqiang.store.cer
[Thu Jun 15 05:07:44 PM CST 2023] Your cert key is in: /root/.acme.sh/learn-php-app-0605-prod.wangqiang.store/learn-php-app-0605-prod.wangqiang.store.key
[Thu Jun 15 05:07:44 PM CST 2023] The intermediate CA cert is in: /root/.acme.sh/learn-php-app-0605-prod.wangqiang.store/ca.cer
[Thu Jun 15 05:07:44 PM CST 2023] And the full chain certs is there: /root/.acme.sh/learn-php-app-0605-prod.wangqiang.store/fullchain.cer

Do you want to add hotlink protection? [y/n]: y

Allow Rewrite rule? [y/n]: y

Please input the rewrite of programme :
wordpress,opencart,magento2,drupal,joomla,codeigniter,laravel
thinkphp,pathinfo,discuz,typecho,ecshop,nextcloud,zblog,whmcs rewrite was exist.
(Default rewrite: other): laravel
You choose rewrite=laravel

Allow Nginx/Tengine/OpenResty access_log? [y/n]: y
You access log file=/data/wwwlogs/learn-php-app-0605-prod.wangqiang.store_nginx.log

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################
Your domain:                  learn-php-app-0605-prod.wangqiang.store
Virtualhost conf:             /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.wangqiang.store.conf
Directory of:                 /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com
Rewrite rule:                 /usr/local/nginx/conf/rewrite/laravel.conf
Let's Encrypt SSL Certificate:/usr/local/nginx/conf/ssl/learn-php-app-0605-prod.wangqiang.store.crt
SSL Private Key:              /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.wangqiang.store.key



5、按需编辑 Nginx 配置文件后,重启 Nginx 服务。


[root@iZ23wv7v5ggZ ~]# vi /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.wangqiang.store.conf
[root@iZ23wv7v5ggZ ~]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service



6、打开:https://learn-php-app-0605-prod.wangqiang.store/robots.txt 。确认域名已经切换成功。如图3
打开:https://learn-php-app-0605-prod.wangqiang.store/robots.txt 。确认域名已经切换成功

图3

]]>
https://www.shuijingwanwq.com/2023/07/21/7894/feed/ 0
部署 Shopify PHP 应用至生产环境(阿里云、ECS 中的 CentOS 7.7 64位、MySQL 5.7) https://www.shuijingwanwq.com/2023/07/13/7855/ https://www.shuijingwanwq.com/2023/07/13/7855/#comments Thu, 13 Jul 2023 03:06:29 +0000 https://www.shuijingwanwq.com/?p=7855 浏览量: 326

1、现有一个 Shopify PHP 应用,已经可在开发环境中预览。如图1

现有一个 Shopify PHP 应用,已经可在开发环境中预览

图1

2、现准备将其部署至生产环境。如果需要部署应用至生产环境,Shopify 建议创建一个单独的应用。此应用与开发、测试环境共用代码库,但是在 Shopify 合作伙伴中心有自己的记录和配置。以避免在开发和测试过程中影响到生产环境的应用。使用 Shopify 合作伙伴
从头开始创建应用:learn-php-app-0605-prod。如图2

使用 Shopify 合作伙伴从头开始创建应用:learn-php-app-0605-prod

图2

3、检索环境变量,以便可以在稍后的步骤中设置它们。记下 SCOPES、SHOPIFY_API_KEY 和 SHOPIFY_API_SECRET 值。 您需要将这些值设置为托管应用程序的环境变量。


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ npm run shopify app env show

> learn-php-app-ubuntu-2004-0605@1.0.0 shopify
> shopify app env show

?  Which existing app is this for?
&#x2714;  learn-php-app-0605-prod


    SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef
    SHOPIFY_API_SECRET=4de64aa8281e97055cf7698bbe56039e
    SCOPES=write_products



4、参考:基于阿里云的 ECS、RDS,将个人博客迁移升级至:Docker(基于预算考虑,最终未实现)、LNMP(CentOS 7.7、Nginx 1.16、MySQL 5.7、PHP 7.4)、HTTPS 的过程  ,之前的环境是基于 OneinStack 的自动安装。PHP 版本 7.4 已经不再符合 Shopify 应用的运行条件。需要升级至 8.1 版本,尽量与本地环境保持一致。


[root@iZ23wv7v5ggZ ~]# php -v
PHP 7.4.0 (cli) (built: Dec  5 2019 11:56:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies




wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ php -v
PHP 8.1.18 (cli) (built: Apr 14 2023 04:39:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies


5、参考:在 阿里云中的 CentOS 7.7 中卸载 PHP 7.4,然后安装 PHP 8

6、查看阿里云中的 ECS 的 Alibaba Cloud Linux 3 的 PHP 版本


[root@iZ23wv7v5ggZ ~]# php -v
PHP 8.1.19 (cli) (built: Jun  7 2023 11:34:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.19, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.19, Copyright (c), by Zend Technologies
[root@iZ23wv7v5ggZ ~]#



7、添加虚拟主机时,设置 SSL 证书失败:Let’s Encrypt Verify error! DNS problem,需要先设置域名的解析。


[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# ~/oneinstack/vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Use HTTP Only
        2. Use your own SSL Certificate and Key
        3. Use Let's Encrypt to Create SSL Certificate and Key
        q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): learn-php-app-0605-prod.shuijingwanwq.com
domain=learn-php-app-0605-prod.shuijingwanwq.com

Please input the directory for the domain:learn-php-app-0605-prod.shuijingwanwq.com :
(Default directory: /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com):
Virtual Host Directory=/data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please select domain cert key length.
Enter one of 2048, 3072, 4096, 8192 will issue a RSA cert.
Enter one of ec-256, ec-384, ec-521 will issue a ECC cert.

Please enter your cert key length (default 2048):

Let's Encrypt Verify error! DNS problem: NXDOMAIN looking up A for learn-php-app-0605-prod.shuijingwanwq.com
[Wed Jun  7 04:44:59 PM CST 2023] Using CA: https://acme.zerossl.com/v2/DV90
[Wed Jun  7 04:44:59 PM CST 2023] Creating domain key
[Wed Jun  7 04:44:59 PM CST 2023] The domain key is here: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/learn-php-app-0605-prod.shuijingwanwq.com.key
[Wed Jun  7 04:44:59 PM CST 2023] Single domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:44:59 PM CST 2023] Getting domain auth token for each domain
[Wed Jun  7 04:45:05 PM CST 2023] Getting webroot for domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:45:05 PM CST 2023] Verifying: learn-php-app-0605-prod.shuijingwanwq.com
[Wed Jun  7 04:45:07 PM CST 2023] Processing, The CA is processing your order, please just wait. (1/30)
[Wed Jun  7 04:45:11 PM CST 2023] learn-php-app-0605-prod.shuijingwanwq.com:Verify error:"error":{
[Wed Jun  7 04:45:11 PM CST 2023] Please add '--debug' or '--log' to check more details.
[Wed Jun  7 04:45:11 PM CST 2023] See: https://github.com/acmesh-official/acme.sh/wiki/How-to-debug-acme.sh
Error: Create Let's Encrypt SSL Certificate failed!
[root@iZ23wv7v5ggZ www.shuijingwanwq.com]#



8、在阿里云 云解析DNS 中添加记录。如图3

在阿里云 云解析DNS 中添加记录

图3

9、再次添加虚拟主机


[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# ~/oneinstack/vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Use HTTP Only
        2. Use your own SSL Certificate and Key
        3. Use Let's Encrypt to Create SSL Certificate and Key
        q. Exit
Please input the correct option: 3

Please input domain(example: www.example.com): learn-php-app-0605-prod.shuijingwanwq.com
domain=learn-php-app-0605-prod.shuijingwanwq.com

Please input the directory for the domain:learn-php-app-0605-prod.shuijingwanwq.com :
(Default directory: /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com):
Virtual Host Directory=/data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com

Create Virtul Host directory......
set permissions of Virtual Host directory......

Do you want to add more domain name? [y/n]: n

Do you want to redirect all HTTP requests to HTTPS? [y/n]: y

Please select domain cert key length.
Enter one of 2048, 3072, 4096, 8192 will issue a RSA cert.
Enter one of ec-256, ec-384, ec-521 will issue a ECC cert.

Please enter your cert key length (default 2048):
[Wed Jun  7 04:51:49 PM CST 2023] Using CA: https://acme.zerossl.com/v2/DV90
[Wed Jun  7 04:51:49 PM CST 2023] Single domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:51:49 PM CST 2023] Getting domain auth token for each domain
[Wed Jun  7 04:51:54 PM CST 2023] Getting webroot for domain='learn-php-app-0605-prod.shuijingwanwq.com'
[Wed Jun  7 04:51:54 PM CST 2023] Verifying: learn-php-app-0605-prod.shuijingwanwq.com
[Wed Jun  7 04:51:55 PM CST 2023] Processing, The CA is processing your order, please just wait. (1/30)
[Wed Jun  7 04:52:01 PM CST 2023] Success
[Wed Jun  7 04:52:01 PM CST 2023] Verify finished, start to sign.
[Wed Jun  7 04:52:01 PM CST 2023] Lets finalize the order.
[Wed Jun  7 04:52:01 PM CST 2023] Le_OrderFinalize='https://acme.zerossl.com/v2/DV90/order/CLf6pxWJkdxtQylgNxS_Jg/finalize'
[Wed Jun  7 04:52:02 PM CST 2023] Order status is processing, lets sleep and retry.
[Wed Jun  7 04:52:02 PM CST 2023] Retry after: 15
[Wed Jun  7 04:52:18 PM CST 2023] Polling order status: https://acme.zerossl.com/v2/DV90/order/CLf6pxWJkdxtQylgNxS_Jg
[Wed Jun  7 04:52:20 PM CST 2023] Downloading cert.
[Wed Jun  7 04:52:20 PM CST 2023] Le_LinkCert='https://acme.zerossl.com/v2/DV90/cert/B2uRnJRfyVAP2B9aqQ2_Lw'
[Wed Jun  7 04:52:22 PM CST 2023] Cert success.
-----BEGIN CERTIFICATE-----
*******************
-----END CERTIFICATE-----
[Wed Jun  7 04:52:22 PM CST 2023] Your cert is in: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/learn-php-app-0605-prod.shuijingwanwq.com.cer
[Wed Jun  7 04:52:22 PM CST 2023] Your cert key is in: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/learn-php-app-0605-prod.shuijingwanwq.com.key
[Wed Jun  7 04:52:22 PM CST 2023] The intermediate CA cert is in: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/ca.cer
[Wed Jun  7 04:52:22 PM CST 2023] And the full chain certs is there: /root/.acme.sh/learn-php-app-0605-prod.shuijingwanwq.com/fullchain.cer

Do you want to add hotlink protection? [y/n]: y

Allow Rewrite rule? [y/n]: y

Please input the rewrite of programme :
wordpress,opencart,magento2,drupal,joomla,codeigniter,laravel
thinkphp,pathinfo,discuz,typecho,ecshop,nextcloud,zblog,whmcs rewrite was exist.
(Default rewrite: other): laravel
You choose rewrite=laravel

Allow Nginx/Tengine/OpenResty access_log? [y/n]: y
You access log file=/data/wwwlogs/learn-php-app-0605-prod.shuijingwanwq.com_nginx.log

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################
Your domain:                  learn-php-app-0605-prod.shuijingwanwq.com
Virtualhost conf:             /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.shuijingwanwq.com.conf
Directory of:                 /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com
Rewrite rule:                 /usr/local/nginx/conf/rewrite/laravel.conf
Let's Encrypt SSL Certificate:/usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.crt
SSL Private Key:              /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.key
[root@iZ23wv7v5ggZ www.shuijingwanwq.com]#



10、添加FTP账号


[root@iZ23wv7v5ggZ www.shuijingwanwq.com]# ~/oneinstack/pureftpd_vhost.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#                 FTP virtual user account management                 #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. UserAdd
        2. UserMod
        3. UserPasswd
        4. UserDel
        5. ListAllUser
        6. ShowUser
        q. Exit
Please input the correct option: 1

Please input a username: learn-php-app-0605-prod.shuijingwanwq.com

Please input the password: XZzqpC4k3Clf6Oup26e

Please input the directory(Default directory: /data/wwwroot): /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com
Password:
Enter it again:
#####################################

[learn-php-app-0605-prod.shuijingwanwq.com] create successful!

You user name is : learn-php-app-0605-prod.shuijingwanwq.com
You Password is : ************
You directory is : /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com



11、此时,需要在本地环境中构建生产环境中的应用,避免在生产环境中构建,因为生产环境中暂不支持构建所需要的前提条件,比如说 npm、composer 等。SHOPIFY_API_KEY 需要使用 步骤 3 中检索出的变量值。复制应用目录 learn-php-app-ubuntu-2004-0605/web 为 learn-php-app-0605-prod。目录 learn-php-app-0605-prod 仅需要构建后,上传至生产环境,因此,开发环境的依赖文件皆不需要。


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app$ cd learn-php-app-0605-prod/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ ls -l
total 300
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 app
-rwxrwxrwx 1 wangqiang wangqiang   1690 Jun  5 15:02 artisan
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 bootstrap
-rwxrwxrwx 1 wangqiang wangqiang   2238 Jun  5 15:02 composer.json
-rwxrwxrwx 1 wangqiang wangqiang 304694 Jun  6 09:35 composer.lock
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 config
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:38 database
-rwxrwxrwx 1 wangqiang wangqiang    450 Jun  5 15:02 entrypoint.sh
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 frontend
-rwxrwxrwx 1 wangqiang wangqiang    860 Jun  5 15:00 nginx.conf
-rwxrwxrwx 1 wangqiang wangqiang   1202 Jun  5 15:00 phpunit.xml
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 public
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 resources
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 routes
-rwxrwxrwx 1 wangqiang wangqiang    563 Jun  5 15:00 server.php
-rwxrwxrwx 1 wangqiang wangqiang     75 Jun  5 15:00 shopify.web.toml
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:39 storage
drwxrwxrwx 1 wangqiang wangqiang   4096 Jun  7 17:42 vendor



12、编辑 .env ,设置为生产环境中的配置值


APP_NAME="Shopify PHP App 0605 Prod"
APP_ENV=production
APP_KEY=***********
APP_DEBUG=false

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=************
DB_PORT=3306
DB_DATABASE=learn_php_app_0605_prod
DB_USERNAME=learn_php_app_0605_prod
DB_PASSWORD=**********



13、构建前端与后端,报错:/bin/sh: 1: vite: not found,需要先执行:npm install 。如图4

构建前端与后端,报错:/bin/sh: 1: vite: not found,需要先执行:npm install

图4


wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/frontend$ SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef yarn build
yarn run v1.22.15
$ vite build
/bin/sh: 1: vite: not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/frontend$ npm install
npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.

added 354 packages, and audited 360 packages in 3m

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/frontend$ SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef npm run build

> shopify-frontend-template-react@1.0.0 build
> vite build

vite v4.3.9 building for production...
✓ 1966 modules transformed.
dist/assets/empty-state-8039a1e1.svg      0.26 kB │ gzip:   0.20 kB
dist/index.html                           0.48 kB │ gzip:   0.33 kB
dist/assets/home-trophy-d70b3542.png     20.65 kB
dist/assets/index-37530742.css          371.48 kB │ gzip:  45.42 kB
dist/assets/ko-ef9a93f5.js                0.21 kB │ gzip:   0.15 kB
dist/assets/ja-abb1af27.js                0.21 kB │ gzip:   0.15 kB
dist/assets/zh-4775ba45.js                0.21 kB │ gzip:   0.15 kB
dist/assets/th-32f01d1c.js                0.21 kB │ gzip:   0.15 kB
dist/assets/vi-72f55a87.js                0.23 kB │ gzip:   0.17 kB
dist/assets/nb-79727cd5.js                0.24 kB │ gzip:   0.17 kB
dist/assets/tr-d5c962f0.js                0.24 kB │ gzip:   0.17 kB
dist/assets/nl-ed6c02b1.js                0.28 kB │ gzip:   0.20 kB
dist/assets/de-5d4a5256.js                0.28 kB │ gzip:   0.20 kB
dist/assets/fi-e67a7779.js                0.28 kB │ gzip:   0.20 kB
dist/assets/da-9b835bb8.js                0.31 kB │ gzip:   0.22 kB
dist/assets/cs-d855408e.js                0.32 kB │ gzip:   0.23 kB
dist/assets/sv-8ac62b51.js                0.37 kB │ gzip:   0.25 kB
dist/assets/en-d265ad8d.js                0.41 kB │ gzip:   0.26 kB
dist/assets/es-fd2f35f4.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-227fd344.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-PT-a0c51464.js             0.41 kB │ gzip:   0.29 kB
dist/assets/pl-ab15c7ea.js                0.42 kB │ gzip:   0.29 kB
dist/assets/fr-23e50d95.js                0.43 kB │ gzip:   0.29 kB
dist/assets/it-08f76780.js                0.45 kB │ gzip:   0.30 kB
dist/assets/en-df34a502.js                1.53 kB │ gzip:   0.77 kB
dist/assets/de-2ae5c9fa.js                1.72 kB │ gzip:   0.90 kB
dist/assets/fr-5253333d.js                1.83 kB │ gzip:   0.94 kB
dist/assets/polyfill-force-11887b4b.js    5.21 kB │ gzip:   2.03 kB
dist/assets/zh-CN-cf74d136.js             7.72 kB │ gzip:   3.26 kB
dist/assets/zh-TW-6a74a185.js             7.86 kB │ gzip:   3.36 kB
dist/assets/ko-2cf626e6.js                8.18 kB │ gzip:   3.39 kB
dist/assets/ja-6f78282b.js                8.35 kB │ gzip:   3.58 kB
dist/assets/en-c240dff3.js                9.95 kB │ gzip:   2.95 kB
dist/assets/vi-e4ef4fd6.js                9.97 kB │ gzip:   3.34 kB
dist/assets/th-2a34d5e0.js               10.14 kB │ gzip:   3.77 kB
dist/assets/sv-a901b08f.js               10.22 kB │ gzip:   3.27 kB
dist/assets/da-1564850b.js               10.30 kB │ gzip:   3.26 kB
dist/assets/nb-0a6d8490.js               10.35 kB │ gzip:   3.25 kB
dist/assets/pl-a603e9c2.js               10.39 kB │ gzip:   3.39 kB
dist/assets/cs-3c753a97.js               10.40 kB │ gzip:   3.50 kB
dist/assets/fi-c0a9d95f.js               10.63 kB │ gzip:   3.41 kB
dist/assets/tr-bd45be97.js               10.68 kB │ gzip:   3.39 kB
dist/assets/it-8bb02787.js               10.72 kB │ gzip:   3.32 kB
dist/assets/pt-PT-af188c06.js            10.85 kB │ gzip:   3.34 kB
dist/assets/nl-0772ea77.js               10.89 kB │ gzip:   3.25 kB
dist/assets/pt-BR-8a1d5660.js            10.94 kB │ gzip:   3.36 kB
dist/assets/es-5e0e20e7.js               10.95 kB │ gzip:   3.39 kB
dist/assets/de-a04fe3bd.js               11.11 kB │ gzip:   3.35 kB
dist/assets/fr-1848494a.js               11.31 kB │ gzip:   3.48 kB
dist/assets/index-41437cc7.js            53.59 kB │ gzip:  18.93 kB
dist/assets/polyfill-904c231f.js        133.64 kB │ gzip:  40.74 kB
dist/assets/index-991532e3.js           618.82 kB │ gzip: 164.28 kB

(!) Some chunks are larger than 500 kBs after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 47.73s
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ composer build
> composer build-frontend-links
> ln -sf ../frontend/dist/assets public/assets &amp;&amp; ln -sf ../frontend/dist/index.html public/index.html
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod$ cd public/
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-0605-prod/public$ ls -l
total 0
lrwxrwxrwx 1 wangqiang wangqiang   23 Jun  6 10:06 assets -> ../frontend/dist/assets
-rwxrwxrwx 1 wangqiang wangqiang    0 Jun  5 15:00 favicon.ico
lrwxrwxrwx 1 wangqiang wangqiang   27 Jun  8 09:45 index.html -> ../frontend/dist/index.html
-rwxrwxrwx 1 wangqiang wangqiang 1743 Jun  5 15:00 index.php
-rwxrwxrwx 1 wangqiang wangqiang   24 Jun  5 15:00 robots.txt


14、基于 FTP 上传 目录 learn-php-app-0605-prod 下的所有文件。总计大小为 150 MB 左右。上传时间过长,最张决定在生产环境中构建。目录:vendor、frontend/node_modules 不上传。如图5

基于 FTP 上传 目录 learn-php-app-0605-prod 下的所有文件。总计大小为 150 MB 左右。上传时间过长,最张决定在生产环境中构建。目录:vendor、frontend/node_modules 不上传

图5

15、安装 Node.js 与 Composer,Node.js 安装后需要重启实例


[root@iZ23wv7v5ggZ ~]# ~/oneinstack/install.sh --node

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

Download Nodejs...
--2023-06-08 10:45:47--  https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/v18.14.2/node-v18.14.2-linux-x64.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 44201520 (42M) [application/octet-stream]
Saving to: ‘node-v18.14.2-linux-x64.tar.gz’

     0K .......... .......... .......... .......... ..........  0%  878K 49s
    50K .......... .......... .......... .......... ..........  0% 1.79M 36s
 43150K .......... .....                                      100% 14.2M=2.7s

2023-06-08 10:45:50 (15.7 MB/s) - ‘node-v18.14.2-linux-x64.tar.gz’ saved [44201520/44201520]

Nodejs installed successfully!
[xprober.php] found
####################Congratulations########################
Total OneinStack Install Time: 0 minutes

[root@iZ23wv7v5ggZ ~]# node -v
-bash: node: command not found

[root@iZ23wv7v5ggZ ~]# ~/oneinstack/addons.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#                    Install/Uninstall Extensions                     #
#       For more information please visit https://oneinstack.com      #
#######################################################################

What Are You Doing?
        1. Install/Uninstall PHP Composer
        2. Install/Uninstall fail2ban
        3. Install/Uninstall ngx_lua_waf
        4. Install/Uninstall Python3.6
        q. Exit
Please input the correct option: 1

Please select an action:
        1. install
        2. uninstall
Please input a number:(Default 1 press Enter) 1

PHP Composer installed successfully!

What Are You Doing?
        1. Install/Uninstall PHP Composer
        2. Install/Uninstall fail2ban
        3. Install/Uninstall ngx_lua_waf
        4. Install/Uninstall Python3.6
        q. Exit
Please input the correct option: q
[root@iZ23wv7v5ggZ ~]# composer -V
Composer version 2.5.7 2023-05-24 15:00:39
[root@iZ23wv7v5ggZ ~]# node -v
v18.14.2



16、当FTP上传完毕后,创建数据库(连接信息与 .env 中的保持一致),生成APP_KEY ,执行数据库迁移,构建前端与后端



[root@iZ23wv7v5ggZ frontend]# npm install
npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.

added 359 packages, and audited 360 packages in 17s

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 9.5.0 -> 9.7.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.7.1
npm notice Run npm install -g npm@9.7.1 to update!
npm notice
[root@iZ23wv7v5ggZ frontend]# SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef npm run build

> shopify-frontend-template-react@1.0.0 build
> vite build

vite v4.3.9 building for production...
✓ 1966 modules transformed.
dist/assets/empty-state-8039a1e1.svg      0.26 kB │ gzip:   0.20 kB
dist/index.html                           0.48 kB │ gzip:   0.33 kB
dist/assets/home-trophy-d70b3542.png     20.65 kB
dist/assets/index-37530742.css          371.48 kB │ gzip:  45.42 kB
dist/assets/ja-abb1af27.js                0.21 kB │ gzip:   0.15 kB
dist/assets/ko-ef9a93f5.js                0.21 kB │ gzip:   0.15 kB
dist/assets/th-32f01d1c.js                0.21 kB │ gzip:   0.15 kB
dist/assets/zh-4775ba45.js                0.21 kB │ gzip:   0.15 kB
dist/assets/vi-72f55a87.js                0.23 kB │ gzip:   0.17 kB
dist/assets/nb-79727cd5.js                0.24 kB │ gzip:   0.17 kB
dist/assets/tr-d5c962f0.js                0.24 kB │ gzip:   0.17 kB
dist/assets/de-5d4a5256.js                0.28 kB │ gzip:   0.20 kB
dist/assets/fi-e67a7779.js                0.28 kB │ gzip:   0.20 kB
dist/assets/nl-ed6c02b1.js                0.28 kB │ gzip:   0.20 kB
dist/assets/da-9b835bb8.js                0.31 kB │ gzip:   0.22 kB
dist/assets/cs-d855408e.js                0.32 kB │ gzip:   0.23 kB
dist/assets/sv-8ac62b51.js                0.37 kB │ gzip:   0.25 kB
dist/assets/en-d265ad8d.js                0.41 kB │ gzip:   0.26 kB
dist/assets/es-fd2f35f4.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-227fd344.js                0.41 kB │ gzip:   0.29 kB
dist/assets/pt-PT-a0c51464.js             0.41 kB │ gzip:   0.29 kB
dist/assets/pl-ab15c7ea.js                0.42 kB │ gzip:   0.29 kB
dist/assets/fr-23e50d95.js                0.43 kB │ gzip:   0.29 kB
dist/assets/it-08f76780.js                0.45 kB │ gzip:   0.30 kB
dist/assets/en-df34a502.js                1.53 kB │ gzip:   0.77 kB
dist/assets/de-2ae5c9fa.js                1.72 kB │ gzip:   0.90 kB
dist/assets/fr-5253333d.js                1.83 kB │ gzip:   0.94 kB
dist/assets/polyfill-force-11887b4b.js    5.21 kB │ gzip:   2.03 kB
dist/assets/zh-CN-cf74d136.js             7.72 kB │ gzip:   3.26 kB
dist/assets/zh-TW-6a74a185.js             7.86 kB │ gzip:   3.36 kB
dist/assets/ko-2cf626e6.js                8.18 kB │ gzip:   3.39 kB
dist/assets/ja-6f78282b.js                8.35 kB │ gzip:   3.58 kB
dist/assets/en-c240dff3.js                9.95 kB │ gzip:   2.95 kB
dist/assets/vi-e4ef4fd6.js                9.97 kB │ gzip:   3.34 kB
dist/assets/th-2a34d5e0.js               10.14 kB │ gzip:   3.77 kB
dist/assets/sv-a901b08f.js               10.22 kB │ gzip:   3.27 kB
dist/assets/da-1564850b.js               10.30 kB │ gzip:   3.26 kB
dist/assets/nb-0a6d8490.js               10.35 kB │ gzip:   3.25 kB
dist/assets/pl-a603e9c2.js               10.39 kB │ gzip:   3.39 kB
dist/assets/cs-3c753a97.js               10.40 kB │ gzip:   3.50 kB
dist/assets/fi-c0a9d95f.js               10.63 kB │ gzip:   3.41 kB
dist/assets/tr-bd45be97.js               10.68 kB │ gzip:   3.39 kB
dist/assets/it-8bb02787.js               10.72 kB │ gzip:   3.32 kB
dist/assets/pt-PT-af188c06.js            10.85 kB │ gzip:   3.34 kB
dist/assets/nl-0772ea77.js               10.89 kB │ gzip:   3.25 kB
dist/assets/pt-BR-8a1d5660.js            10.94 kB │ gzip:   3.36 kB
dist/assets/es-5e0e20e7.js               10.95 kB │ gzip:   3.39 kB
dist/assets/de-a04fe3bd.js               11.11 kB │ gzip:   3.35 kB
dist/assets/fr-1848494a.js               11.31 kB │ gzip:   3.48 kB
dist/assets/index-41437cc7.js            53.59 kB │ gzip:  18.93 kB
dist/assets/polyfill-904c231f.js        133.64 kB │ gzip:  40.74 kB
dist/assets/index-991532e3.js           618.82 kB │ gzip: 164.28 kB

(!) Some chunks are larger than 500 kBs after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 21.56s
[root@iZ23wv7v5ggZ frontend]# cd ..
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - league/flysystem is locked to version 1.1.10 and an update of this package was not requested.
    - league/flysystem 1.1.10 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
  Problem 2
    - league/mime-type-detection is locked to version 1.11.0 and an update of this package was not requested.
    - league/mime-type-detection 1.11.0 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
  Problem 3
    - league/flysystem 1.1.10 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
    - laravel/framework v8.83.27 requires league/flysystem ^1.1 -> satisfiable by league/flysystem[1.1.10].
    - laravel/framework is locked to version v8.83.27 and an update of this package was not requested.

To enable extensions, verify that they are enabled in your .ini files:
    - /usr/local/php/etc/php.ini
    - /usr/local/php/etc/php.d/02-opcache.ini
    - /usr/local/php/etc/php.d/03-imagick.ini
    - /usr/local/php/etc/php.d/04-ldap.ini
    - /usr/local/php/etc/php.d/05-redis.ini
    - /usr/local/php/etc/php.d/07-mongodb.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-fileinfo` to temporarily ignore these required extensions.



17、安装 PHP 扩展 fileinfo 后,再次执行。报错:The Process class relies on proc_open, which is not available on your PHP installation.

[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 114 installs, 0 updates, 0 removals
proc_open is disabled so 'unzip' and '7z' commands cannot be used, zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Enabling proc_open and installing 'unzip' or '7z' (21.01+) may remediate them.
  - Downloading brick/math (0.11.0)
  - Downloading psr/log (2.0.0)
  - Downloading psr/cache (3.0.0)
  - Downloading doctrine/event-manager (2.0.0)
  - Downloading doctrine/deprecations (v1.1.1)
  - Downloading doctrine/cache (2.2.0)
  - Downloading doctrine/dbal (3.6.3)
  - Downloading doctrine/lexer (1.2.3)
  - Downloading symfony/polyfill-ctype (v1.27.0)
  - Downloading webmozart/assert (1.11.0)
  - Downloading dragonmantank/cron-expression (v3.3.2)
  - Downloading symfony/polyfill-php80 (v1.27.0)
  - Downloading symfony/polyfill-mbstring (v1.27.0)
  - Downloading symfony/var-dumper (v5.4.24)
  - Downloading symfony/polyfill-intl-normalizer (v1.27.0)
  - Downloading symfony/polyfill-intl-grapheme (v1.27.0)
  - Downloading symfony/string (v6.3.0)
  - Downloading symfony/deprecation-contracts (v3.3.0)
  - Downloading psr/container (1.1.2)
  - Downloading symfony/service-contracts (v2.5.2)
  - Downloading symfony/polyfill-php73 (v1.27.0)
  - Downloading symfony/console (v5.4.24)
  - Downloading monolog/monolog (2.9.1)
  - Downloading voku/portable-ascii (1.6.1)
  - Downloading phpoption/phpoption (1.9.1)
  - Downloading graham-campbell/result-type (v1.1.1)
  - Downloading vlucas/phpdotenv (v5.5.0)
  - Downloading symfony/css-selector (v6.3.0)
  - Downloading tijsverkoyen/css-to-inline-styles (2.2.6)
  - Downloading symfony/routing (v5.4.22)
  - Downloading symfony/process (v5.4.24)
  - Downloading symfony/polyfill-php72 (v1.27.0)
  - Downloading symfony/polyfill-intl-idn (v1.27.0)
  - Downloading symfony/mime (v5.4.23)
  - Downloading symfony/http-foundation (v5.4.24)
  - Downloading psr/event-dispatcher (1.0.0)
  - Downloading symfony/event-dispatcher-contracts (v3.3.0)
  - Downloading symfony/event-dispatcher (v6.3.0)
  - Downloading symfony/error-handler (v5.4.24)
  - Downloading symfony/http-kernel (v5.4.24)
  - Downloading symfony/finder (v5.4.21)
  - Downloading symfony/polyfill-iconv (v1.27.0)
  - Downloading egulias/email-validator (2.1.25)
  - Downloading swiftmailer/swiftmailer (v6.3.0)
  - Downloading ramsey/collection (2.0.0)
  - Downloading ramsey/uuid (4.7.4)
  - Downloading psr/simple-cache (1.0.1)
  - Downloading opis/closure (3.6.3)
  - Downloading symfony/translation-contracts (v3.3.0)
  - Downloading symfony/translation (v6.3.0)
  - Downloading nesbot/carbon (2.67.0)
  - Downloading league/mime-type-detection (1.11.0)
  - Downloading league/flysystem (1.1.10)
  - Downloading nette/utils (v4.0.0)
  - Downloading nette/schema (v1.2.3)
  - Downloading dflydev/dot-access-data (v3.0.2)
  - Downloading league/config (v1.2.0)
  - Downloading league/commonmark (2.4.0)
  - Downloading laravel/serializable-closure (v1.3.0)
  - Downloading doctrine/inflector (2.0.6)
  - Downloading laravel/framework (v8.83.27)
  - Downloading facade/ignition-contracts (1.0.2)
  - Downloading facade/flare-client-php (1.10.0)
  - Downloading facade/ignition (2.17.7)
  - Downloading fakerphp/faker (v1.22.0)
  - Downloading fideloper/proxy (4.4.2)
  - Downloading fruitcake/php-cors (v1.2.0)
  - Downloading fruitcake/laravel-cors (v3.0.0)
  - Downloading guzzlehttp/promises (2.0.0)
  - Downloading symfony/yaml (v6.3.0)
  - Downloading laravel/sail (v1.22.0)
  - Downloading nikic/php-parser (v4.15.5)
  - Downloading psy/psysh (v0.11.18)
  - Downloading laravel/tinker (v2.8.1)
  - Downloading hamcrest/hamcrest-php (v2.0.1)
  - Downloading mockery/mockery (1.6.1)
  - Downloading filp/whoops (2.15.2)
  - Downloading nunomaduro/collision (v5.11.0)
  - Downloading sebastian/version (3.0.2)
  - Downloading sebastian/type (3.2.1)
  - Downloading sebastian/resource-operations (3.0.3)
  - Downloading sebastian/recursion-context (4.0.5)
  - Downloading sebastian/object-reflector (2.0.4)
  - Downloading sebastian/object-enumerator (4.0.4)
  - Downloading sebastian/global-state (5.0.5)
  - Downloading sebastian/exporter (4.0.5)
  - Downloading sebastian/environment (5.1.5)
  - Downloading sebastian/diff (4.0.5)
  - Downloading sebastian/comparator (4.0.8)
  - Downloading sebastian/code-unit (1.0.8)
  - Downloading sebastian/cli-parser (1.0.1)
  - Downloading phpunit/php-timer (5.0.3)
  - Downloading phpunit/php-text-template (2.0.4)
  - Downloading phpunit/php-invoker (3.1.1)
  - Downloading phpunit/php-file-iterator (3.0.6)
  - Downloading theseer/tokenizer (1.2.1)
  - Downloading sebastian/lines-of-code (1.0.3)
  - Downloading sebastian/complexity (2.0.2)
  - Downloading sebastian/code-unit-reverse-lookup (2.0.3)
  - Downloading phpunit/php-code-coverage (9.2.26)
  - Downloading phar-io/version (3.2.1)
  - Downloading phar-io/manifest (2.0.3)
  - Downloading myclabs/deep-copy (1.11.1)
  - Downloading doctrine/instantiator (2.0.0)
  - Downloading phpunit/phpunit (9.6.8)
  - Downloading psr/http-message (1.1)
  - Downloading psr/http-factory (1.0.2)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-client (1.0.2)
  - Downloading guzzlehttp/psr7 (2.5.0)
  - Downloading guzzlehttp/guzzle (7.7.0)
  - Downloading firebase/php-jwt (v6.5.0)
  - Downloading shopify/shopify-api (v5.0.0)
  - Downloading squizlabs/php_codesniffer (3.7.2)
  - Installing brick/math (0.11.0): Extracting archive
  - Installing psr/log (2.0.0): Extracting archive
  - Installing psr/cache (3.0.0): Extracting archive
  - Installing doctrine/event-manager (2.0.0): Extracting archive
  - Installing doctrine/deprecations (v1.1.1): Extracting archive
  - Installing doctrine/cache (2.2.0): Extracting archive
  - Installing doctrine/dbal (3.6.3): Extracting archive
  - Installing doctrine/lexer (1.2.3): Extracting archive
  - Installing symfony/polyfill-ctype (v1.27.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing dragonmantank/cron-expression (v3.3.2): Extracting archive
  - Installing symfony/polyfill-php80 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive
  - Installing symfony/var-dumper (v5.4.24): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.27.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.27.0): Extracting archive
  - Installing symfony/string (v6.3.0): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing psr/container (1.1.2): Extracting archive
  - Installing symfony/service-contracts (v2.5.2): Extracting archive
  - Installing symfony/polyfill-php73 (v1.27.0): Extracting archive
  - Installing symfony/console (v5.4.24): Extracting archive
  - Installing monolog/monolog (2.9.1): Extracting archive
  - Installing voku/portable-ascii (1.6.1): Extracting archive
  - Installing phpoption/phpoption (1.9.1): Extracting archive
  - Installing graham-campbell/result-type (v1.1.1): Extracting archive
  - Installing vlucas/phpdotenv (v5.5.0): Extracting archive
  - Installing symfony/css-selector (v6.3.0): Extracting archive
  - Installing tijsverkoyen/css-to-inline-styles (2.2.6): Extracting archive
  - Installing symfony/routing (v5.4.22): Extracting archive
  - Installing symfony/process (v5.4.24): Extracting archive
  - Installing symfony/polyfill-php72 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-intl-idn (v1.27.0): Extracting archive
  - Installing symfony/mime (v5.4.23): Extracting archive
  - Installing symfony/http-foundation (v5.4.24): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.3.0): Extracting archive
  - Installing symfony/event-dispatcher (v6.3.0): Extracting archive
  - Installing symfony/error-handler (v5.4.24): Extracting archive
  - Installing symfony/http-kernel (v5.4.24): Extracting archive
  - Installing symfony/finder (v5.4.21): Extracting archive
  - Installing symfony/polyfill-iconv (v1.27.0): Extracting archive
  - Installing egulias/email-validator (2.1.25): Extracting archive
  - Installing swiftmailer/swiftmailer (v6.3.0): Extracting archive
  - Installing ramsey/collection (2.0.0): Extracting archive
  - Installing ramsey/uuid (4.7.4): Extracting archive
  - Installing psr/simple-cache (1.0.1): Extracting archive
  - Installing opis/closure (3.6.3): Extracting archive
  - Installing symfony/translation-contracts (v3.3.0): Extracting archive
  - Installing symfony/translation (v6.3.0): Extracting archive
  - Installing nesbot/carbon (2.67.0): Extracting archive
  - Installing league/mime-type-detection (1.11.0): Extracting archive
  - Installing league/flysystem (1.1.10): Extracting archive
  - Installing nette/utils (v4.0.0): Extracting archive
  - Installing nette/schema (v1.2.3): Extracting archive
  - Installing dflydev/dot-access-data (v3.0.2): Extracting archive
  - Installing league/config (v1.2.0): Extracting archive
  - Installing league/commonmark (2.4.0): Extracting archive
  - Installing laravel/serializable-closure (v1.3.0): Extracting archive
  - Installing doctrine/inflector (2.0.6): Extracting archive
  - Installing laravel/framework (v8.83.27): Extracting archive
  - Installing facade/ignition-contracts (1.0.2): Extracting archive
  - Installing facade/flare-client-php (1.10.0): Extracting archive
  - Installing facade/ignition (2.17.7): Extracting archive
  - Installing fakerphp/faker (v1.22.0): Extracting archive
  - Installing fideloper/proxy (4.4.2): Extracting archive
  - Installing fruitcake/php-cors (v1.2.0): Extracting archive
  - Installing fruitcake/laravel-cors (v3.0.0): Extracting archive
  - Installing guzzlehttp/promises (2.0.0): Extracting archive
  - Installing symfony/yaml (v6.3.0): Extracting archive
  - Installing laravel/sail (v1.22.0): Extracting archive
  - Installing nikic/php-parser (v4.15.5): Extracting archive
  - Installing psy/psysh (v0.11.18): Extracting archive
  - Installing laravel/tinker (v2.8.1): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.6.1): Extracting archive
  - Installing filp/whoops (2.15.2): Extracting archive
  - Installing nunomaduro/collision (v5.11.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.2.1): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.5): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.5): Extracting archive
  - Installing sebastian/exporter (4.0.5): Extracting archive
  - Installing sebastian/environment (5.1.5): Extracting archive
  - Installing sebastian/diff (4.0.5): Extracting archive
  - Installing sebastian/comparator (4.0.8): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.26): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing doctrine/instantiator (2.0.0): Extracting archive
  - Installing phpunit/phpunit (9.6.8): Extracting archive
  - Installing psr/http-message (1.1): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-client (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.5.0): Extracting archive
  - Installing guzzlehttp/guzzle (7.7.0): Extracting archive
  - Installing firebase/php-jwt (v6.5.0): Extracting archive
  - Installing shopify/shopify-api (v5.0.0): Extracting archive
  - Installing squizlabs/php_codesniffer (3.7.2): Extracting archive
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
 
In Process.php line 146:
 
  The Process class relies on proc_open, which is not available on your PHP installation.
 
 
install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--download-only] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [--audit] [--audit-format AUDIT-FORMAT] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [&lt;packages>...]
 
 

18、参考:Jenkins 构建镜像时,报错:The Process class relies on proc_open, which is not available on your PHP installation.的解决 。 编辑 /usr/local/php/etc/php.ini,在 disable_functions 中删除 proc_open、proc_get_status


disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen

[root@iZ23wv7v5ggZ php]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
81 packages you are using are looking for funding.
Use the `composer fund` command to find out more!



19、执行数据库迁移时失败,报错:SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# php artisan migrate
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes

Migration table created successfully.
Migrating: 2019_08_19_000000_create_failed_jobs_table

   Illuminate\Database\QueryException

  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `failed_jobs` add unique `failed_jobs_uuid_unique`(`uuid`))

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

      +9 vendor frames
  10  database/migrations/2019_08_19_000000_create_failed_jobs_table.php:24
      Illuminate\Support\Facades\Facade::__callStatic()

      +22 vendor frames
  33  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()


20、参考:阿里云RDS的参数配置,启用Innodb_large_prefix 。编辑 config/database.php,修改 ‘engine’ => null, 为 ‘engine’ => ‘InnoDB’,。再次执行数据库迁移,报错。SQLSTATE[42S01]: Base table or view already exists: 1050 Table ‘failed_jobs’ already exists。在数据库中删除掉所有表后,重新执行迁移。不再报错。


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# php artisan migrate
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes

Migration table created successfully.
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (13.03ms)
Migrating: 2021_05_03_050717_create_sessions_table
Migrated:  2021_05_03_050717_create_sessions_table (11.62ms)
Migrating: 2021_05_05_071311_add_scope_expires_access_token_to_sessions
Migrated:  2021_05_05_071311_add_scope_expires_access_token_to_sessions (9.72ms)
Migrating: 2021_05_11_151158_add_online_access_info_to_sessions
Migrated:  2021_05_11_151158_add_online_access_info_to_sessions (9.32ms)
Migrating: 2021_05_17_152611_change_sessions_user_id_type
Migrated:  2021_05_17_152611_change_sessions_user_id_type (48.28ms)



21、构建后端。


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# composer build
> composer build-frontend-links
> ln -sf ../frontend/dist/assets public/assets &amp;&amp; ln -sf ../frontend/dist/index.html public/index.html



22、访问应用首页:https://learn-php-app-0605-prod.shuijingwanwq.com/ 。响应 403。如图6

访问应用首页:https://learn-php-app-0605-prod.shuijingwanwq.com/ 。响应 403

图6

23、查看虚拟主机配置文件


[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# cat /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.shuijingwanwq.com.conf
server {
  listen 80;
  listen [::]:80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.crt;
  ssl_certificate_key /usr/local/nginx/conf/ssl/learn-php-app-0605-prod.shuijingwanwq.com.key;
  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
  ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;
  ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256;
  ssl_conf_command Options PrioritizeChaCha;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache shared:SSL:10m;
  ssl_buffer_size 2k;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name learn-php-app-0605-prod.shuijingwanwq.com;
  access_log /data/wwwlogs/learn-php-app-0605-prod.shuijingwanwq.com_nginx.log combined;
  index index.html index.htm index.php;
  root /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }

  include /usr/local/nginx/conf/rewrite/laravel.conf;
  #error_page 404 /404.html;
  #error_page 502 /502.html;
  location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {
    valid_referers none blocked *.shuijingwanwq.com learn-php-app-0605-prod.shuijingwanwq.com;
    if ($invalid_referer) {
        return 403;
    }
  }
  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
    deny all;
  }
  location /.well-known {
    allow all;
  }
}
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# ^C
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]# cat /usr/local/nginx/conf/rewrite/laravel.conf
location / {
  try_files $uri $uri/ /index.php?$query_string;
}
[root@iZ23wv7v5ggZ learn-php-app-0605-prod.shuijingwanwq.com]#



24、参考模板中的 nginx.conf,其内容如下


user www-data www-data;

events {
    worker_connections 1024;
}

http {
    index index.php index.html;

    upstream php {
        server 127.0.0.1:9000;
    }

    server {
        include /etc/nginx/mime.types;
        include /etc/nginx/default.d/*.conf;

        listen PORT;
        server_name 0.0.0.0;
        root /app/public;

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

        location ~ [^/]\.php(/|$) {
            include /etc/nginx/fastcgi_params;

            try_files $uri $uri/ /index.php?$uri;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

            fastcgi_pass   php;
            fastcgi_index  index.php;
        }
    }
}


25、编辑 /usr/local/nginx/conf/vhost/learn-php-app-0605-prod.shuijingwanwq.com.conf


  index index.php index.html;
  root /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com/public;


26、响应 500,开启 debug,编辑 .env。报错:TypeError
Shopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com/app/Lib/AuthRedirection.php on line 17 。不用理会,符合预期。如图7

报错:TypeErrorShopify\Utils::sanitizeShopDomain(): Argument #1 ($shop) must be of type string, null given, called in /data/wwwroot/learn-php-app-0605-prod.shuijingwanwq.com/app/Lib/AuthRedirection.php on line 17

图7


APP_ENV=local
APP_DEBUG=true


27、更新合作伙伴仪表板中的 URL。如图8

更新合作伙伴仪表板中的 URL

图8

28、在合作伙伴仪表板中,转到应用程序的概览页面。在“测试您的应用”部分中,单击“选择商店”,然后选择一个商店来测试应用。如图9

在合作伙伴仪表板中,转到应用程序的概览页面。在“测试您的应用”部分中,单击“选择商店”,然后选择一个商店来测试应用

图9

29、安装应用时,报错:ops, something went wrong. 。原因应该在于请求参数有误。如图10

安装应用时,报错:ops, something went wrong. 。原因应该在于请求参数有误

图10


client_id: not_defined
scope: not_defined
redirect_uri: https://not_defined/api/auth/callback
state: b27be356-0010-43ae-b3b8-90a337314c0c
grant_options[]: 


30、编辑 .env,参考 .env.testing


APP_NAME="Shopify PHP App 0605 Prod"
APP_ENV=production
APP_KEY=base64:tPbLjWcISYL3Z/HS+OQS2GXvMPb0A7GlvNv6iFwFG6A=
APP_DEBUG=false
APP_URL=https://learn-php-app-0605-prod.shuijingwanwq.com

SHOPIFY_API_KEY=c7f826670575f7ae069f7e56350465ef
SHOPIFY_API_SECRET=4de64aa8281e97055cf7698bbe56039e
SCOPES=write_products
HOST=learn-php-app-0605-prod.shuijingwanwq.com

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=**************
DB_PORT=3306
DB_DATABASE=learn_php_app_0605_prod
DB_USERNAME=learn_php_app_0605_prod
DB_PASSWORD=*********



31、不再报错。如图11

不再报错

图11

32、点击安装应用后,进入店铺后台,但是页面预览为空白。如图12

点击安装应用后,进入店铺后台,但是页面预览为空白

图12

33、重新构建前端与后端后,卸载应用。如图13

重新构建前端与后端后,卸载应用

图13

34、再次安装,刷新页面,页面不再空白,符合预期。如图14

再次安装,刷新页面,页面不再空白,符合预期

图14

]]>
https://www.shuijingwanwq.com/2023/07/13/7855/feed/ 1
在 阿里云中的 CentOS 7.7 中卸载 PHP 7.4,然后安装 PHP 8 https://www.shuijingwanwq.com/2023/07/10/7832/ https://www.shuijingwanwq.com/2023/07/10/7832/#comments Mon, 10 Jul 2023 01:57:37 +0000 https://www.shuijingwanwq.com/?p=7832 浏览量: 196 1、参考:基于阿里云的 ECS、RDS,将个人博客迁移升级至:Docker(基于预算考虑,最终未实现)、LNMP(CentOS 7.7、Nginx 1.16、MySQL 5.7、PHP 7.4)、HTTPS 的过程 ,之前的环境是基于 OneinStack 的自动安装。PHP 版本 7.4 已经不再符合 Shopify 应用的运行条件。需要升级至 8.1 版本,尽量与本地环境保持一致。如图1
PHP 版本 7.4 已经不再符合 Shopify 应用的运行条件。需要升级至 8.1 版本,尽量与本地环境保持一致

图1



[root@iZ23wv7v5ggZ ~]# php -v
PHP 7.4.0 (cli) (built: Dec  5 2019 11:56:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies





wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ php -v
PHP 8.1.18 (cli) (built: Apr 14 2023 04:39:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.18, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies


2、在阿里云中,将磁盘创建快照,避免操作过程中导致数据丢失。如图2
在阿里云中,将磁盘创建快照,避免操作过程中导致数据丢失

图2

3、配置 CentOS 7 yum 源,参考:《CentOS、Ubuntu、Debian依赖源配置》 。更新缓存时报错:File contains no section headers. Loaded plugins: fastestmirror
<pre class="wp-block-syntaxhighlighter-code">

[root@iZ23wv7v5ggZ ~]# cd /etc/yum.repos.d/
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 8
-rw-r--r-- 1 root root 2523 Jan 28  2022 CentOS-Base.repo
-rw-r--r-- 1 root root  664 Jan 28  2022 epel.repo
[root@iZ23wv7v5ggZ yum.repos.d]# rm -rf /etc/yum.repos.d/*.repo
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 0
[root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7221  100  7221    0     0   3763      0  0:00:01  0:00:01 --:--:--  3762
[root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7215  100  7215    0     0  11531      0 --:--:-- --:--:-- --:--:-- 11525
[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache
Loaded plugins: fastestmirror


File contains no section headers.
file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 1
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n'
[root@iZ23wv7v5ggZ yum.repos.d]# ls -l
total 16
-rw-r--r-- 1 root root 7221 Jun  6 14:32 CentOS-Base.repo
-rw-r--r-- 1 root root 7215 Jun  6 14:32 epel.repo
[root@iZ23wv7v5ggZ yum.repos.d]#


</pre>
4、查看文件 /etc/yum.repos.d/CentOS-Base.repo 的内容,其已经不再是正确的格式,下载失败了。阿里云的源已经不存在。如图3
查看文件 /etc/yum.repos.d/CentOS-Base.repo 的内容,其已经不再是正确的格式,下载失败了。阿里云的源已经不存在

图3

5、打开 https://mirrors.aliyun.com/repo/ ,确认源 Centos-7.repo 与 epel-7.repo 是可以下载的。决定手动编辑保存内容,然后更新缓存。报错:[Errno 14] HTTP Error 502 – Bad Gateway。如图4
打开 https://mirrors.aliyun.com/repo/ ,确认源 Centos-7.repo 与 epel-7.repo 是可以下载的。决定手动编辑保存内容,然后更新缓存。报错:[Errno 14] HTTP Error 502 - Bad Gateway

图4



[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
http://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyun.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyun.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyun.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
Metadata Cache Created



6、停止实例后,回滚云盘。如图5
停止实例后,回滚云盘

图5

7、更新缓存,仍然报错。


[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
http://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyun.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyun.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyun.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway
Trying other mirror.
Metadata Cache Created



8、参考:在阿里云的 ECS 中,CentOS 7 迁移(更换)至 Alibaba Cloud Linux 3 。打开网址:https://oneinstack.com/auto/ ,基于 OneinStack 的自动安装,选择了 LNMP,PHP 版本 8.1,复制安装命令,如图6
参考:在阿里云的 ECS 中,CentOS 7 迁移(更换)至 Alibaba Cloud Linux 3 https://www.shuijingwanwq.com/2023/07/06/7805/。打开网址:https://oneinstack.com/auto/ ,基于 OneinStack 的自动安装,选择了 LNMP,PHP 版本 8.1,复制安装命令

图6

9、启动 ECS 实例后,基于 PuTTY 进入 Alibaba Cloud Linux 服务器中,粘贴执行安装命令,然后一直卡在 –php_extensions fileinfo 处。按 Ctrl + C 中止掉安装过程。如图7
启动 ECS 实例后,基于 PuTTY 进入 Alibaba Cloud Linux 服务器中,粘贴执行安装命令,然后一直卡在 --php_extensions fileinfo 处。按 Ctrl + C 中止掉安装过程

图7



[root@iZ23wv7v5ggZ ~]# wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1 --php_option 11 --phpcache_option 1 --php_extensions imagick,fileinfo,imap,ldap,redis,mongodb --pureftpd  --redis


10、在安装命令中 PHP 扩展仅保留 imagick,redis,其他扩展后续按需安装。如果之前没有安装组件,后续补充安装,统一入口为 ./install.sh 。仍然一直卡在 –php_extensions fileinfo 处,确认 OneinStack 不支持 PHP 8.1 下的扩展 fileinfo 的安装。后续自行想办法安装此扩展。
<pre class="wp-block-syntaxhighlighter-code">

[root@iZ23wv7v5ggZ ~]# wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1 --php_option 11 --phpcache_option 1 --php_extensions imagick,redis --pureftpd  --redis
[root@iZ23wv7v5ggZ oneinstack]# ./install.sh

#######################################################################
#       OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+      #
#       For more information please visit https://oneinstack.com      #
#######################################################################

Please input SSH port(Default: 22):

Do you want to install Web server? [y/n]: n

Do you want to install Database? [y/n]: n

Do you want to install PHP? [y/n]: n

Do you want to install opcode cache of the PHP? [y/n]: n

Please select PHP extensions:
         0. Do not install
         1. Install zendguardloader(PHP<=5.6)
         2. Install ioncube
         3. Install sourceguardian(PHP<=7.2)
         4. Install imagick
         5. Install gmagick
         6. Install fileinfo
         7. Install imap
         8. Install ldap
         9. Install phalcon(PHP>=5.5)
        10. Install yaf(PHP>=7.0)
        11. Install redis
        12. Install memcached
        13. Install memcache
        14. Install mongodb
        15. Install swoole
        16. Install xdebug(PHP>=5.5)
Please input numbers:(Default '4 11 12' press Enter) 6


</pre>
12、查看 PHP 版本


[root@iZ23wv7v5ggZ ~]# php -v
PHP 8.1.19 (cli) (built: Jun  7 2023 11:34:24) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.19, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.19, Copyright (c), by Zend Technologies
[root@iZ23wv7v5ggZ ~]#



13、我的 ECS 内存为 1 GB 配置。编译 fileinfo 非常占用内存,这是导致无法编译的直接原因。最终决定提升 ECS 的配置,内存提升至 2 GB 。参考:在阿里云 ECS 中编译安装 PHP 扩展 fileinfo 时,一直卡住的解决(提升内存配置)]]>
https://www.shuijingwanwq.com/2023/07/10/7832/feed/ 2