Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codebuild not installing PHP packages

My codebuild has been working well till today. It's failing with the following errors:

Reading state information... 
E: Unable to locate package php7.1 
E: Couldn't find any package by regex 'php7.1' 
E: Unable to locate package php7.1-xml 
E: Couldn't find any package by regex 'php7.1-xml' 
E: Unable to locate package php7.1-xmlrpc 
E: Couldn't find any package by regex 'php7.1-xmlrpc' 
E: Unable to locate package php7.1-zip 
E: Couldn't find any package by regex 'php7.1-zip' 
E: Unable to locate package php7.1-mysql 
E: Couldn't find any package by regex 'php7.1-mysql' 
E: Unable to locate package php7.1-mbstring 
E: Couldn't find any package by regex 'php7.1-mbstring' 
E: Unable to locate package php7.1-mcrypt 
E: Couldn't find any package by regex 'php7.1-mcrypt' 
E: Unable to locate package php7.1-gd 

what could be the issue? Please note that the builds have been working well with this setup. There was no change in the buildspec file.

This is what I tried:

version: 0.2
phases:
 install:
   commands:
     - |

         apt-get install -y software-properties-common

         export DEBIAN_FRONTEND=noninteractive
         apt-get update

         LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php

version: 0.2
phases:
 install:
   commands:
     - |

         apt-get install -y software-properties-common

         export DEBIAN_FRONTEND=noninteractive
         apt-get update

         LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
         apt-get update
         apt-get install -y php7.1 \
                  php7.1-xml \
                  php7.1-xmlrpc \
                  php7.1-zip \
                  php7.1-mysql \
                  php7.1-mbstring \
                  php7.1-mcrypt \
                  php7.1-gd \
                  php7.1-opcache \
                  php7.1-dom \
                  php7.1-bcmath \
                  php7.1-curl \
                  unzip \
                  nasm

I expected the php packages to be installed normally as it has been the case.

like image 484
learner Avatar asked Dec 23 '22 23:12

learner


2 Answers

This was an issue with the base image I was using, which was on Ubuntu 14.04. Ubuntu 14.04 LTS ended support as of April 2019, and from the ondrej repository there is no repo folder that matches ubuntu 14.04.

I had to switch my base image to aws/codebuild/standard:2.0, which fixed my problem.

like image 137
learner Avatar answered Jan 12 '23 03:01

learner


When you switch to aws/codebuild/standard:2.0 it provides you with Ubuntu 18. You also have to supply a runtime like

phases:
  install:
    runtime-versions:
      php: 7.3

I found that AWS put their PHP ini in /usr/local/etc/php/conf.d/ but when you install extensions the ini gets put into /etc/php/7.3/cli/php.ini - so you have to join the non-standard to the standard so the extension files are found.

This can be solved by adding the standard path to an ini file as follows:

touch /usr/local/etc/php/conf.d/extra_config.ini
echo extension_dir="/usr/lib/php/20180731/" >> /usr/local/etc/php/conf.d/extra_config.ini
echo extension=gd.so >> /usr/local/etc/php/conf.d/extra_config.ini
Running command php -m

The final buildspec.yml looks like this (with some debug so you can see the before and after, and the contents of the extra_config.ini:

phases:
  install:
    runtime-versions:
      php: 7.3
    commands:
      - php -v
      - php -m
      - lsb_release -a
      - LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
      - apt-get update -y
      - apt-get install -y php7.3-gd  php7.3-xdebug
      - ls /usr/lib/php/20180731
      - touch /usr/local/etc/php/conf.d/extra_config.ini
      - "echo extension_dir=\"/usr/lib/php/20180731/\" >> /usr/local/etc/php/conf.d/extra_config.ini"
      - "echo extension=gd.so >> /usr/local/etc/php/conf.d/extra_config.ini"
      - "echo zend_extension=xdebug.so >> /usr/local/etc/php/conf.d/extra_config.ini"  
      - cat /usr/local/etc/php/conf.d/extra_config.ini
      - php -m
like image 39
sixfive Avatar answered Jan 12 '23 01:01

sixfive