Migration steps to AlmaLinux 9 for sites using PHP or Python¶
Introduction¶
For each webEOS site in CC7 (considered as main site) a preview site in AlmaLinux 9 will be available. For example, preview for https://mysite.web.cern.ch will be available at https://mysite-el9-preview.webtest.cern.ch.
The notable differences between the CC7 and EL9 environments are:
- PHP 5 is replaced by PHP 8:
- Check the differences between the versions in order to update your scripts accordingly (https://www.php.net/manual/en/migration70.php).
-
Python 2 is replaced by Python 3:
Note
Python 3 is available on CC7 as well. Therefore, any changes should be compatible with your main site as well.
How to troubleshoot¶
Testing preview site by updating existing scripts/config¶
- Select your website from
My sites
list: https://webservices-portal.web.cern.ch/my-sites -
Select the preview site
mysite-el9-preview.webtest.cern.ch
from the left menu.Open your browser, type the URL of the preview site and validate that it is working normally on EL9.
In case the preview site isn't working as expected when accessing it from your browser, we suggest to follow the steps below to adapt the content of your site:
-
Check the website's logs for troubleshooting.
Select
Type: Error
to view the error logs. -
Adapt your scripts and configuration.
Warning
Updating your scripts to test the preview site can impact the operation of the main site.
-
Once you make sure that the preview site is working as expected, select the main site
mysite.web.cern.ch
from the left menu. -
Change the
Version
field fromCERN Centos 7
toAlmaLinux 9
. -
Click the
Save button
.6. Access your main site and validate that it is working normally on EL9.
Note
In case of any issues, you can revert your main site back to CC7
by changing the Version
field to CERN Centos 7
.
If your preview site still have issues, we suggest to:
- Duplicate the site folder
www
towww-el9
- If your site needs to run on a specific PHP or Python version, more packages or any other configuration, you may consider moving to PaaS for more flexibility and source control with GitLab.
Testing preview site by duplicating the site folder¶
-
Duplicate the site folder
www
towww-el9
either from CERNBox or fromlxplus
.Share the above EOS location with the account
a:wwweos
(notice the prefixa
). See how to share personal EOS folder and project EOS folder. -
Point the preview site to the new EOS path where you duplicated the folder.
In this way, you'll make sure that your changes won't break the production site.
-
Adapt your scripts and configuration.
-
Once you make sure that the preview site is working as expected, choose your main site
. -
Change the
EOS Path
to the new EOS path where you duplicated the folder and theVersion
field fromCERN Centos 7
toAlmaLinux 9
. -
Click the
Save
button. -
After making sure you main site is working as expected, you can delete the old
www
folder.
Known issues and how to fix them¶
php_value in .htaccess¶
PHP settings (php_value
, php_admin_value
and php_flag
) currently set in .htaccess
will stop working and should be moved to a .user.ini
file instead: https://www.php.net/manual/en/configuration.file.per-user.php.
When accessing the preview of your website, you'll get a 500 - Internal server error
:
In the error logs of your website, the error will be similar to:
[test-dchatzic-webeos-php.web.cern.ch] [Fri Oct 20 13:52:23.461941 2023] [alert] [pid 128804] config.c(2045): [client 2a01:cb15:31a:4600:a882:dae8:9bc3:4eb4:0] /eos/user/d/dchatzic/tests/www/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
Example of an .htaccess
file with PHP settings:
php_value max_input_vars 9000
php_value max_execution_time 60
To fix the error, you need first to remove the lines with php_value
in the .htaccess
file and move them in a .user.ini
file:
max_input_vars=9000
max_execution_time=60
Shebang in Python 2 scripts¶
Python 2 scripts using #!/usr/bin/python
shebang will fail on execution.
When accessing the preview of your website, you'll get a 500 - Internal server error
:
In the error logs of your website, the error will be similar to:
[test-dchatzic-webeos-php.web.cern.ch] [Fri Oct 20 14:38:17.760238 2023] [error] [pid 130577] mod_cgid.c(1196): [client 2a01:cb15:31a:4600:a882:dae8:9bc3:4eb4:0] AH01241: error spawning CGI child: exec of '/eos/user/d/dchatzic/tests/www/cgi-bin/hello.py' failed (No such file or directory): /eos/user/d/dchatzic/tests/www/cgi-bin/hello.py
[test-dchatzic-webeos-php.web.cern.ch] [Fri Oct 20 14:38:17.761481 2023] [error] [pid 130577] util_script.c(501): [client 2a01:cb15:31a:4600:a882:dae8:9bc3:4eb4:0] End of script output before headers: hello.py
To fix this, you need to replace #!/usr/bin/python
with #!/usr/bin/python3
on the top of your python scripts.
create_function in PHP scripts¶
create_function
has been removed in PHP 8: https://www.php.net/manual/en/function.create-function.php.
Example of create_function
usage in a php script:
create_function('$a,$b', 'return filemtime($b) - filemtime($a);');
In the error logs of your website, the error will include:
Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to undefined function create_function()
To fix the error, you need to define an anonymous function instead:
function($a,$b) {return filemtime($b) - filemtime($a);};
Undefined arguments in PHP function with type declarations¶
Passing undefined arguments in a PHP function can cause TypeError
: https://www.php.net/manual/en/language.types.declarations.php.
An example is provided that the argument of the function is expected to be of type array
. However, we are giving the variable $b
as an input, which is undefined:
<?php
function f(array $a) {
// function implementation
}
f($b); // call the function
?>
In the error logs of your website, the error will include:
PHP Fatal error: Uncaught TypeError: f(): Argument #1 ($b) must be of type array, null given
To fix the error, we need to define the variables before passing them to the corresponding functions. In the example, this could be done by defining $b
to an empty array:
<?php
$b = []; // define $b
f($b);
PHP scripts in CGI-enabled folders¶
Example of .htaccess
file in CGI-enabled folder:
# *** This htaccess file has been generated automatically on November 24, 2020 ***
# Due to the end-of-life of SLC6 and Apache 2.2, web sites get migrated to a new infratructure running
# CC7 and Apache 2.4. Some settings previously managed in the old webservices site management interface
# have been moved to .htaccess files.
# See https://cern.service-now.com/service-portal/?id=outage&n=OTG0059516
<IfVersion >= 2.3>
# Enable CGI scripts execution in this folder in the new Apache 2.4 infrastructure.
# This folder was previously CGI-enabled using a setting in the old webservices site management interface.
Options +ExecCGI
SetHandler cgi-script
# The old infrastructure supported php scripts in CGI-enabled folders, preserve that behavior for migrated sites.
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
</IfVersion>
The above configuration should be simplified into:
Options +ExecCGI
SetHandler cgi-script
without special directives for PHP files since the current httpd configuration in EL9 supports the execution of PHP scripts in CGI-enabled folders.