We are using CircleCI as build server for php symfony application and we require the mongodb library with composer, which is dependent on the mongodb extension, that we install with pecl. So we have the following steps in our build:
- run: sudo pecl install mongodb
- run: echo -e "extension=mongodb.so" | sudo tee /usr/local/etc/php/php.ini > /dev/null
- run: cd app && composer install --no-interaction
This works fine, but the PECL mongo db extension takes half of our build time.
Is there a way to store the installed PECL extensions into the CircleCI cache?
I have tried the following:
- save_cache:
key: pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
paths:
- /usr/local/20160303/mongodb.so
But this doesn't work - mongodb is downloaded again by PECL. What are the directories that I should try to cache in this case?
Answering my own question. There is a way to cache PHP extensions installed with PECL. One needs to know where exactly the pecl extensions are installed (pecl config-show). It seems that on the Circle CI containers this location is:
/usr/local/lib/php/extensions/no-debug-non-zts-20160303/
The extensions can be copied from this folder to a temporary directory which can be cached and restored. Restored files can be copied back with sudo.
- run: pecl config-show
- run: mkdir pecl-cache
- restore_cache:
keys:
- pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
- pecl-v1-
- run:
name: Copying restored pecl extensions cache into extensions directory
command: sudo cp -R pecl-cache/. /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
- run:
name: Install mongodb pecl extensions if mongodb.so is not there
command: >
if [ ! -f /usr/local/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so ]; then
sudo pecl install mongodb ;
fi
- run:
name: Copying pecl extensions to temp directory which will be cached
command: sudo cp -R /usr/local/lib/php/extensions/no-debug-non-zts-20160303/* pecl-cache/
- save_cache:
key: pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
paths:
- pecl-cachedocker-php-ext-install
Related
I am trying to deploy a php project via cloud run, but I keep getting the same error
Problem 1
- spatie/image is locked to version 1.10.1 and an update of this package was not requested.
- spatie/image 1.10.1 requires ext-exif * -> it is missing from your system. Install or enable PHP's exif extension.
Problem 2
- spatie/pdf-to-image is locked to version 2.1.0 and an update of this package was not requested.
- spatie/pdf-to-image 2.1.0 requires ext-imagick * -> it is missing from your system. Install or enable PHP's imagick extension.
Problem 3
- spatie/image 1.10.1 requires ext-exif * -> it is missing from your system. Install or enable PHP's exif extension.
- spatie/laravel-medialibrary 7.19.5 requires spatie/image ^1.4.0 -> satisfiable by spatie/image[1.10.1].
- spatie/laravel-medialibrary is locked to version 7.19.5 and an update of this package was not requested.
I can't find not about this package, but it's an Laravel's deppendece, so I can't uninstall, I am using docker to make this deploy
FROM composer as build
WORKDIR /app
COPY . /app
RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader
FROM node:12 as node
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
RUN npm install
FROM php:7.3-apache-stretch
RUN docker-php-ext-install pdo pdo_mysql
EXPOSE 8080
COPY --from=build /app /var/www/html
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
RUN echo "Listen 8080" >> /etc/apache2/ports.conf && \
chown -R www-data:www-data /var/www/html && \
a2enmod rewrite
CMD service apache2 restart && bash
already tried:
remove as required package (Continuous deployment has been set up, but your repository has failed to build and deploy.)
php composer.phar require spatie/image-optimizer --ignore-platform-reqs
composer require google/cloud-logging google/cloud-error-reporting
update the package
update the yarn and the npm
You have to install required php extensions, in dockerfile, at line
RUN docker-php-ext-install pdo pdo_mysql
add exif:
RUN docker-php-ext-install pdo pdo_mysql exif
Installing image magick, may be complicated, see https://github.com/docker-library/php/issues/105#issuecomment-563010422 or this script - https://github.com/mlocati/docker-php-extension-installer
The problem was resolved by running install commands on a Linux(ubuntu) platform, nothing else changed, I don't even have sure yet why the error was happening
I'm new to docker.
I would like to use docker-php-extension-installer for installing PHP extensions to my container, because according to php-docker hub docs this script builds upon the docker-php-ext-* scripts and simplifies the installation of PHP extensions by automatically adding and removing Debian (apt) and Alpine (apk) packages.
The problem is when I try to install gd or pdo_mysql or something else, extensions are installed but not shown in the modules list when I run php -m command in my bash.
Here is my DockerFile
FROM php:7.3-fpm
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN apt-get update && apt-get install -y unzip \
&& apt-get install -y git nano \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# use https://github.com/mlocati/docker-php-extension-installer to simply install php extensions with dependencies
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd pdo_mysql
Maybe I have to enable these extensions somehow, but how can I do it from my Dockerfile? There is nothing said about this neither in docker-php-extension-installer page docs, no in official php docker page.
If anybody knows, please help. Thanks.
The above-mentioned Dockerfile is used as part of docker-compose. When I created a docker-compose.yml file, I made a mistake. To change default php configuration, I mounted host folded, where I keep my custom php.ini, and mapped it to conf.d folder in php container. Like this:
# PHP Service
php:
build: ./.docker/php
volumes:
- ./.docker/php/conf.d:/usr/local/etc/php/conf.d:ro
depends_on:
- mysql
But the conf.d folder keeps the configuration of all installed extensions, for example:
docker-php-ext-gd.ini docker-php-ext-pdo_mysql.ini docker-php-ext-sodium.ini docker-php-ext-xdebug.ini
So the contents of my host folder replaced the original conf.d contents and as a result - extensions didn't work.
These extensions are pre-installed and enabled on Google App Engine php container:
APCu
Bzip2
cURL
FPM
GMP
mbstring
mcrypt
libsodium
Memcached
MySQL(PDO) (uses mysqlnd)
MySQLi (uses mysqlnd)
OPcache
OpenSSL
pcntl
PostgreSQL
PostgreSQL (PDO)
Readline
recode
sem
Sockets
Zip
Zlib
They are compiled with php and enabled by default (as you can see here https://github.com/GoogleCloudPlatform/php-docker/blob/master/package-builder/debian/rules.in)
How can I disable some of then? MySQL for example, as I'm using postgres.
Here is my Dockerfile until the moment:
FROM gcr.io/google-appengine/php72:latest
ARG ENABLE_XDEBUG
ARG COMPOSER_FLAGS='--no-scripts --no-dev --prefer-dist'
ENV COMPOSER_FLAGS=${COMPOSER_FLAGS}
RUN apt-get update -y
RUN apt-get install unzip -y
RUN apt-get install autoconf -y
RUN apt-get install build-essential -y
# php-decimal
RUN apt-get install libmpdec-dev -y
RUN pecl install decimal
# Swoole
RUN pecl install swoole-4.2.13
COPY . $APP_DIR
RUN chown -R www-data.www-data $APP_DIR
RUN /bin/bash /build-scripts/move-config-files.sh
RUN /build-scripts/composer.sh;
ENTRYPOINT ["/build-scripts/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
# Option to install xdebug
RUN echo "Will enable XDEBUG: $ENABLE_XDEBUG"
RUN if [ "$ENABLE_XDEBUG" = "true" ]; then pecl install xdebug; fi
RUN if [ "$ENABLE_XDEBUG" = "true" ]; then echo "zend_extension=/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/xdebug.so" >> /opt/php72/lib/php.ini; fi
EXPOSE 8080
You can take complete control of the container and the extensions that are being loaded by mounting your own php.ini (and complete conf.d directory for that matter) into the container.
You can start the container and then log into the container by using...
docker exec -it [container_name] bash
...and navigate to the /opt/php72/lib directory. That, or download the php.ini directly using...
docker cp [container_name]:/opt/php72/lib/php.ini
...,modify it and volume mount it into the container using a -v flag or add it to a docker-compose.yml file.
Just one other thing that caught my attention in your Dockerfile is that the xdebug. So is added to the php.ini. It would be better to add a separate .ini to PHP's conf.d directory so the original file remains...well, original.
I'm struggling with Docker.
I'm tring to create an image to work on symfony project and to learn Docker in the same time.
Here is my Dockerfile:
FROM php:7-apache
LABEL Description = "This image is used to start Symfony3 project"
ENV DIRPATH /var/www/html
# apt-get command
RUN apt-get update && apt-get install -y \
vim \
git \
&& apt-get clean
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Install the Symfony Installer
RUN curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
RUN chmod a+x /usr/local/bin/symfony
I build the image with the command:
docker build -t symfony .
Works well! Cool!
I'm create a container with:
docker run --name symfony -d -v "$PWD":/var/www/html -p 80:80 symfony
Works well also. The web server is running on the good port.
I can go in my container with:
docker exec -ti symfony bash
But when I'm trying to do a composer update, I have some errors:
Failed to download symfony/symfony from dist: Could not decompress the archive, enable the PHP zip extension.
A php.ini file does not exist. You will have to create one.
How can I create the php.ini in Dockerfile?
I also think that I have an issue with permission.
When I'm trying to the web/app_dev.php I have this message:
You are not allowed to access this file. Check app_dev.php for more information.
You can ADD a custom php.ini configuration specifing it in the dockerfile,
As Example, you can take a look at this repo for this example:
dokerfile
# install a few more PHP extensions
RUN apt-get update && apt-get install -y php5-imagick php5-gd php5-mongo php5-curl php5-mcrypt php5-intl
# copy a custom config file from the directory where this Dockerfile resides to the image
COPY php.ini /etc/php5/fpm/php.ini
You can find various approach and various sample on the net.
Hope this help
Next to the missing php.ini file you should also install zip so you can download from dist, i.e.
RUN docker-php-ext-install zip
Which will install and enable the PHP zip extension which is requested in your error message.
I have a Symfony-application which is dependent on APCu (php5-apcu). The server is running PHP 5.6 on Ubuntu 15.04. APCu is required as a dependency through composer, i.e:
"require": {
"ext-apc": "~4.0"
}
Which works great. Trying to get the application running on Travis-CI, isn't as smooth, since they run Ubuntu 12.04, which doesn't have the php5-apcu package, which yields:
E: Unable to locate package php5-apcu
Installing php-apc doesn't satisfy the ext-apcu requirement, and I'd prefer not to promote deprecated packages.
Any suggestions on how to setup APCu on Travis CI? Preferably without manually downloading the package.
You can easily install the apcu extension from pecl.
Here is an example .travis.yml file:
language: php
php:
- 5.6
before_script:
- pear config-set preferred_state beta
- yes '' | pecl install apcu
script:
- cd tests/ && phpunit
If you need a more complex solution, for example multiple php versions, you should be able to easily adopt the solution from the doctrine/cache repository (https://github.com/doctrine/cache/blob/master/.travis.yml).
They run the tests against php 5.3 - 5.6 and hhvm with the following before_script:
[...]
before_script:
- [...]
- sh -c "if [[ $TRAVIS_PHP_VERSION != 'hhvm' && `php-config --vernum` -ge 50500 ]] ; then pecl config-set preferred_state beta; printf "yes\n" | pecl install apcu ; else echo 'extension="apc.so"' >> ./tests/travis/php.ini ;fi"
- [...]
[...]
Happy testing