geerlingguy / ansible-role-php-versions

Ansible Role - PHP Versions
https://galaxy.ansible.com/geerlingguy/php-versions/
MIT License
98 stars 73 forks source link

php-versions 5.6 still installs php 7.2 #14

Closed claystation closed 6 years ago

claystation commented 6 years ago

I was trying to install php 5.6 in a Vagrant debian/contrib-jessie64 machine. I set the variable to 5.6 in the defaults/main.yml in the php-versions role. This sets all the correct variables. But when install with the role php i still got php 7.2. I did some debugging (ansible -v) and found this:

TASK [geerlingguy.php : Ensure PHP packages are installed.] **** changed: [default] => (item=[u'php5.6', u'php5.6-apcu', u'php5.6-cli', u'php5.6-common', u'php5.6-curl', u'php5.6-dev', u'php5.6-fpm', u'php5.6-gd', u'php5.6-imap', u'php5.6-json', u'php5.6-mbstring', u'php5.6-mcrypt', u'php5.6-opcache', u'php5.6-sqlite3', u'php5.6-xml', u'php5.6-yaml']) => {"cache_update_time": 1514993379, "cache_updated": false, "changed": true, "item": ["php5.6", "php5.6-apcu", "php5.6-cli", "php5.6-common", "php5.6-curl", "php5.6-dev", "php5.6-fpm", "php5.6-gd", "php5.6-imap", "php5.6-json", "php5.6-mbstring", "php5.6-mcrypt", "php5.6-opcache", "php5.6-sqlite3", "php5.6-xml", "php5.6-yaml"], "stderr": "Reading changelogs...\n\rExtracting templates from packages: 32%\rExtracting templates from packages: 64%\rExtracting templates from packages: 96%\rExtracting templates from packages: 100%\n", "stderr_lines": ["Reading changelogs...", "", "Extracting templates from packages: 32%", "Extracting templates from packages: 64%", "Extracting templates from packages: 96%", "Extracting templates from packages: 100%"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following extra packages will be installed:\n autoconf automake autopoint autotools-dev build-essential debhelper dh-php\n dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-4.9 gettext\n intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl\n libalgorithm-merge-perl libapparmor1 libargon2-0 libasprintf-dev\n libc-client2007e libc-dev-bin libc6-dev libcroco3 libcurl3 libdpkg-perl\n libfakeroot libfile-fcntllock-perl libfontconfig1 libgd3 libgettextpo-dev\n libgettextpo0 libglib2.0-0 libglib2.0-data liblist-moreutils-perl\n libltdl-dev libltdl7 libmail-sendmail-perl libmcrypt4 libpcre16-3 libpcre3\n libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium18 libssl-dev libssl-doc\n libssl1.0.2 libstdc++-4.9-dev libsys-hostname-long-perl libtool\n libunistring0 libvpx1 libxpm4 libxslt1.1 libyaml-0-2 linux-libc-dev\n manpages-dev mlock php-apcu-bc php-common php-pear php5.6-readline\n php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg\n php7.2-readline pkg-php-tools po-debconf shared-mime-info shtool\n xdg-user-dirs xml2 zlib1g-dev\nSuggested packages:\n autoconf-archive gnu-standards autoconf-doc dh-make debian-keyring\n g++-multilib g++-4.9-multilib gcc-4.9-doc libstdc++6-4.9-dbg gettext-doc\n uw-mailutils glibc-doc libgd-tools libtool-doc libmcrypt-dev mcrypt\n libstdc++-4.9-doc automaken gfortran fortran95-compiler gcj-jdk php-gd\n libmail-box-perl\nRecommended packages:\n php-readline\nThe following NEW packages will be installed:\n autoconf automake autopoint autotools-dev build-essential debhelper dh-php\n dpkg-dev fakeroot fontconfig-config fonts-dejavu-core g++ g++-4.9 gettext\n intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl\n libalgorithm-merge-perl libapparmor1 libargon2-0 libasprintf-dev\n libc-client2007e libc-dev-bin libc6-dev libcroco3 libcurl3 libdpkg-perl\n libfakeroot libfile-fcntllock-perl libfontconfig1 libgd3 libgettextpo-dev\n libgettextpo0 libglib2.0-0 libglib2.0-data liblist-moreutils-perl\n libltdl-dev libltdl7 libmail-sendmail-perl libmcrypt4 libpcre16-3\n libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium18 libssl-dev libssl-doc\n libssl1.0.2 libstdc++-4.9-dev libsys-hostname-long-perl libtool\n libunistring0 libvpx1 libxpm4 libxslt1.1 libyaml-0-2 linux-libc-dev\n manpages-dev mlock php-apcu php-apcu-bc php-common php-pear php-yaml php5.6\n php5.6-cli php5.6-common php5.6-curl php5.6-dev php5.6-fpm php5.6-gd\n php5.6-imap php5.6-json php5.6-mbstring php5.6-mcrypt php5.6-opcache\n php5.6-readline php5.6-sqlite3 php5.6-xml php7.2-cli php7.2-common\n php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline pkg-php-tools\n po-debconf shared-mime-info shtool xdg-user-dirs xml2 zlib1g-dev\nThe following packages will be upgraded:\n libpcre3\n1 upgraded, 92 newly installed, 0 to remove and 2 not upgraded.\nNeed to get 59.6 MB of archives.\nAfter this operation, 174 MB of additional disk space will be used.

As you can see, there are still PHP 7.2 packages installed altough ansible only passes PHP 5.6 packages to the installer. I ran only the php-versions role and went on installing the PHP packages one by one. I found out the php-apcu package is the problem. Manually running APT will give you this:

vagrant@contrib-jessie:~$ sudo apt install php5.6-apcu Reading package lists... Done Building dependency tree
Reading state information... Done Note, selecting 'php-apcu' instead of 'php5.6-apcu' The following extra packages will be installed: libargon2-0 libsodium18 php-apcu-bc php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline Suggested packages: php-gd php-pear The following NEW packages will be installed: libargon2-0 libsodium18 php-apcu php-apcu-bc php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline 0 upgraded, 10 newly installed, 0 to remove and 3 not upgraded. Need to get 3721 kB of archives. After this operation, 16.8 MB of additional disk space will be used.

I have not tested this on any other platform, maybe it is only Debian. Should the php5.6-apcu be removed from the list? It does not seem to exist anymore. I could submit a pull, but i rather ask for advice first.

Playbook:

  • hosts: all remote_user: vagrant become: true roles:
  • geerlingguy.php-versions
  • geerlingguy.php

Vagrantfile:

Vagrant.configure("2") do |config| config.vm.box = "debian/contrib-jessie64" config.vm.network "private_network", ip: "192.168.33.10" config.vm.provider "virtualbox" do |vb| vb.memory = "1024" end config.vm.provision "ansible" do |ansible| ansible.playbook = "ansible/webserver.yml" ansible.verbose = "v" end end

Host OS: Fedora 27 Guest OS: Debian Jessie

klonos commented 6 years ago

Yep, confirming the above ^^:

apt list --installed | grep php

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

php-apcu/xenial,now 5.1.9+4.0.11-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php-common/now 1:58+ubuntu16.04.1+deb.sury.org+1 all [installed,upgradable to: 1:59+ubuntu16.04.1+deb.sury.org+1]
php-igbinary/xenial,now 2.0.5-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php-memcached/xenial,now 3.0.4+2.2.0-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php-msgpack/xenial,now 2.0.2+0.5.7-1+ubuntu16.04.1+deb.sury.org+3 amd64 [installed]
php-yaml/xenial,now 2.0.2+1.3.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6/xenial,xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 all [installed]
php5.6-cli/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-common/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php5.6-curl/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-dev/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-fpm/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-gd/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-imap/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-json/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-mbstring/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-mcrypt/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-mysql/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-opcache/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-readline/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php5.6-sqlite3/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-xml/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php5.6-zip/xenial,now 5.6.33-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed]
php7.2-cli/xenial,now 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php7.2-common/xenial,now 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php7.2-json/xenial,now 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php7.2-opcache/xenial,now 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php7.2-phpdbg/xenial,now 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
php7.2-readline/xenial,now 7.2.1-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installed,automatic]
mlvnds commented 6 years ago

Same here with:

playbook.yml

- hosts: all
  become: yes
  vars_files:
    - vars.yml
  roles:
    - geerlingguy.php-versions
    - geerlingguy.php

vars.yml

php_install_from_source: false
php_version: "5.6"

php_packages_state: "latest"
php_packages_extra:
  - libpcre3-dev
  - "php{{ php_version }}-apcu"
  - "php{{ php_version }}-common"
  - "php{{ php_version }}-intl"
  - "php{{ php_version }}-cli"
  - "php{{ php_version }}-dev"
  - "php{{ php_version }}-fpm"
  - "php{{ php_version }}-gd"
  - "php{{ php_version }}-curl"
  - "php{{ php_version }}-imap"
  - "php{{ php_version }}-json"
  - "php{{ php_version }}-memcache"
  - "php{{ php_version }}-memcached"
  - "php{{ php_version }}-mcrypt"
  - "php{{ php_version }}-opcache"
  - "php{{ php_version }}-pdo"
  - "php{{ php_version }}-xml"
  - "php{{ php_version }}-zip"
  - "php{{ php_version }}-mysql"
  - "php{{ php_version }}-ssh2"

php_conf_paths:
  - "/etc/php/{{ php_version }}/fpm"
  - "/etc/php/{{ php_version }}/cli"
php_extension_conf_paths:
  - "/etc/php/{{ php_version }}/fpm/conf.d"
  - "/etc/php/{{ php_version }}/cli/conf.d"

php_date_timezone: "Europe/Paris"
php_display_errors: "On"
php_error_reporting: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
php_webserver_daemon: "nginx"
php_enable_php_fpm: true
php_fpm_daemon: "php{{ php_version }}-fpm"
php_fpm_conf_path: "/etc/php/{{ php_version }}/fpm"
php_fpm_pool_conf_path: "{{ php_fpm_conf_path }}/pool.d/www.conf"

An easy quick fix for me was to call 'php-versions' role after 'php' role:

playbook.yml

- hosts: all
  become: yes
  vars_files:
    - vars.yml
  roles:
    - geerlingguy.php
    - geerlingguy.php-versions

That seems weird but with that order, the php binaries purge will come after php extension installations

geerlingguy commented 6 years ago

I haven't had this issue, but I always have the php-versions role before the php role. Tested with a few different installs on CentOS and Debian and can't replicate :/

geerlingguy commented 6 years ago

Ah, but yes, if you install any package without an explicit version (e.g. php-apcu), then everything kind of blows up because of the way Debian OSes do PHP versioned packages (at least the most standard way)... I know apcu and maybe one or two other packages will default to making the systemwide PHP install whatever is latest on that OS, at least I think.

claystation commented 6 years ago

Ah, but yes, if you install any package without an explicit version (e.g. php-apcu), then everything kind of blows up because of the way Debian OSes do PHP versioned packages (at least the most standard way)...

But i specified the version? See in my initial report:

vagrant@contrib-jessie:~$ sudo apt install php5.6-apcu
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php-apcu' instead of 'php5.6-apcu'
The following extra packages will be installed:
libargon2-0 libsodium18 php-apcu-bc php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline
Suggested packages:
php-gd php-pear
The following NEW packages will be installed:
libargon2-0 libsodium18 php-apcu php-apcu-bc php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-phpdbg php7.2-readline
0 upgraded, 10 newly installed, 0 to remove and 3 not upgraded.
Need to get 3721 kB of archives.
After this operation, 16.8 MB of additional disk space will be used.

I specified php5.6-acpu, but it does not exists. So it will install php-acpu which is latest (7.2).

geerlingguy commented 6 years ago

See upstream issue: https://github.com/oerdnj/deb.sury.org/issues/563 — basically, quick fix is setting php_install_recommends: no in your playbook.

I'm also going to patch this role to set that explicitly to avoid this problem by default (noticed that PHP 7.2 was installed on my test Ubuntu 16.04 box when I was doing some testing tonight).