Actions

User

Gold/PHP 8 Scratchpad/Add PHP8

From Mahara Wiki

< User:Gold‎ | PHP 8 Scratchpad
Revision as of 14:13, 16 May 2022 by Gold (talk | contribs)

Check available versions

[email protected]:~/$ apt-cache search php | sort | grep fpm
php7.4-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) (default)

If there are no php 8 options we need to add the repo and check again.

[email protected]:~/$ sudo add-apt-repository ppa:ondrej/php

You will likely be challenged to install ppa:ondrej/apache2. We are not using mod-php so there is no need to do that.

To check php8 is available rerun the apt-cache call above. You should see many more options.

Install PHP 7.4 and 8.1

Testing on PHP 7.4 and PHP 8.1 so install the related supporting packages that Mahara needs. There is no php8.1-json package. This is part of php8.1-common now.

[email protected]:~/$ sudo apt install \
  php7.4-cli php7.4-common php7.4-curl php7.4-gd \
  php7.4-json php7.4-ldap php7.4-mbstring php7.4-pgsql  \
  php7.4-xml php7.4-xmlrpc php7.4-zip \
  php8.1-cli php8.1-common php8.1-curl php8.1-gd \
  php8.1-ldap php8.1-mbstring php8.1-pgsql php8.1-xml \
  php8.1-xmlrpc php8.1-zip

Set up Apache

I'm configuring 2 sites. One for PHP 7.4 and one for PHP 8.1. At this point I'm not supporting PHP 7.2 and 8.0 is not the default in Ubuntu 22.04 which is our target platform.

I have updated my local /etc/hosts file and added entries for https://php74.mahara.local/ and https://php81.mahara.local/. While I'm ignoring 7.2 and 8.0 I'm including the minor version for future-proofing. Just in case.

Next the following is added as mahara-php8.conf and a sudo a2ensite mahara-php8 && sudo systemctl reload apache2 to enable it.


/etc/apache2/sites-available/mahara-php8.conf

<VirtualHost *:80>
  ServerName php81.mahara.local
  DocumentRoot /home/gold/Mahara/php8/htdocs
 
  <Directory /home/gold/Mahara/codereview>
    Options Indexes FollowSymLinks MultiViews
    Require all granted
  </Directory>
 
  ErrorLog /var/log/apache2/error.log
  LogLevel debug
 
  CustomLog /var/log/apache2/access.log combined
  DirectoryIndex index.php index.html
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName php81.mahara.local
        DocumentRoot /home/gold/Mahara/php8/htdocs
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key

        <FilesMatch \.php$>
            SSLOptions +StdEnvVars
            SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
        </FilesMatch>
        <Directory /home/gold/Mahara/php8>
            SSLOptions +StdEnvVars
            DirectoryIndex index.php
            Options Indexes FollowSymLinks MultiViews
            Require all granted
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel info
 
        CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
</IfModule>

<VirtualHost *:80>
  ServerName php74.mahara.local
  DocumentRoot /home/gold/Mahara/php8/htdocs
 
  <Directory /home/gold/Mahara/codereview>
    Options Indexes FollowSymLinks MultiViews
    Require all granted
  </Directory>
 
  ErrorLog /var/log/apache2/error.log
  LogLevel debug
 
  CustomLog /var/log/apache2/access.log combined
  DirectoryIndex index.php index.html
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName php74.mahara.local
        DocumentRoot /home/gold/Mahara/php8/htdocs
        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key

        <FilesMatch \.php$>
            SSLOptions +StdEnvVars
            SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
        </FilesMatch>
        <Directory /home/gold/Mahara/php8>
            SSLOptions +StdEnvVars
            DirectoryIndex index.php
            Options Indexes FollowSymLinks MultiViews
            Require all granted
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel info
 
        CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
</IfModule>