Multiple PHP versions
Currently this role supports the version of PHP that comes with the distro, it would be nice to have the option to run multiple versions using the sury repo, see also the Debian guide for third party repos.
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Chris Croome changed milestone to %WSH Version 1.0
changed milestone to %WSH Version 1.0
- Author Owner
Note that
phpquery -V
can return a list:phpquery -V 7.3 7.2 5.6
- Chris Croome changed title from Debian and PHP versions to Multiple PHP versions
changed title from Debian and PHP versions to Multiple PHP versions
- Chris Croome changed the description
changed the description
- Chris Croome mentioned in issue munin-node#4
mentioned in issue munin-node#4
- Author Owner
A dictionary could be used for this, for example:
php_versions: 8.1: state: absent 8.0: state: absent 7.4: state: default sapi: cli: modules: apcu: state: enabled apcu_bc: state: enabled bcmath: state: enabled bz2: state: enabled calendar: state: enabled ctype: state: enabled curl: state: enabled dom: state: enabled exif: state: enabled ffi: state: enabled fileinfo: state: enabled ftp: state: enabled gd: state: enabled geoip: state: enabled gettext: state: enabled gmp: state: enabled iconv: state: enabled imagick: state: enabled imap: state: enabled intl: state: enabled json: state: enabled ldap: state: enabled mbstring: state: enabled mysqli: state: enabled mysqlnd: state: enabled opcache: state: enabled pdo: state: enabled pdo_mysql: state: enabled pdo_sqlite: state: enabled phar: state: enabled posix: state: enabled readline: state: enabled shmop: state: enabled simplexml: state: enabled soap: state: enabled sockets: state: enabled sqlite3: state: enabled sysvmsg: state: enabled sysvsem: state: enabled sysvshm: state: enabled tokenizer: state: enabled uploadprogress: state: enabled xml: state: enabled xmlreader: state: enabled xmlrpc: state: enabled xmlwriter: state: enabled xsl: state: enabled zip: state: enabled fpm: settings: allow_url_include: false date_timezone: Europe/London max_execution_time: 600 max_file_uploads: 60 max_input_nesting_level: 512 max_input_time: 600 max_input_vars: 100000 memory_limit: 512M mysqli_allow_local_infile: false opcache_enable: true opcache_interned_strings_buffer: 8 opcache_max_accelerated_files: 100000 opcache_memory_consumption: 1024 opcache_revalidate_freq: 2 opcache_use_cwd: true opcache_validate_permission: true opcache_validate_root: true opcache_validate_timestamps: 1 post_max_size: 512M session_save_path: "${TMPDIR}" short_open_tag: false upload_max_filesize: 512M pools: www: state: present user: www-data group: www-data pm: dynamic listen: /run/php/php8.1-fpm.sock pm_max_children: 10 pm_process_idle_timeout: 10s pm_start_servers: 2 pm_min_spare_servers: 1 pm_max_spare_servers: 3 pm_max_requests: 1000 disable_functions: - chgrp - chown - dl - exec - passthru - pcntl_alarm - pcntl_fork - pcntl_waitpid - pcntl_wait - pcntl_wifexited - pcntl_wifstopped - pcntl_wifsignaled - pcntl_wifcontinued - pcntl_wexitstatus - pcntl_wtermsig - pcntl_wstopsig - pcntl_signal - pcntl_signal_get_handler - pcntl_signal_dispatch - pcntl_get_last_error - pcntl_strerror - pcntl_sigprocmask - pcntl_sigwaitinfo - pcntl_sigtimedwait - pcntl_exec - pcntl_getpriority - pcntl_setpriority - pcntl_async_signals - pcntl_unshare - popen - posix_kill - posix_mkfifo - posix_setpgid - posix_setsid - posix_setuid - show_source - socket_create - symlink - system - system_exec modules: apcu: state: enabled apcu_bc: state: enabled bcmath: state: enabled bz2: state: enabled calendar: state: enabled ctype: state: enabled curl: state: enabled dom: state: enabled exif: state: enabled ffi: state: enabled fileinfo: state: enabled ftp: state: enabled gd: state: enabled geoip: state: enabled gettext: state: enabled gmp: state: enabled iconv: state: enabled imagick: state: enabled imap: state: enabled intl: state: enabled json: state: enabled ldap: state: enabled mbstring: state: enabled mysqli: state: enabled mysqlnd: state: enabled opcache: state: enabled pdo: state: enabled pdo_mysql: state: enabled pdo_sqlite: state: enabled phar: state: enabled posix: state: enabled readline: state: enabled shmop: state: enabled simplexml: state: enabled soap: state: enabled sockets: state: enabled sqlite3: state: enabled sysvmsg: state: enabled sysvsem: state: enabled sysvshm: state: enabled tokenizer: state: enabled uploadprogress: state: enabled xml: state: enabled xmlreader: state: enabled xmlrpc: state: enabled xmlwriter: state: enabled xsl: state: enabled zip: state: enabled
The
phpenmod
andphpdismod
Bash scripts can be use to enable and disable modules.Perhaps the packages to be installed / uninstalled can be derived from the modules dictionaries, or perhaps everything should be installed and then things disabled on a per module basis?
- Chris Croome mentioned in issue users#64
mentioned in issue users#64
- Chris Croome mentioned in commit 1c1527a8
mentioned in commit 1c1527a8
- Author Owner
Ansible
local_facts
are generated usingphpquery
, see this template and this results in aansible_local.phpquery
dictionary like this:ansible_facts: ansible_local: phpquery: state: present versions: '7.4': mods_available: - apcu - apcu_bc - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gd - geoip - gettext - gmp - iconv - imagick - imap - intl - json - ldap - mbstring - mysqli - mysqlnd - opcache - pdo - pdo_mysql - pdo_sqlite - phar - posix - readline - shmop - simplexml - soap - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlrpc - xmlwriter - xsl - zip sapis: cli: mods_enabled: - apcu - apcu_bc - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gd - geoip - gettext - gmp - iconv - imagick - imap - intl - json - ldap - mbstring - mysqli - mysqlnd - opcache - pdo - pdo_mysql - pdo_sqlite - phar - posix - readline - shmop - simplexml - soap - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlrpc - xmlwriter - xsl - zip state: present fpm: mods_enabled: - apcu - apcu_bc - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gd - geoip - gettext - gmp - iconv - imagick - imap - intl - json - ldap - mbstring - mysqli - mysqlnd - opcache - pdo - pdo_mysql - pdo_sqlite - phar - posix - readline - shmop - simplexml - soap - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlrpc - xmlwriter - xsl - zip state: present state: present '8.0': mods_available: - apcu - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gettext - iconv - imap - intl - ldap - opcache - pdo - pdo_sqlite - phar - posix - readline - shmop - simplexml - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlwriter - xsl sapis: cli: mods_enabled: - apcu - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gettext - iconv - imap - intl - ldap - opcache - pdo - pdo_sqlite - phar - posix - readline - shmop - simplexml - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlwriter - xsl state: present fpm: mods_enabled: - apcu - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gettext - iconv - imap - intl - ldap - opcache - pdo - pdo_sqlite - phar - posix - readline - shmop - simplexml - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlwriter - xsl state: present state: present '8.1': mods_available: - apcu - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gettext - iconv - imap - intl - ldap - mbstring - opcache - pdo - pdo_sqlite - phar - posix - readline - shmop - simplexml - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlwriter - xsl sapis: cli: mods_enabled: - apcu - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gettext - iconv - imap - intl - ldap - mbstring - opcache - pdo - pdo_sqlite - phar - posix - readline - shmop - simplexml - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlwriter - xsl state: present fpm: mods_enabled: - apcu - bcmath - bz2 - calendar - ctype - curl - dom - exif - ffi - fileinfo - ftp - gettext - iconv - imap - intl - ldap - mbstring - opcache - pdo - pdo_sqlite - phar - posix - readline - shmop - simplexml - sockets - sqlite3 - sysvmsg - sysvsem - sysvshm - tokenizer - uploadprogress - xml - xmlreader - xmlwriter - xsl state: present state: present
References:
- https://wiki.debian.org/DebianRepository/UseThirdParty
- https://packages.sury.org/php/README.txt
- https://github.com/oerdnj/deb.sury.org/wiki/Managing-Multiple-Versions
- https://github.com/oerdnj/deb.sury.org/wiki/Frequently-Asked-Questions#why-are-some-packages-named-phpxy--and-some-php-
- https://docs.ansible.com/ansible/latest/collections/community/general/alternatives_module.html
Edited by Chris Croome - Chris Croome mentioned in commit d3015ae3
mentioned in commit d3015ae3
- Chris Croome mentioned in commit 4f9cfdb6
mentioned in commit 4f9cfdb6
- Chris Croome mentioned in commit dee91b0c
mentioned in commit dee91b0c
- Chris Croome mentioned in commit ba921a06
mentioned in commit ba921a06
- Author Owner
The role will need to set these alternatives:
update-alternatives --get-selections | grep -e "php" -e "phar" phar auto /usr/bin/phar8.1 phar.phar auto /usr/bin/phar.phar8.1 php auto /usr/bin/php8.1 php-fpm.sock auto /run/php/php8.1-fpm.sock
The defaults:
update-alternatives --query php | grep -e "^Alternative" -e "^Priority" Alternative: /usr/bin/php7.4 Priority: 74 Alternative: /usr/bin/php8.0 Priority: 80 Alternative: /usr/bin/php8.1 Priority: 81 update-alternatives --query phar | grep -e "^Alternative" -e "^Priority" Alternative: /usr/bin/phar7.4 Priority: 74 Alternative: /usr/bin/phar8.0 Priority: 80 Alternative: /usr/bin/phar8.1 Priority: 81 update-alternatives --query phar.phar | grep -e "^Alternative" -e "^Priority" Alternative: /usr/bin/phar.phar7.4 Priority: 74 Alternative: /usr/bin/phar.phar8.0 Priority: 80 Alternative: /usr/bin/phar.phar8.1 Priority: 81 update-alternatives --query php-fpm.sock | grep -e "^Alternative" -e "^Priority" Alternative: /run/php/php7.4-fpm.sock Priority: 74 Alternative: /run/php/php8.0-fpm.sock Priority: 80 Alternative: /run/php/php8.1-fpm.sock Priority: 81
A
facts.d
script could report the status in JSON, that for example could look like this YAML:ansible_facts: ansible_local: php_alternatives: php: state: present alternatives: '8.1': 81 '8.0': 80 '7.4': 74 phar: state: present alternatives: '8.1': 81 '8.0': 80 '7.4': 74 'phar.phar': state: present alternatives: '8.1': 81 '8.0': 80 '7.4': 74 'php-fpm.sock': state: present alternatives: '8.1': 81 '8.0': 80 '7.4': 74
And the alternatives could be specified like this:
php_alternatives: cli: '8.1': priority: 81 '8.0': priority: 74 '7.4': priority: 74 fpm: '8.1': priority: 81 '8.0': priority: 74 '7.4': priority: 74
Edited by Chris Croome - Author Owner
Additional alternatives need to be set:
It's important to note that there are four important PHP commands you should update if changing the default versions. These include php, php-config, phpdbg and phpize. So, to fully migrate to PHP 7.0, execute the following:
sudo update-alternatives --set php /usr/bin/php7.0 sudo update-alternatives --set php-config /usr/bin/php-config7.0 sudo update-alternatives --set phpdbg /usr/bin/phpdbg7.0 sudo update-alternatives --set phpize /usr/bin/phpize7.0
- Author Owner
PHP configuration is in
.ini
format so can be read as JSON:cat /etc/php/8.1/fpm/php.ini | jc --ini -p
- Author Owner
Done
- Chris Croome closed
closed