Trying to include PHP 7 in the Discourse container

trying to update discourse but its failing on this command

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 is installed using internal NGINX.
So I am trying to update discourse which is 2 years old. from 3.2 to 3.4 i think.

So I ran below commands

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

YAML file looks like below, i have removed personal info:

# 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;}'

Can anyone help me fix it as my site is down now.

I was also thinking of doing

./launcher rebuild data

There is no nginx and no PHP installed on my server, this means its using internal nginx and internal PHP. So what do i do to fix it and update my discourse and data container?

Remove this line here.

1 Like

Thanks @Falco …Yes i have commented it and it works fine but
i need AMP pages to work using below script, so i need to update here so it works with latest PHP version? because if i comment AMP template then AMP pages will not work.

below is 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

what changes I need to do there?

if i do

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

i get below errors

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 <module>
    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#

I have tried to update the file to 8.2 php as below, but i still get errors

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

Getting below error

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 <module>
    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#

My original file was

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

Can you please give me correct way to install correct PHP version to not face this issue and i can rebuild successfully with AMP template?

Not really, as this was never supported by Discourse and is something completely custom.

PHP 7.4 went end-of-life almost three years ago so I suspect you might want to raise that version number to something along the lines of 8.3.

I suggest that you keep PHP and all the associated logic in a separate container and just proxy everything /amp to it.

3 Likes