Using APCu on Travis CI, which runs Ubuntu 12.04 - php

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

Related

How to install apfd PHP extension on Debian

I would like to install apfd PHP extension on Debian Buster, but looks like system can't find it.
Link to extension: https://pecl.php.net/package/apfd
Operating System: Debian GNU/Linux 10 (buster)
Kernel: Linux 4.19.0-14-cloud-amd64
PHP version:
$ php --version
PHP 7.3.27-9+0~20210223.81+debian10~1.gbpa4a3d6 (cli) (built: Feb 23 2021 16:47:00) ( NTS )
It's not avaliable in apt list as other php packages even after apt update:
$ sudo apt search apfd
Sorting... Done
Full Text Search... Done
texlive-fonts-recommended/stable 2018.20190227-2 all
TeX Live: Recommended fonts
This is what I was trying to do:
$ sudo apt install php7.3-apfd
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.3-apfd
E: Couldn't find any package by glob 'php7.3-apfd'
E: Couldn't find any package by regex 'php7.3-apfd'
As well as:
$ sudo apt install php7-apfd
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7-apfd
I already update apt, ondrej-php.
This is quite strange, because I always use this Ansible task for PHP packages installation and never had problems like that:
- name: Install additional PHP modules required by PHP Unit
apt: pkg=php7.3-{{ item }} state=present
loop: "{{ php_modules }}"
when: php_version != 5
notify: restart fpm
php_modules:
- xml
- mbstring
- curl
- bcmath
- bz2
- dba
- soap
- zip
- intl
- gd
- imagick
- apfd
When running this Ansible task with apfd this error occured:
"item": "apfd",
"msg": "No package matching 'php7.3-apfd' is available"
I don't have any idea how to fix it.
I can install other php packages like imagick, gd, intl or soap with success using mentioned Ansible tasks.
Thanks to #Zeitounator I manage to install extension.
STEPS:
Install php-pear and php{{ php_version }}-dev on server:
Command line version:
sudo apt install php-pear php7.3-dev
Ansible version:
- name: Install PHP packages
apt: pkg={{ item }} state=present
loop:
- php-pear
- php7.3-dev
Install localy community.general to use community.general.pear Ansible module:
ansible-galaxy collection install community.general
Install apfd extension via pecl:
Command line version:
pecl install apfd
Ansible version:
- name: Install pear package
community.general.pear:
name: pecl/apfd
state: present

Cache PHP extensions installed with Pecl on CircleCI

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

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

When I run composer install on command promp, there exist error like this :
Problem 1
- Installation request for laravel/horizon v1.1.0 -> satisfiable by laravel/horizon[v1.1.0].
- laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system.
To enable extensions, verify that they are enabled in your .ini files:
- C:\xampp-7.1\php\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
How can I solve this error?
Run composer with the --ignore-platform-reqs option and specify pcntl and posix
composer install --ignore-platform-reqs
As per the accepted answer, but you can add this to your composer.json so that you don't have to run --ignore-platform-reqs all the time
"config": {
"platform": {
"ext-pcntl": "8.0",
"ext-posix": "8.0"
}
}
install horizon this way :
composer require laravel/horizon --ignore-platform-reqs
then run
php artisan horizon:install
If you are using docker based on a Unix image you can add it with the docker utility:
docker-php-ext-install pcntl
You can then confirm that this extension is installed and enabled inside of your container:
?> php -i | grep pcntl
/usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini,
pcntl
pcntl support => enabled
pcntl extension is not supported on Windows. (based on your XAMPP information)
Please see these github issues on laravel/horizon page #131, #78.
I suggest you use Laravel Homestead on your Windows system, It is easy to setup and will save you from many of the similar problems in future.
Just run the following:
composer install --ignore-platform-reqs
Note: pcntl is not supported on Windows
add this line
RUN docker-php-ext-install pcntl
before
RUN composer install
This works for me
composer require laravel/horizon --ignore-platform-reqs
Hopefully it will help.
The answer to simply ignore the dependency is wrong. That isn't going to give you a working version of Horizon or whatever package you may be hoping to install. The dependencies must be installed.
Examples of how to install:
APK
sudo add php8-pcntl php8-pcntl
Yum
sudo yum install -y php-pcntl php-posix
I have installed PHP 7.2 instead of 7.1 and everything works fine now. It appears that pcntl was not present in 7.1 but it's installed with php 7.2.
I have some problem and composer install --ignore-platform-reqs works for me
Thanks
You need to install the package while ignoring the platform requirements.
composer require laravel/horizon --ignore-platform-reqs
Then run
php artisan horizon:install
If you're running on windows 10 without homestead you can enable the linux subsystem and run horizon through that.
https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10
Then install the requirements
sudo apt install php7.2-fpm php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip php7.2-mysql
This also can run laravel envoy too which doesn't work on windows.
It's a nice lightweight solution
$composer install --ignore-platform-reqs ext-pcntl
If you use Windows and get that issue - you should just ignore it since Horizon works fine without the extension and doesn't require it on Windows.
So basically you must use the next
composer require laravel/horizon --ignore-platform-reqs
Good luck!

PHP | "The requested PHP extension bcmath is missing from your system."

Greetings fellow developers,
I am trying to use composer for a PHP project of mine on a development server I recently booted up and for some reason I am unable to. I successfully installed composer, however, when I try to run the require command I get the following error:
root#webserver:/var/mypersonal/index# composer require php-amqplib/php-amqplib
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_openssl.dll' - /usr/lib/php/20151012/php_openssl.dll: cannot open shared object file: No such file or directory in Unknown on line 0
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Using version ^2.6 for php-amqplib/php-amqplib
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- php-amqplib/php-amqplib v2.6.3 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
- php-amqplib/php-amqplib v2.6.2 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
- php-amqplib/php-amqplib v2.6.1 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
- php-amqplib/php-amqplib v2.6.0 requires ext-bcmath * -> the requested PHP extension bcmath is missing from your system.
- Installation request for php-amqplib/php-amqplib ^2.6 -> satisfiable by php-amqplib/php-amqplib[v2.6.0, v2.6.1, v2.6.2, v2.6.3].
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-mysqli.ini
- /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, deleting ./composer.json.
I'm assuming it's something to do with the PHP warning I recieve right when running the composer require command but no google search results lead me to the correct direction.
Additionally, I have provided my /etc/php/7.0/cli/php.ini file incase of an error in that file.
https://gist.github.com/anonymous/bc5bac59d684cbf575cef931ef36daf6 (I couldn't include the file in this post due to the character limit on posts.)
Thank you.
You can use function get_loaded_extensions to see if bcmath modul is loaded. Or in terminal php -m or php -m | grep name_of_the_modul
You can install it depending on what OS you are using:
Ubuntu
sudo apt install php7.0-bcmath
CentOS
yum install bcmath
PHP 7.2
Debian - jessie
apt-get update
apt-get install php7.2-bcmath
work like a charm :)
For any version in php Centos use
This solution worked for me
yum install php-bcmath
PHP will take the default version installed in the machine, search for that package and install it.
Delete the file composer.lock file if that is already created and then run again,
composer install
If you run
composer update
it will update whatever default packages are installed in composer.json which might create problem for you.
In Ubuntu 20.04
For php 7.4.3, sudo apt install php7.4-bcmath
For PHP 7.1, the following worked for me:
sudo apt install php7.1-bcmath
If you are using Docker:
bcmath can be installed by running this command inside a container: docker-php-ext-install bcmath
check your php version by type: php --version
you will see something like this:
PHP 7.2.9-1+ubuntu16.04.1 ....
then sudo apt install phpX.X-bcmath where X.X is php version, so for this ^ example it will be sudo apt install php7.2-bcmath
after this check if module existed or not by type php -m | grep bcmath
php 7.2 if you have other version just change it accordingly
For CentOS
sudo yum install php72-bcmath
For Ubuntu
sudo apt install php7.0-bcmath
Run this command, hope it will works
sudo apt-get install php-bcmath
hope this will fix the problem.
sudo apt install php-bcmath
For this problem we should use sudo apt install php-bcmath
Strange thing here
Some month ago I have installed all PHP version in the same manner. In here are the 4 identically configured version of php: 5.6, 7.0, 7.1, 7.2, with the same extensions ( when this was made possible ).
The strange thing was that bcmath is present for all php version excluding 7.1.
In the solution search I arrive here in this question, where the logic's things was confirmed installing bcmath, but in my Linode Debian 9 server the command
apt install php7.1-bcmath
doesn't work, with 3 error messages;
E: Impossible to find the package php7.1-bcmath
E: Impossible to find some package with glob "php7.1-bcmath"
E: Impossible to find a package with the regular expression "php7.1-bcmath"
The goals no meet with any combination of tips and trick, refreshing apt cache, change Debian's mirrored server, installing yum, so on...
After some tentatives I had an illumination: modificating of /etc/apt/sources.list enabling the default Linode repository, then after an apt update (with no solution in the immediate), I have restored the /etc/apt/sources.list commenting out the Linode mirror sources again. Magically, after the new apt update the command now are working.
By this I confirm: apt install php7.1-bcmath is the right command, but your Debian can need a kick in the ass
Install with this command, thats work for me
apt-get install php-bcmath
I tried below package and it worked in Php version 5.6
yum install php56w-bcmath
For those who have already tried installing bc-math and still composer is giving errors.
Try this command
rm composer.lock
It will definitely work

Docker install memcached

I am trying to install memcached in Dockerfile but I keep getting th same error. Everything was working fine but looks like some layers were cached I and the images was being built with no problems at all. But since I cleared the cache I can't build the image. Here is some of it's content:
FROM php:5-apache
RUN apt-get install -y libmemcached11 libmemcachedutil2 build-essential libmemcached-dev libz-dev
RUN pecl install memcached
RUN echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini
There are many other things that are installed but as I said everything was working before. The error is that memcached requires php7 to run. I dont know if something has changed in the recent builds of the library but looks like it refuses to work with php5. Here is the error:
pecl/memcached requires PHP (version >= 7.0.0), installed version is 5.6.30
pecl/memcached can optionally use PHP extension "igbinary" (version >= 2.0)
pecl/memcached can optionally use PHP extension "msgpack" (version >= 2.0)
No valid packages found
install failed
The command '/bin/sh -c pecl install memcached' returned a non-zero code: 1
The PECL memcached package introduced the dependency on PHP 7 in version 3.0.0. You can still install the 2.x version of that package:
FROM php:5-apache
RUN apt-get update && apt-get install -y libmemcached11 libmemcachedutil2 build-essential libmemcached-dev libz-dev
RUN pecl install memcached-2.2.0
RUN echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini

Categories