PHP extensions dependency issue when installing from puppet - php

does anybody knows how to resolve issue with dependencies for php extensions ?
default.pp
class { 'php':
package => 'php5',
service => 'apache',
version => '5.2.10.dfsg.1-2ubuntu6.5',
require => Package['apache'],
}
package { "PhpModule_mhash":
ensure => '5.2.10.dfsg.1-2ubuntu6.5',
name => 'php5-mhash',
require => [Package['php'], Package['PhpModule_common'], ],
}
when i vagrant up i'm receiving err
err: /Stage[main]//Package[PhpModule_mhash]/ensure: change from purged to 5.2.10.dfsg.1-2ubuntu6.5 failed: Could not update: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold --force-yes install php5-mhash=5.2.10.dfsg.1-2ubuntu6.5' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
php5-mhash : Depends: php5 but it is not going to be installed or
phpapi-20060613+lfs
E: Unable to correct problems, you have held broken packages.
at /tmp/vagrant-puppet/manifests/default.pp:79
My virtual box repository is up to date and all required packages are available. PHP is also installed without problems.
What's very interesting is fact that when i vagrant ssh and execute following command:
/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold --force-yes install php5-mhash=5.2.10.dfsg.1-2ubuntu6.5
it's installed without any notice...
Is there a way to tell Package that php5 is already installed ?
Is there a way to omit dependencies if i have already required package ?
What options do i have on Puppet or Debian side?
Thanks in advance

Puppet Chaining is the answer !
Even though i've specified that *PhpModule_mhash* package`requires php class i had to insert chaining in my manifest.
Class['php'] -> Package['PhpModule_common'] -> Package['PhpModule_cli'] -> Package['PhpModule_mhash']

Related

Having Difficulty getting Mongodb to work with PHP

I have installed mongodb on a newly installed Ubuntu 18.04 server, and while I am able to work with mongo on the command line, I cannot seem to connect to it using PHP.
I've been following the process as per https://www.youtube.com/watch?v=RQcQ5tvb5E8&t=620s:
apt install mongodb-server
apt install php-pear # to get PECL
apt install php7.2-dev # to get phpize
pecl install mongodb
phpinfo() shows extension_dir=/usr/lib/php/20170718, and mongodb.so is indeed in that directory, with the same ownership and permissions as all other files. php -i | grep extension_dir shows extension_dir => /usr/lib/php/20170718 => /usr/lib/php/20170718
I then added extension=mongodb.so to /etc/php/7.2/apache2/php.ini, in the same location as the other extensions are listed. There is also a php.ini file under /etc/php/7.2/cli/, so I added the line there to. I then restarted the apache2 service.
I created a test file under /var/www/html/mongo.php
<?php
$m = new Mongo();
var_dump($m);exit;
When I browse to that page I get a 'This page isnt working; HTTP ERROR 500' message in Chrome. I have also tried Mongodb();, MongoClient();, MongodbClient();, mongo();, mongodb();, and mongodbclient();, but all to no avail.
Please make sure you have also installed the mongodb php driver. Please confirm the php version first.
On Ubuntu you can just do:
sudo apt-get install php-mongodb
or the same for specific PHP version:
sudo apt-get install php5.6-mongo
or
sudo apt-get install php7.0-mongodb
And then restart the service.
sudo systemctl reload nginx
You should to try some of these
https://docs.mongodb.com/ecosystem/drivers/php/
https://www.php.net/manual/en/mongodb.tutorial.library.php
they should work fine with php7 + composer
Actually with composer is pretty easy(something like this):
`$ composer require mongodb/mongodb
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing mongodb/mongodb (1.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
Create a File: test.php (in the same location where you ran composer)
<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>
That should be enough

Composer require ext-zip fails

I am told by PHPStorm that I need to composer require ext-zip, however, that command is failing...
PHPStorm says
The command I am issuing is
composer require ext-zip
results in
Your requirements could not be resolved to an installable set of packages.
and
Installation failed, reverting ./composer.json to its original content.
Solution #1 - add ext-zip to your required section of composer.json:
{
"require" : {
"ext-zip": "*"
}
}
Solution #2 - install php-zip extension:
Windows:
Uncomment this line in your php.ini
;extension=php_zip.dll
Linux:
sudo apt-get install php-zip
or
sudo apt-get install php7.0-zip (make sure you typed YOUR php version, you can check your version by doing php -v command)
Then, you need to restart your web server.
sudo service apache2 restart
If your code runs OK - you've already got the zip extension installed on your machine. PHPStorm adds this suggestion to ensure that anywhere else that the project is deployed also has the right extensions too.
Manually adding the line in your composer.json file (require block) "ext-zip": "*", (and others that it can suggest, such as ext-apc, ext-redis and ext-json, as well as any others that you might be using) will make sure that when you deploy it composer can also check that the appropriate extra items are installed.
It's only a warning though, and you could ignore it - or you can allow composer to make sure that your servers are setup as they would be needed to run your code, and do things with zip-files. If your server doesn't have ext-zip installed, composer install would complain, and stop - saving issues later when you discover that code fails without the zip extension, et al.
The given hint comes from PhpStorm, not from composer itself: your IDE has detected that your code uses a method (or in this case: the ZipArchive class) that is only available when the ZIP extension is enabled. But your composer.json did not contain that requirement so far.
So, PhpStorm asks you to add this requirement to the JSON file to make the requirements to run your code more precise. How you solve that requirement is up to you: the best way would be to install that extension, but that is out of composer's scope

Install Specific PHP Version with Puppet & Vagrant

First time puppet user, and I'm having trouble getting an install of a specified version of PHP using Vagrant. I'm using the example42/php module, and I keep running into ensure problems.
Error: Could not update: Execution of '/usr/bin/yum -d 0 -e 0 -y install php-5.5.12' returned 1: Error: Nothing to do
Error: /Stage[main]/Php/Package[php]/ensure: change from absent to 5.5.12 failed: Could not update: Execution of '/usr/bin/yum -d 0 -e 0 -y install php-5.5.12' returned 1: Error: Nothing to do
Warning: /Stage[main]/Php/File[php.conf]: Skipping because of failed dependencies
spits out of my console, followed by another attempt that's identical.
My .pp file I'm provisioning with:
class lamp {
# package {'php':
# ensure => present,
# }
}
node 'node1' {
include lamp
file { '/php':
ensure => directory,
# I read that I may need to have a directory in order for the install to work...
}
class { 'php':
version => '5.5.12',
}
}
As far as I can tell, I'm referencing correctly to the modules, which I store inside /puppet/modules/ and it's finding them, but I'm having a hard time getting a specific version of PHP to install. I could use a very simple "getting started LAMP" for Puppet but that only install 5.3.3 even if I ensure => latest,
The puppet module only uses your system's package manager (yum) to download specific php packages. If it cannot find the required packages, it will not work. 5.3.3 is latest version in your repository, so it install that. I wouldn't be surprised if this is the only version of php available in your repositories.
You need to configure yum with some repositories which have the required PHP packages and then try the puppet module with that.

PHPUnit complains about Selenium

Sorry if this is trivial but I did not find any advice how to fix this.
I am on Ubuntu and need PHPUnit for my Yii project.
I have installed PHPUnit twice, by downloading and moving phpunit.phar to '/usr/local/bin' and by running:
composer global require "phpunit/phpunit=3.7.*"
Now I am trying to execute my Yii PHPUnit test:
phpunit unit/DbTest.php
And what I get is:
PHP Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php):
failed to open stream: No such file or directory in
/opt/lampp/htdocs/yii-project/framework/test/CWebTestCase.php on line 12
PHP Fatal error: require_once(): Failed opening required
'PHPUnit/Extensions/SeleniumTestCase.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/opt/lampp/htdocs/yii-project/framework/test/CWebTestCase.php on line 12
So it seems that it can't find PHPUnit extension SeleniumTestCase.php. Then PHPUnit installation manual states that Selenium 'is included in the PHAR distribution of PHPUnit.'.
Can you suggest what do I do to make my Yii test work?
You need to install optional additional packages of phpunit for Yii testing to run
The packages you would need are
PHP_Invoker
DbUnit
PHPUnit_Selenium
phpunit-story
You can install them using composer by adding the following to require-dev
"phpunit/php-invoker": "*",
"phpunit/dbunit": ">=1.2",
"phpunit/phpunit-selenium": ">=1.2",
"phpunit/phpunit-story": "*"
use the following commands to install the respective dependencies
composer global require 'phpunit/phpunit-selenium=*'
composer global require 'phpunit/phpunit-story=*'
composer global require 'phpunit/dbunit=*'
composer global require 'phpunit/php-invoker=*'
What I did to fix this:
1) I have downloaded selenium extensions from:
https://github.com/sebastianbergmann/phpunit-selenium/tree/master/PHPUnit/Extensions
and placed the entire PHPUnit directory under
/opt/lampp/htdocs/yii-project/framework/test
At that point PHPUnit stopped complaining about missing SeleniumTestCase.php.
2) Then I got an error about missing file in
PHPUnit/Runner/Version.php
To fix this I commented out these lines in CTestCase.php:
//require_once('PHPUnit/Runner/Version.php');
//require_once('PHPUnit/Util/Filesystem.php'); // workaround for PHPUnit <= 3.6.11
//require_once('PHPUnit/Autoload.php');
Now I am able to run my tests.
Here is what worked for me
sudo pear config-set auto_discover 1
sudo pear channel-discover pear.phpunit.de
sudo pear install --alldeps pear.phpunit.de/PHP_Invoker
sudo pear install --alldeps pear.phpunit.de/DbUnit
sudo pear install --alldeps pear.phpunit.de/PHPUnit_Selenium
sudo pear install --alldeps pear.phpunit.de/phpunit-story
In time of replying this, it is necessary to little bit amend Manquer's response. It is necessary to edit CWebTestCase and include Selenium2TestCase.php instead of SeleniumTestCase.php and extending PHPUnit_Extensions_Selenium2TestCase instead of PHPUnit_Extensions_SeleniumTestCase. Php-invoker is not possible to install on Windows and it is not necessary.

Pyrus problems on Ubuntu 12 installing ZF2

I tried to install zend framework 2 on Ubuntu 12.04.1 64 bit but have run into difficulties.
# sudo pyrus install zf2/Zend_Framework-beta#Standard
failed mid transaction with no other previous errors that I can recall other than warnings about timezone not being set. ( Unfortuantely my terminal history has lost the original output)
Pyrus\Installer\Exception: Installation failed
Pyrus\AtomicFileTransaction\MultiException: ERROR: commit failed
Pyrus\IOException: CRITICAL - unable to complete transaction, rename of actual to backup path failed
Pyrus\AtomicFileTransaction\RuntimeException: Cannot rollback - not in a transaction
Now when I try to rerun
# sudo pyrus install -f zf2/Zend_Framework-beta#Standard
it fails with
Pyrus\Registry\Exception: Cannot retrieve package file object for package packages.zendframework.com/zend_framework, it is not installed
Uninstall just tells me that it's not installed.
I restored /usr/share/.old-php to /usr/share/php however I still get the same error.
Please help.
You can just try to download and unzip Zend Framework 2 archive into your project's library folder.
It looks like it's a problem with the metapackage according the Matthew. I'm having the same problem.
Error Installing full framework with Pyrus
So if I installed pyrus here: "/usr/share/pear/pyrus" , then should I create a directory "/usr/share/pear/pyrus/zf2" and download and unzip the full Zend Framework in zf2 and it should work?
thanks

Categories