当前位置:   article > 正文

检测服务器环境,实现快速部署。适用于CRMEB_PRO/多店

检测服务器环境,实现快速部署。适用于CRMEB_PRO/多店

运行效果如图:

241b4202311271112504772.png

最近被好多人问,本来运行的好好的,突然swoole就启动不了了。

本工具为爱发电,如果工具正好解决了您的需求。我会很开心

代码如下:

  1. """
  2. 本脚本为爱发电
  3. by:网前雨刮器
  4. """
  5. import subprocess
  6. import re
  7. def check_php_environment():
  8. def check_php_version():
  9. try:
  10. output = subprocess.check_output(['php', '-v'], stderr=subprocess.STDOUT)
  11. result = output.decode('utf-8')
  12. php_version_str = result.split('\n')[0]
  13. php_version = php_version_str.lower().split(' ')[1]
  14. if php_version.startswith('7.'):
  15. major_version, minor_version, patch_version = map(int, php_version.split('.'))
  16. if 7 <= major_version <= 7 and 1 <= minor_version <= 4:
  17. print(f"\033[32mPHP版本通过 (当前版本:{php_version})\033[0m")
  18. else:
  19. print(f"\033[31mPHP版本不通过 (当前版本:{php_version})\033[0m")
  20. else:
  21. print(f"\033[31mPHP版本不通过 (当前版本:{php_version})\033[0m")
  22. except subprocess.CalledProcessError as e:
  23. return None
  24. def check_php_extension(extension_name, expected_version=None):
  25. try:
  26. output = subprocess.check_output(['php', '-m'], stderr=subprocess.STDOUT)
  27. result = output.decode('utf-8')
  28. installed_extensions = result.split()
  29. if extension_name in installed_extensions:
  30. print(f"\033[32m{extension_name} 已安装\033[0m")
  31. if expected_version is not None:
  32. output = subprocess.check_output(['php', '--ri', extension_name], stderr=subprocess.STDOUT)
  33. result = output.decode('utf-8')
  34. match = re.search(r"Version => (.+)", result)
  35. if match:
  36. version = match.group(1).strip()
  37. print(f"\033[32m{extension_name} 版本号为 {version}\033[0m")
  38. if not re.match(expected_version.replace("*", r"\d+"), version):
  39. return None
  40. # print(f"报错:{extension_name} 扩展的版本号不满足要求")
  41. else:
  42. return None
  43. #print(f"无法获取 {extension_name} 扩展的版本信息")
  44. else:
  45. print(f"\033[31m{extension_name} 扩展未安装\033[0m")
  46. except subprocess.CalledProcessError as e:
  47. print(f"无法执行命令: {e.output}")
  48. def check_proc_open():
  49. try:
  50. output = subprocess.check_output(['php', '-i'], stderr=subprocess.STDOUT)
  51. result = output.decode('utf-8')
  52. if 'disable_functions' in result:
  53. disable_functions = result.split('disable_functions => ')[1].split(' =>')[0]
  54. if 'proc_open' in disable_functions:
  55. print("\033[31mproc_open 函数已被禁用\033[0m")
  56. else:
  57. print("\033[32mproc_open 函数未被禁用\033[0m")
  58. else:
  59. print("无法获取禁用函数列表")
  60. except subprocess.CalledProcessError as e:
  61. print(f"无法执行命令: {e.output}")
  62. def check_mysql_version():
  63. try:
  64. output = subprocess.check_output(['mysql', '-V'], stderr=subprocess.STDOUT)
  65. result = output.decode('utf-8')
  66. version_match = re.search(r"\d+\.\d+\.\d+", result)
  67. if version_match:
  68. mysql_version = version_match.group(0)
  69. if mysql_version.startswith('5.6.') or mysql_version.startswith('5.7.'):
  70. print(f"\033[32mMySQL 版本通过 (当前版本:{mysql_version})\033[0m")
  71. else:
  72. print(f"\033[31mMySQL 版本不通过 (当前版本:{mysql_version})\033[0m")
  73. else:
  74. print("\033[31m无法获取MySQL 版本号\033[0m")
  75. except subprocess.CalledProcessError as e:
  76. print(f"无法执行命令: {e.output}")
  77. def check_web_server():
  78. try:
  79. apache_process = subprocess.check_output(['ps', '-ef']).decode('utf-8')
  80. if 'apache2' in apache_process or 'httpd' in apache_process:
  81. print("\033[32m当前环境为 Apache (建议使用Nginx)\033[0m")
  82. return
  83. nginx_process = subprocess.check_output(['ps', '-ef']).decode('utf-8')
  84. if 'nginx' in nginx_process:
  85. print("\033[32m当前环境为 Nginx\033[0m")
  86. return
  87. print("\033[31m未检测到 Apache 或 Nginx 进程\033[0m")
  88. except subprocess.CalledProcessError as e:
  89. print(f"无法执行命令: {e.output}")
  90. print('')
  91. check_php_version()
  92. print('')
  93. check_proc_open()
  94. print('')
  95. check_php_extension('redis')
  96. print('')
  97. check_php_extension('fileinfo')
  98. print('')
  99. check_php_extension('swoole')
  100. print('')
  101. check_php_extension('swoole_loader', '3.0.\d+')
  102. print('')
  103. check_mysql_version()
  104. print('')
  105. check_web_server()
  106. print('')
  107. print('---------------------------------------------------------------------------------')
  108. print('')
  109. print("\033[33m注:请确定当前PHP命令行版本与你安装的PHP版本一致\033[0m")
  110. print("\033[33m注:如果你确定以上扩展已经安装并配置,请重启php、必要时重启服务器\033[0m")
  111. print("\033[33m本脚本为爱发电\033[0m")
  112. print("\033[33mby:网前雨刮器\033[0m")
  113. check_php_environment()

如果您不会使用python 不会配置python环境,可以使用我已经打包好的程序

使用方法如下:

将程序放在服务器下,直接“./文件名” 运行即可。

982b9202311271116187887.png

​​​​​​​ 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/549902
推荐阅读
相关标签
  

闽ICP备14008679号