Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PHP Version and make it configurable #161

Open
6 tasks
roborourke opened this issue Mar 15, 2022 · 3 comments
Open
6 tasks

Update PHP Version and make it configurable #161

roborourke opened this issue Mar 15, 2022 · 3 comments

Comments

@roborourke
Copy link

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:

  • Document process for building and uploading PHP binaries
  • Rename current binary on S3 to php@7.1
  • Build & add PHP binary for 7.4 to S3 as php@7.4
  • Optional: Build and add PHP 8.1 binary to S3 as php@8.1
  • Update PHPCS linter to spawn child PHP process using php@7.4 by default
  • Update PHPCS linter to read config for PHP version and spawn child process with configured version

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
Copy link
Author

@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
Copy link
Member

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
Copy link
Member

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

roborourke added a commit that referenced this issue Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants