humanmade / linter-bot

Automatically run the HM Coding Standards on any repository.
https://github.com/apps/hm-linter
16 stars 3 forks source link

Update PHP Version and make it configurable #161

Open roborourke opened 2 years ago

roborourke commented 2 years ago

When the lambda is built we copy the pre-built binary of PHP from an S3 bucket and install it to /bin/php.

The current version is PHP 7.1 and needs to be updated to a minimum of PHP 7.4 in order to not flag false negatives for PHP syntax errors.

Specifically we are seeing this error:

PHP syntax error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)

For code like the following:

class Test {
  public int $id;
}

Acceptance criteria:

Suggested config for PHP version:

phpcs:
  php: 7 # latest PHP 7 version, same for 8

phpcs:
  php: 7.1 # specific php version, must match available binaries
roborourke commented 2 years ago

@joehoyle or @rmccue, was there anything special about the process to build the PHP binary? Presumably needs to built using the lambda build container, if you have existing docs or a script that would help.

joehoyle commented 2 years ago

Hmm I don't remember specifically if we saved that process somewhere. I think I might have followed something like https://aws.amazon.com/blogs/apn/aws-lambda-custom-runtime-for-php-a-practical-example/

joehoyle commented 2 years ago

FYI I was able to compile specific versions of PHP for lambda, using this Dockerfile. You can copy the PHP bin out of /opt/php-bin/bin/php:

#Lambda base image Amazon linux
FROM public.ecr.aws/lambda/provided as builder
# Set desired PHP Version
ARG php_version="7.3.6"
RUN echo ${php_version}
RUN yum clean all && \
    yum install -y autoconf \
                bison \
                bzip2-devel \
                gcc \
                gcc-c++ \
                git \
                gzip \
                libcurl-devel \
                libxml2-devel \
                make \
                openssl-devel \
                tar \
                unzip \
                zip

# Download the PHP source, compile, and install both PHP and Composer
RUN curl -sL https://github.com/php/php-src/archive/php-${php_version}.tar.gz | tar -xvz && \
    cd php-src-php-${php_version} && \
    ./buildconf --force && \
    ./configure --prefix=/opt/php-bin/ --with-openssl --with-curl --with-zlib --without-pear --enable-bcmath --with-bz2 --enable-mbstring --with-mysqli && \
    make -j 5 && \
    make install && \
    /opt/php-bin/bin/php -v