Where to contribute PHP support for Windows

I would like to extend the travis setup of one Project to Windows.

I have some experience installing PHP with Chocolatey, even if it is a bit rusty.
I just would like to know where I need to do the PR, and make sure its not something already worked on.

3 Likes

I just would like to know where I need to do the PR

Probably https://github.com/travis-ci/travis-build

For PHP, you can use language: sh. For example:

os: windows
language: sh
before_install:
  - choco install php
  - export PATH=/c/tools/php72:$PATH

First of all …

Thank you for your interest in bringing PHP support to Windows! We very much appreciate your enthusiasm.

I will describe how PHP support works on Linux and the Mac right now. Do keep in mind that Windows is a new game, and it would not have to happen in the same way as it does in the other two OSes. (Though, obviously, similar tooling may reduce the amount of work it would take to make it happen.)

How PHP support works now on Linux and macOS

As @mauriciofauth pointed out, much of what we would call “PHP support” on Travis CI is described in https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/script/php.rb, in particular, in this code branch:

  1. First, run phpenv global VERSION
    1. if it succeeds, use that version. This is one that is pre-installed on the build image.
    2. If it fails, grab a pre-compiled archive from our PHP archive on remote file storage (more on this in the next section).
  2. Write ~/.pearrc with reverse-engineered file content (this could be quite brittle).
  3. Run phpenv global VERSION again, and phpenv rehash to activate the new PHP run time.

Creating pre-compiled PHP archives

https://github.com/travis-ci/php-src-builder is responsible for compiling and creating new PHP archives. It sets up (if necessary) a PHP building environment, compiles PHP using php-build, and uploads the archives to the right place so that travis-build can find it at the run time.

How should PHP support on Travis look?

This is an open question. As I said earlier, I might be less work to make it look a lot like Linux and Mac. Maybe not. My understanding of the Windows ecosystem is very limited.

Option 1: Leverage current tooling

In this case, I reckon the first thing to do would be to create a base set of PHP archives for use by Windows VMs. This would start with a language: sh job on Windows, use php-build to compile, archive and upload to the remote file storage. I do not know if php-build, written in bash, is compatible with “git bash”. If it’s not, it could be some work to make it so.

This would also mean that we ensure that the Windows image has a reasonable C/C++ toolchain that we can use.

Option 2: Use Windows-native tooling

It might be more intuitive for Windows developers to use the Windows-native tools. For example, https://windows.php.net/download has many archives that might be usable. Or, alternatively, Chocolatey archive(s) might be more in tune with what we need (as suggested by @mauriciofauth).


I hope all of this makes some sense, and helps you get started.

1 Like

Thank you for this extensive introduction.

not sure if phpenv and php-build will properly run on windows, as they seem to be very centred on *nix systems.
There seems to be an alternative with https://github.com/tobias-trozowski/phpenv-windows

And the windows native way seems a lot easier (or chocolatey, which is basicly using the archives provided by php.net if I remember correctly)

So I guess I will work on the travis-build repository in the linked file.
I then need to get a example_payload for a php windows build and need to pipe it into the /scrip/compile and see if it runs through?
cat example_payloads/windows_php.json | bundler exec script/compile

I wonder how and what I should and could test there, and how do I validate php is working on windows?

Hi All

@BanzaiMan wrote up a great summary. Also, major High 5s to @Flyingmana for there extra info.

I did a little experiment to see if I could get phpenv to work: https://staging.travis-ci.com/joshk/windows-testing/builds/234625

You can see the .travis.yml config which went with it: https://github.com/joshk/windows-testing/blob/joshk-php/.travis.yml

It failed with the error message:

configure: error: xml2-config not found. Please check your libxml2 installation.

If we can resolve this issue, we could get the install on demand option working, and then address building some archives for faster installation.

Any and all help would be greatly appreciated.

I tried out a bit to install php via choco, but had problems as refreshenv was not available, so php was not added to the environment.
Also most commands are only available as their .exe version, so php will likely be also only available as php.exe inside bash. Not sure if this will be a problem.

no idea about the libxml, seems to be normally delivered with the php installer/package, and on choco I dont find a related package.
Only thing I found was https://stackoverflow.com/questions/36980095/php-configure-on-windows-enable-libxml2

The lack of a libxml2 to build against is a major problem with choco only windows. Lots of software needs this. I am facing it because I want python ‘lxml’ to build, and it also needs the headers and .lib files, etc.

There is a nice trick to use the xsltproc package which includes the libxml2 headers and built libraries; see https://github.com/metanorma/chocolatey-metanorma/issues/33 . I then ran into a problem of the linker missing a few stdlib symbols, and the python/lxml build wrappers didnt let me easily change which vcdist to link against so I put that on hold. But the approach that metanorma used should work most of the time, especially if you have control over the compiler and linker flags.

Regarding refreshenv, see RefreshEnv for bash for a hack at getting refreshenv working.

On the topic of php choco , the php choco does a bit of fiddling after the install to create a basic php.ini, however I found quite a bit more work was needed to get to a sane php, especially for older php versions in choco.
You can see the post-install steps done by the most recent versions of the php package at https://github.com/chocolatey-community/chocolatey-coreteampackages/blob/master/automatic/php/tools/chocolateyInstall.ps1

My fixup script for php also installs pear from the phar , as that seems impossible to do with pear components inside the php package from choco. Here is a recent version of it :

Even if you dont need to use PEAR, doing a PEAR sync is a simple way to check that the php SSL is working correctly.

I was able to mostly get this working using Choco to install PHP and then hacking together a refreshenv function.

_anchors:
  - &refreshpath eval $(powershell -NonInteractive -Command 'write("export PATH=`"" + ([Environment]::GetEnvironmentVariable("PATH","Machine") + ";" + [Environment]::GetEnvironmentVariable("PATH","User")).replace("\","/").replace("C:","/c").replace(";",":") + ":`$PATH`"")')
os: windows
language: bash
before_install:
  - choco install php
  - choco install composer
  - *refreshpath

This would have been so much easier if Travis CI natively supported PHP or at least documented this solution somewhere. Also note that while this works (ish) for my use case, it’s definitely a hack and more complex use cases may fail.

I did also try to use php-env but ran into the same issue mentioned above of missing libxml2.

1 Like
Imprint