Skip to content

build: Remove unsupported PHP versions by default, fixes #5984 - #6691

Merged
rfay merged 15 commits into
ddev:masterfrom
rfay:20241105_less_php_versions
Nov 8, 2024
Merged

rfay merged 15 commits into
ddev:masterfrom
rfay:20241105_less_php_versions

Conversation

@rfay

@rfay rfay commented Nov 5, 2024

Copy link
Copy Markdown
Member

The Issue

Every new PHP version has been adding heft to the default ddev-webserver. We'd like it to be smaller, for faster download and extraction times. And we'd like it not to grow with every new year's PHP version.

How This PR Solves The Issue

  • Only preinstall versions of PHP that are currently supported
  • When earlier versions are required (like PHP 7.4) install them as needed during first-time project startup.
  • This PR brings the ddev-webserver image size down significantly. In v1.23.5, we had 480MB compressed. After removing most locales, we had 425MB compressed, and now with this one we have 377MB compressed.
image

Manual Testing Instructions

  • Use ddev config --php-version=7.4 and ddev config --php-version=5.6
  • Use all the normal things.

Automated Testing Overview

I think that all the normal test coverage remains the same. It will mean that when we test all PHP versions that the tests will be a bit slower.

Release/Deployment Notes

We need to boast about how much smaller the image is :)

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file maintenance labels Nov 5, 2024
@github-actions

github-actions Bot commented Nov 5, 2024 •

Copy link
Copy Markdown

@rfay
rfay force-pushed the 20241105_less_php_versions branch from cd39ebf to 272551d Compare November 6, 2024 13:44
@rfay
rfay marked this pull request as ready for review November 6, 2024 20:17
@rfay
rfay requested a review from a team as a code owner November 6, 2024 20:17
@rfay
rfay requested a review from stasadev November 6, 2024 20:17
Comment thread pkg/ddevapp/config.go Outdated
Comment on lines +1170 to +1181
// If our PHP version is not already provided in the ddev-webserver, add it now
if _, ok := nodeps.PreinstalledPHPVersions[app.PHPVersion]; !ok {
contents = contents + fmt.Sprintf(`
### DDEV-injected addition of not-preinstalled PHP version
RUN /usr/local/bin/install_php_extensions.sh "php%s" "${TARGETPLATFORM#linux/}";
RUN update-alternatives --set php /usr/bin/php%s
RUN chmod ugo+rw /var/log/php-fpm.log && chmod ugo+rwx /var/run && ln -sf /usr/sbin/php-fpm%s /usr/sbin/php-fpm
RUN mkdir -p /tmp/xhprof
RUN chmod -fR ugo+w /etc/php /var/lib/php/modules /tmp/xhprof
RUN phpdismod blackfire xdebug xhprof
`, app.PHPVersion, app.PHPVersion, app.PHPVersion)
}

@stasadev stasadev Nov 6, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block should have been added earlier.

If people do any manipulation with php (or it's packages) in pre.Dockerfile, then this change is likely to break their customization (not expected PHP version will be used), so maybe this block should be before including pre.Dockerfile?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. I put it here because the check for ddev-webserver had already been done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another advantage of earlier PHP install is when you add more packages to the web image, or make some changes in the .ddev/web-build, Docker will use the cached layer for this PHP install, so it won't rebuild the whole thing.

Comment thread pkg/ddevapp/config.go Resolved
@rfay
rfay force-pushed the 20241105_less_php_versions branch from 61181e2 to 4698571 Compare November 7, 2024 00:53
@rfay

rfay commented Nov 7, 2024

Copy link
Copy Markdown
Member Author

I pushed the images, thanks so much for catching that @stasadev

deviantintegral added a commit to Lullabot/drainpipe that referenced this pull request Nov 7, 2024
justafish pushed a commit to Lullabot/drainpipe-dev that referenced this pull request Nov 7, 2024
@rfay
rfay force-pushed the 20241105_less_php_versions branch from 0c20a3e to f7ac210 Compare November 7, 2024 14:21
@stasadev
stasadev force-pushed the 20241105_less_php_versions branch from f7ac210 to a69d1a6 Compare November 7, 2024 17:45
@stasadev

stasadev commented Nov 7, 2024 •

Copy link
Copy Markdown
Member

I Tested it again with php7.4, it fails much faster (less that a minute).

But it failed for php5.6:

Installing packages for PHP php5.6 on amd64: php5.6-apcu php5.6-bcmath php5.6-bz2 php5.6-curl php5.6-cli php5.6-common php5.6-fpm php5.6-gd php5.6-imagick php5.6-intl php5.6-json php5.6-ldap php5.6-mbstring php5.6-mcrypt php5.6-memcached php5.6-mysql php5.6-opcache php5.6-pgsql php5.6-readline php5.6-redis php5.6-soap php5.6-sqlite3 php5.6-uploadprogress php5.6-xdebug php5.6-xhprof php5.6-xml php5.6-xmlrpc php5.6-zip

E: Unable to correct problems, you have held broken packages.

I removed -qq from apt-get install because there are not enough details on error:
(If something breaks here, it will give people a full error message, resulting in less need for support.)

Installing packages for PHP php5.6 on amd64: php5.6-apcu php5.6-bcmath php5.6-bz2 php5.6-curl php5.6-cli php5.6-common php5.6-fpm php5.6-gd php5.6-imagick php5.6-intl php5.6-json php5.6-ldap php5.6-mbstring php5.6-mcrypt php5.6-memcached php5.6-mysql php5.6-opcache php5.6-pgsql php5.6-readline php5.6-redis php5.6-soap php5.6-sqlite3 php5.6-uploadprogress php5.6-xdebug php5.6-xhprof php5.6-xml php5.6-xmlrpc php5.6-zip

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 php5.6-mcrypt : Depends: libmcrypt4 (>= 2.5.8) but it is not installable
E: Unable to correct problems, you have held broken packages.

The script needs to update /etc/apt/sources.list.d/debian.sources too.

I pushed a new commit and started a new build for ddev-php-base.

Comment thread pkg/ddevapp/config.go Outdated
contents = contents + fmt.Sprintf(`
### DDEV-injected addition of not-preinstalled PHP version
RUN /usr/local/bin/install_php_extensions.sh "php%s" "${TARGETPLATFORM#linux/}"
RUN update-alternatives --set php /usr/bin/php%s

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried PHP 5.6, and Composer doesn't work because PHP binary is set too early. I think it's fine to install the packages early, but this should be moved back.

ddev config --php-version=5.6 --composer-version=2.2
Warning: command 'composer self-update --2.2' run as 'root' failed with exit code 1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen the composer update failures with php5.6... but composer just isn't going to work anyway is it with 5.6? My assumption was that it was OK, just an artifact of ancient PHP. I don't think (any version of) composer is going to be usable with 5.6 is it?

@stasadev stasadev Nov 7, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short, Composer uses PHP, if the current PHP is not compatible with the current Composer (which is always latest stable in our Docker image), it cannot downgrade itself.


Composer 2.2 works fine with PHP 5.6, 7.0, 7.1

The problem is not whether some PHP can use Composer or not: by default we install the latest stable version of Composer and then use the composer self-update feature, but Composer itself depends on PHP, and if the current Composer binary from which the upgrade/downgrade is done is not compatible with the current PHP binary, it will not be able to run this upgrade/downgrade.

If someone is using PHP 5.6, 7.0, 7.1, DDEV will try to install Composer every ddev start because there is a warning, the warning from log-stderr.sh doesn't show the details, because they are written to stdout:

$ ddev config --php-version=7.1 --composer-version=2.2

$ ddev start
...
Warning: command 'composer self-update --2.2' run as 'root' failed with exit code 1:
Command 'composer self-update --2.2' didn't return stderr output
...

# Composer 2.8.2 tries to downgrade itself to 2.2 but can't do it because
# update-alternatives --set php /usr/bin/php7.1

$ ddev exec composer self-update --2.2
Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.1.33-65+0~20241104.97+debian12~1.gbpf30d7c, please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.
Failed to execute command composer self-update --2.2: exit status 1

The same config works with DDEV v1.23.5.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the careful thinking and testing. My interpretation of your suggestion is in 0acdcd1

It does remove the composer warning. I think it's likely correct and non-intrusive.

@rfay
rfay force-pushed the 20241105_less_php_versions branch from 8a42d22 to 0acdcd1 Compare November 8, 2024 15:04

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and works great, I retested all unsupported PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 and 8.0 on AMD64.

@terry-pixel

Copy link
Copy Markdown

Thanks,
but for me it's impossible to use :
ddev exec php7.4 mycommand

@stasadev

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants