尝试在 Discourse 容器中集成 PHP 7

正在尝试更新 discourse,但在以下命令上失败:

I, [2024-10-01T23:08:46.462452 #1]  INFO -- : > apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring
E: Package 'php7.4' has no installation candidate
E: Unable to locate package php7.4-curl
E: Couldn't find any package by glob 'php7.4-curl'
E: Couldn't find any package by regex 'php7.4-curl'
E: Package 'php7.4-fpm' has no installation candidate
E: Unable to locate package php7.4-mbstring
E: Couldn't find any package by glob 'php7.4-mbstring'
E: Couldn't find any package by regex 'php7.4-mbstring'
I, [2024-10-01T23:08:47.335246 #1]  INFO -- : Reading package lists...
Building dependency tree...
Reading state information...
Package php7.4 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php7.4-fpm is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source


FAILED
--------------------
Pups::ExecError: apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring failed with return #<Process::Status: pid 2912 exit 100>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in spawn'
exec failed with the params "apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring"
bootstrap failed with exit code 100
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
d87ce61f0dbfc527ede7d3c09e222eff42934608174066401b2317d05193786b
root@htd-9-feb-22-live:/var/discourse#

Discourse 使用内部 NGINX 进行安装。
所以我正在尝试将 Discourse 从 3.2 更新到 3.4(我认为是这样),运行了以下命令:

 1465  cd /var/discourse
 1466  git pull
 1467  ./launcher bootstrap web_only && ./launcher destroy web_only && ./launcher start web_only

YAML 文件看起来像这样,我已删除个人信息:

# IMPORTANT: SET A SECRET PASSWORD in Postgres for the Discourse User
# TODO: change SOME_SECRET in this template

templates:
  - "templates/web.template.yml"
    #- "templates/web.ratelimited.template.yml"
  - "shared/web-only/amp/web.amp.template.yml"
    #- "shared/web_only/amp/templates/web.amp.template.yml"
  ## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  - "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80" # http
  - "443:443" # https

# Use 'links' key to link containers together, aka use Docker --link flag.
links:
  - link:
      name: data
      alias: data

# any extra arguments for Docker?
# docker_args:

params:
  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed
  env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  #EMBER_CLI_PROD_ASSETS: 1

  # DISCOURSE_DEFAULT_LOCALE: en
  #Global rate limits disabling rate limits to let SEO fix penalty crawling to get rid of 429 too many req error
  DISCOURSE_MAX_REQS_PER_IP_MODE: none

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  UNICORN_WORKERS: 32

  ## TODO: The domain name this Discourse instance will respond to
  #DISCOURSE_HOSTNAME: hidden
  DISCOURSE_HOSTNAME:hidden

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: "hidden"

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: hidden
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: hidden
  DISCOURSE_SMTP_PASSWORD: "hidden"
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: hidden
  DISCOURSE_NOTIFICATION_EMAIL: hidden

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  LETSENCRYPT_ACCOUNT_EMAIL: hidden
  ## TODO: configure connectivity to the databases
  #ljlsdfj;sdfj;lkdsfj
  DISCOURSE_DB_SOCKET: ""
  #DISCOURSE_DB_USERNAME: hidden
  DISCOURSE_DB_PASSWORD: hidden
  DISCOURSE_DB_HOST: data
  DISCOURSE_REDIS_HOST: data

  ## The http or https CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details


  ## The maxmind geolocation IP address key for IP address lookup
  ## see https://meta.discourse.org/t/-/137387/23 for details


volumes:
  - volume:
      host: /var/discourse/shared/web-only
      guest: /shared
  - volume:
      host: /var/discourse/shared/web-only/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          #- git clone https://github.com/discourse/discourse-sitemap.git
          #- git clone https://github.com/discourse/discourse-math.git # custom plugin for math JAX support
          #- git clone https://github.com/discourse/discourse-solved.git # custom plugin for question and answers and choosing best answer
          #- git clone https://github.com/discourse/discourse-voting.git # custom plugin for voting on topics only
          #- git clone https://github.com/discourse/discourse-yearly-review.git # custom plugin for automatically posting a yearly topic of forum activity
          #- git clone https://github.com/discourse/discourse-user-notes.git # custom plugin to allow staff to add notes about a user
          #- git clone https://github.com/paviliondev/discourse-question-answer.git # custom non official plugin for SO style QnA voting on posts
          #- git clone https://github.com/discourse/discourse-adplugin.git # custom official plugin for ads
          #- git clone https://github.com/discourse/discourse-whos-online.git # custom plugin to see who is online
          #- git clone https://github.com/paviliondev/discourse-topic-previews.git # custom plugin for showing topics previews nicely
          #- git clone https://github.com/paviliondev/discourse-ratings.git # custom plugin to allow user rating on topics
          #- git clone https://github.com/discourse/discourse-cakeday.git # official plugin for birthdays and join date celebrations
          #- git clone https://github.com/discourse/discourse-saved-searches.git # official plugin for saved search notifications
          #- git clone https://github.com/paviliondev/discourse-follow.git # custom plugin to allow users to follow each other
          - git clone https://github.com/FaizanZahid/discourse-amp-htd-plugin.git # custom build AMP support for HTD
          #- git clone https://github.com/discourse/discourse-assign.git # custom for assigning topics to staff
          #- git clone https://github.com/paviliondev/x-discourse-tlp-thumbnail.git # custom plugin for showing thumbnails from CDN images
          #- git clone https://github.com/discourse/discourse-prometheus.git # custom plugin for slow speed monitoring
          #- git clone https://github.com/discourse/discourse-push-notifications.git # plugin for push notifications

## Remember, this is YAML syntax - you can only have one block with a name worker_conn was 3000
run:
  - exec: echo "Beginning of custom commands"
  - replace:
      filename: "/etc/nginx/nginx.conf"
      from: "worker_connections 768"
      to: "worker_connections 4000"
  - replace:
      filename: "/etc/nginx/nginx.conf"
      from: "worker_processes auto"
      to: "worker_processes 16"

  ## If you want to configure password login for root, uncomment and change:
  ## Use only one of the following lines:
  #- exec: /usr/sbin/usermod -p 'PASSWORD_HASH' root
  #- exec: /usr/sbin/usermod -p "$(mkpasswd -m sha-256 'RAW_PASSWORD')" root

  ## If you want to authorized additional users, uncomment and change:
  #- exec: ssh-import-id username
  #- exec: ssh-import-id anotherusername

  - exec: echo "End of custom commands"
  - exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'

有人能帮我解决这个问题吗,因为我的网站现在无法访问了。

我还在考虑运行:

./launcher rebuild data

我的服务器上没有安装 nginx 和 php,这意味着它使用的是内部 nginx 和内部 php。那么我该如何修复它并更新我的 discourse 和 data 容器?

删除此行。

谢谢 @Falco ..是的,我已经注释掉了它,它工作正常,但我需要 AMP 页面使用下面的脚本工作,所以我需要在这里更新以使其与最新 PHP 版本兼容?因为如果我注释掉 AMP 模板,AMP 页面将无法工作。

以下是 web.amp.template.yml 文件:

hooks:
  after_ssl:
    # mkdir tmp/amp_cache/
  - exec: apt-get update
  - exec: apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring
  - exec: apt-get install -y php7.4-mbstring php7.4-xml
  - exec: mkdir -p /run/php

  - replace:
      filename: "/etc/nginx/conf.d/discourse.conf"
      from: /gzip_proxied any;/
      to: |
        gzip_proxied any;
        ## BEGIN inserted by web.amp.template.ymly
        location /ads.txt {
          alias /shared/amp/ads.txt;
        }
        if ($arg_amp) { rewrite ^ /amp/index.php?q=$uri last; }

        location ~ \\.php\\$ {
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $request_filename;
          fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }

        location @amp {
          rewrite ^/amp(.*) /amp/index.php?q=$1;
        }
        
        location /custom_widgets.php {
          include         fastcgi_params;
          root  /shared/amp/api/;
          fastcgi_pass    unix:/run/php/php7.4-fpm.sock;
          fastcgi_param   SCRIPT_FILENAME  /shared/amp/api/custom_widgets.php;
          fastcgi_param   QUERY_STRING     $query_string;
          fastcgi_param   REQUEST_METHOD   $request_method;
          fastcgi_param   CONTENT_TYPE     $content_type;
          fastcgi_param   CONTENT_LENGTH   $content_length;
        }
        
        
        location /amp {
          index index.php;
          try_files $uri $uri/ @amp;
          alias /shared/amp;
          location ~ \\.php$ {
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $request_filename;
          fastcgi_pass unix:/run/php/php7.4-fpm.sock;
          }
        }
        ## END inserted by web.amp.template.ymly

  - file:
     path: /etc/service/phpfpm/run
     chmod: "+x"
     contents: |
        #!/bin/sh
        exec 2>&1
        exec /usr/sbin/php-fpm7.4 --nodaemonize

  - file:
     path: /etc/runit/3.d/01-phpfpm
     chmod: "+x"
     contents: |
       #!/bin/bash
       sv stop phpfpm
```\n
我需要在那里做哪些更改?

如果我这样做:


hooks:
after_ssl:
# mkdir tmp/amp_cache/

  • exec: apt-get update
    #- exec: apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring
  • exec: apt-get install -y php8.1-mbstring php8.1-xml
    #- exec: apt-get install -y php7.4-mbstring php7.4-xml
    #- exec: apt-get install -y php8.1-xml
  • exec: mkdir -p /run/php

我会收到以下错误:


nvoke-rc.d: policy-rc.d denied execution of reload.
start-stop-daemon: unable to stat /usr/libexec/polkitd (No such file or directory)
Setting up packagekit (1.2.6-5) …
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of force-reload.
Failed to open connection to “system” message bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
Created symlink /etc/systemd/user/sockets.target.wants/pk-debconf-helper.socket → /usr/lib/systemd/user/pk-debconf-helper.socket.
Setting up packagekit-tools (1.2.6-5) …
Setting up software-properties-common (0.99.30-4.1~deb12u1) …
Processing triggers for dbus (1.14.10-1~deb12u1) …

I, [2024-10-02T01:05:32.803478 #1] INFO – : > add-apt-repository ppa:ondrej/php
Traceback (most recent call last):
File “/usr/bin/add-apt-repository”, line 362, in
sys.exit(0 if addaptrepo.main() else 1)
^^^^^^^^^^^^^^^^^
File “/usr/bin/add-apt-repository”, line 345, in main
shortcut = handler(source, **shortcut_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/shortcuts.py”, line 40, in shortcut_handler
return handler(shortcut, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 86, in init
if self.lpppa.publish_debug_symbols:
^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 126, in lpppa
self._lpppa = self.lpteam.getPPAByName(name=self.ppaname)
^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 113, in lpteam
self._lpteam = self.lp.people(self.teamname)
^^^^^^^^^^^^^^
AttributeError: ‘NoneType’ object has no attribute ‘people’
I, [2024-10-02T01:05:33.029140 #1] INFO – :

FAILED

Pups::ExecError: add-apt-repository ppa:ondrej/php failed with return #<Process::Status: pid 3887 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in spawn’
exec failed with the params “add-apt-repository ppa:ondrej/php”
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
b74ec42509c5559c7814ad3011f49969bd7aba5fd92d2ba16717584dae2f9e4f
root@htd-9-feb-22-live:/var/discourse#


我尝试将文件更新为 PHP 8.2,如下所示,但我仍然收到错误:


hooks:
after_ssl:
# mkdir tmp/amp_cache/

  • exec: apt-get update
    #- exec: apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring
    #- exec: apt-get install -y php7.4-mbstring php7.4-xml

Install software-properties-common to add repositories

  • exec: apt-get install -y software-properties-common

Add the Ondřej Surý PPA for the latest PHP versions

  • exec: add-apt-repository -y ppa:ondrej/php
  • exec: apt-get update

Install the latest version of PHP and the required extensions

  • exec: apt-get install -y php8.2 php8.2-curl php8.2-fpm php8.2-mbstring php8.2-xml

  • exec: mkdir -p /run/php

  • replace:
    filename: “/etc/nginx/conf.d/discourse.conf”
    from: /gzip_proxied any;/
    to: |
    gzip_proxied any;
    ## BEGIN inserted by web.amp.template.ymly
    location /ads.txt {
    alias /shared/amp/ads.txt;
    }
    if ($arg_amp) { rewrite ^ /amp/index.php?q=$uri last; }

    location ~ \\.php\\$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      #fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    
    }
    
    location @amp {
      rewrite ^/amp(.*) /amp/index.php?q=$1;
    }
    
    location /custom_widgets.php {
      include         fastcgi_params;
      root  /shared/amp/api/;
      #fastcgi_pass    unix:/run/php/php7.4-fpm.sock;
      fastcgi_pass    unix:/run/php/php8.2-fpm.sock;
      fastcgi_param   SCRIPT_FILENAME  /shared/amp/api/custom_widgets.php;
      fastcgi_param   QUERY_STRING     $query_string;
      fastcgi_param   REQUEST_METHOD   $request_method;
      fastcgi_param   CONTENT_TYPE     $content_type;
      fastcgi_param   CONTENT_LENGTH   $content_length;
    }
    
    
    location /amp {
      index index.php;
      try_files $uri $uri/ @amp;
      alias /shared/amp;
      location ~ \\.php$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      #fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    
      }
    }
    ## END inserted by web.amp.template.ymly
    
  • file:
    path: /etc/service/phpfpm/run
    chmod: “+x”
    contents: |
    #!/bin/sh
    exec 2>&1
    #exec /usr/sbin/php-fpm7.4 --nodaemonize
    exec /usr/sbin/php-fpm8.2 --nodaemonize

  • file:
    path: /etc/runit/3.d/01-phpfpm
    chmod: “+x”
    contents: |
    #!/bin/bash
    sv stop phpfpm

出现以下错误:


Setting up packagekit (1.2.6-5) …
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of force-reload.
Failed to open connection to “system” message bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
Created symlink /etc/systemd/user/sockets.target.wants/pk-debconf-helper.socket → /usr/lib/systemd/user/pk-debconf-helper.socket.
Setting up packagekit-tools (1.2.6-5) …
Setting up software-properties-common (0.99.30-4.1~deb12u1) …
Processing triggers for dbus (1.14.10-1~deb12u1) …

I, [2024-10-02T01:32:10.341970 #1] INFO – : > add-apt-repository -y ppa:ondrej/php
Traceback (most recent call last):
File “/usr/bin/add-apt-repository”, line 362, in
sys.exit(0 if addaptrepo.main() else 1)
^^^^^^^^^^^^^^^^^
File “/usr/bin/add-apt-repository”, line 345, in main
shortcut = handler(source, **shortcut_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/shortcuts.py”, line 40, in shortcut_handler
return handler(shortcut, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 86, in init
if self.lpppa.publish_debug_symbols:
^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 126, in lpppa
self._lpppa = self.lpteam.getPPAByName(name=self.ppaname)
^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/softwareproperties/ppa.py”, line 113, in lpteam
self._lpteam = self.lp.people(self.teamname)
^^^^^^^^^^^^^^
AttributeError: ‘NoneType’ object has no attribute ‘people’
I, [2024-10-02T01:32:10.554558 #1] INFO – :

FAILED

Pups::ExecError: add-apt-repository -y ppa:ondrej/php failed with return #<Process::Status: pid 3885 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn’
exec failed with the params “add-apt-repository -y ppa:ondrej/php”
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
8ec2386561b45752c20182c8f592036fa0921f1e81c3bd17b50c9ca2660a2354
root@htd-9-feb-22-live:/var/discourse#


我的原始文件是:

hooks:
after_ssl:
# mkdir tmp/amp_cache/

  • exec: apt-get update

  • exec: apt-get install -y php7.4 php7.4-curl php7.4-fpm php7.4-mbstring

  • exec: apt-get install -y php7.4-mbstring php7.4-xml

  • exec: mkdir -p /run/php

  • replace:
    filename: “/etc/nginx/conf.d/discourse.conf”
    from: /gzip_proxied any;/
    to: |
    gzip_proxied any;
    ## BEGIN inserted by web.amp.template.ymly
    location /ads.txt {
    alias /shared/amp/ads.txt;
    }
    if ($arg_amp) { rewrite ^ /amp/index.php?q=$uri last; }

    location ~ \\.php\\$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }
    
    location @amp {
      rewrite ^/amp(.*) /amp/index.php?q=$1;
    }
    
    location /custom_widgets.php {
      include         fastcgi_params;
      root  /shared/amp/api/;
      fastcgi_pass    unix:/run/php/php7.4-fpm.sock;
      fastcgi_param   SCRIPT_FILENAME  /shared/amp/api/custom_widgets.php;
      fastcgi_param   QUERY_STRING     $query_string;
      fastcgi_param   REQUEST_METHOD   $request_method;
      fastcgi_param   CONTENT_TYPE     $content_type;
      fastcgi_param   CONTENT_LENGTH   $content_length;
    }
    
    
    location /amp {
      index index.php;
      try_files $uri $uri/ @amp;
      alias /shared/amp;
      location ~ \\.php$ {
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
      fastcgi_pass unix:/run/php/php7.4-fpm.sock;
      }
    }
    ## END inserted by web.amp.template.ymly
    
  • file:
    path: /etc/service/phpfpm/run
    chmod: “+x”
    contents: |
    #!/bin/sh
    exec 2>&1
    exec /usr/sbin/php-fpm7.4 --nodaemonize

  • file:
    path: /etc/runit/3.d/01-phpfpm
    chmod: “+x”
    contents: |
    #!/bin/bash
    sv stop phpfpm


请问您能否提供正确的方法来安装正确的 PHP 版本,以避免遇到此问题,并使我能够使用 AMP 模板成功重建?

并非如此,因为 Discourse 从未支持过此功能,这是完全自定义的。

PHP 7.4 早已停止生命周期近三年,因此我怀疑您可能想将版本号提高到 8.3 左右。

我建议您将 PHP 和所有相关逻辑保留在单独的容器中,并将所有 /amp 请求代理到该容器。