php5enmod mcrypt with Puppet - php

Another Puppet related question.
As part of my installation with Puppet, I'm installing: -
Ubuntu 14.04.2 LTS
PHP5-FPM
Nginx
MySQL etc
As part of the PHP class I have the following: -
package {[
'php5-fpm',
'php5-mysql',
'php5-cli',
'php5-mcrypt',
'php5-curl',
]:
ensure => present,
require => Exec['apt-get update'],
}
This part works fine. No issues.
Once the server has finished doing its thing, I'm able to run: -
php5enmod mcrypt
This, again, runs without issue and mcrypt is enabled in the php5-fpm installation. The problem is arising with the following code block.
exec { 'enable-mcrypt':
command => 'php5enmod mcrypt',
path => '/usr/sbin',
require => [
Package['php5-mcrypt'],
Package['php5-fpm']
],
notify => [
Service['php5-fpm'],
Service['nginx'],
],
}
I've tried running it in various incarnations, and there are no issues regarding syntax or dependencies for it to execute.
However, when I look through the debug information I'm seeing this: -
Debug: Exec[enable-mcrypt](provider=posix): Executing 'php5enmod pdo'
Debug: Executing 'php5enmod pdo'
Notice: /Stage[main]/Php/Exec[enable-mcrypt]/returns: /usr/sbin/php5enmod: 233: /usr/sbin/php5enmod: expr: not found
Notice: /Stage[main]/Php/Exec[enable-mcrypt]/returns: /usr/sbin/php5query: 181: /usr/sbin/php5query: expr: not found
Notice: /Stage[main]/Php/Exec[enable-mcrypt]/returns: /usr/sbin/php5query: 203: /usr/sbin/php5query: find: not found
Notice: /Stage[main]/Php/Exec[enable-mcrypt]/returns: WARNING:
Notice: /Stage[main]/Php/Exec[enable-mcrypt]/returns: usage: php5enmod [ -s ALL|sapi_name ] module_name [ module_name_2 ]
Error: php5enmod pdo returned 1 instead of one of [0]
Error: /Stage[main]/Php/Exec[enable-mcrypt]/returns: change from notrun to 0 failed: php5enmod pdo returned 1 instead of one of [0]
I cannot make heads nor tails of it. It would almost appear that php5enmod is not seeing the argument that's being passed to it, hence the WARNING: usage php5enmod [ -s ALL|sapi_name ] etc...
I say this because if I run phpenmod without any arguments, that's the same error you get.
If anybody has any ideas, I'd be outrageously thankful.

It appears the correct way to do this (As referenced #BMW's comment) is to ensure that Puppet knows where the "find" command is before attempting to execute php5enmod.
My puppet configuration is below:
# Ensure Mcrypt is enabled
exec { "enablemcrypt":
path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ],
command => "php5enmod mcrypt",
notify => Service["apache2"],
require => Package["php5-common"],
}
As you can see, by adding "/bin", "/sbin", "/usr/bin" and "/usr/sbin" to the path parameter, puppet can now use the "find" command, which it seems to use internally when executing commands with arguments. php5enmod now runs correctly for me on Ubuntu 14.04 LTS.

Unfortunately, I wasn't able to get this to work as I would have liked. I'm unsure if Puppet is just not playing nicely with php5enmod, or whether there's some internal issues with php5enmod and the way it's being called by the Puppet scripts.
However, I did manage to manually create the symbolic link and restart the service with the following block of code.
file { '/etc/php5/fpm/conf.d/20-mcrypt.ini':
ensure => 'link',
target => '/etc/php5/mods-available/mcrypt.ini',
require => [
Package['php5-mcrypt'],
Package['php5-fpm'],
],
notify => Service['php5-fpm'],
}
Hopefully this helps somebody out in the future.

Related

Laravel 4: Class 'MongoClient' Not Found

I have Laravel 4 installed on WAMP and it works great with a MySQL backend.
I have successfully setup second virtual host and would like to use a MongoDB backend. After searching around I found out that Laravel does not natively connect to MongoDB and I found https://github.com/jenssegers/Laravel-MongoDB and I have been trying to set it up but I can't seem to get it right. Obviously I must be doing something wrong and I am hoping someone can help me identify what it is that I am not doing right.
I edited composer.json per the instructions:
............
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"jenssegers/mongodb": "*"
},
"autoload": {
.........
Then I ran composer update. It installed monolog 1.9.1 and swiftmailer v5.2.0 - whatever these are - successfully (a few days ago) but then threw an error after that. Today I tried to run composer update again, and it updated the two to 1.10.0 and v5.2.1 respectively and then encountered the same error. Now when I try composer update it consistently throws the same error:
Nothing to install or update
Generating autoload files
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","me
ssage":"Class 'MongoClient' not found","file":"C:\\wamp\\www\\laravel\\vendor\\j
enssegers\\mongodb\\src\\Jenssegers\\Mongodb\\Connection.php","line":132}}Script
php artisan clear-compiled handling the post-update-cmd event returned with an
error
[RuntimeException]
Error Output:
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock]
[--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-
dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [
packagesN]
What I have tried:
I have downloaded and installed the php_mongo.dll by placing it in the php ext folder and enabling it in php.ini:
; added for mongoDB connections
extension=php_mongo.dll
But this did not help.
NOTE: I would not have been able to resolve the issue completely without #Hassan 's help -- please see comments under #Hassan 's answer.
I'll provide this answer in the hopes that it may help someone else who may experience the same issue. I thought it better to give it as an answer so that it stands out.
Further search lead me here: https://github.com/jenssegers/Laravel-MongoDB/issues/36
Then here: https://github.com/leroy-merlin-br/mongolid-laravel#troubleshooting
The following command and output indicates the location of php.ini that I should have updated with the php_mongo.dll extension:
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => C:\wamp\bin\php\php5.5.12\php.ini
The WAMP tray icon however points to C:\wamp\bin\apache2.4.9\bin\php.ini -- which is what I had updated. I also checked if PHP in the CLI environment is importing the driver properly by running the following command with the output shown:
$ php -i | grep 'Mongo'
MongoDB Support => enabled
After updating the correct php.ini, I restarted apache and tried again composer update again. The error was different -- authentication -- as the username, password and database were wrong. Once those were corrected, the update completed without incident.
Your composer file looks fine, as is probably everything else. Try a "composer dumpautoload", from the docs:
If you need to update the autoloader because of new classes in a classmap package for example, you can use "dump-autoload" to do that without having to go through an install or update.
This should fix that error, after which you'll need to change your adapter in app/config/database.php to use mongodb like so:
'default' => 'mongodb',
And add mongodb to your connections too:
'connections' => array(
...
'mongodb' => array(
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => '',
'password' => '',
'database' => 'test'
),
),

Composer update ran via puppet times out

I'm using composer to manage dependencies. And basically want I want to do is automatically run composer update in puppet config when vagrant up is running.
I'm using puphpet to generate puppet files for vagrant.
I added composer::exec section in this code in the default.pp file:
if $php_values['composer'] == 1 {
class { 'composer':
target_dir => '/usr/local/bin',
composer_file => 'composer',
download_method => 'curl',
logoutput => true,
tmp_path => '/tmp',
php_package => "${php::params::module_prefix}cli",
curl_package => 'curl',
suhosin_enabled => false,
}
composer::exec { 'composer-update':
cmd => 'update',
cwd => '/var/www/myproject'
}
}
Some times I'm getting this error in output:
Error: Command exceeded timeout
Error: /Stage[main]//Composer::Exec[composer-update]/Exec[composer_update_composer-update]/returns: change from notrun to 0 failed: Command exceeded timeout
And there is no timeout property in puppet composer.
How to solve it?
Take a look at http://docs.puppetlabs.com/references/latest/type.html#exec-attribute-timeout - it is possible to set a timeout for an exec resource. If the puppet composer module does not provide an option to override that, it really should IMO. And if by a chance it is composer itself that's timing out, not puppet exec, you'd wanna try
export COMPOSER_PROCESS_TIMEOUT=600

Error! Symfony2 with KNP Snappy Bundle & WKHTML2PDF

When I go to /fileDownload I receive a 500 Internal Server Error - RuntimeException:
The process stopped because of a "0" signal.
Controller Action:
public function fileAction()
{
$html = $this->render('MyBundle:Downloads:file.html.twig', array(
'fileNumber' => '1234'
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
I've used terminal commands for WKHTMLTOPDF and it has successfully generated the PDF. It just will not work in Symfony2 app.
In my config.yml:
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
I'm assuming Symfony is issuing an exec() at some stage. You need to get the exact command line error returned. The fact it works for you in a terminal session doesn't necessarily mean it will work when a different user/process is running it.
Check permissions on wkhtmltopdf that apache or whoever is running your web server has access to run the command.
Also, check this question out wkhtmltopdf: cannot connect to X server and also the first post here: http://geekisland.org/index.php?m=05&y=11&entry=entry110518-114630
X Server is required to run certain builds of wkhtmltopdf and it is not present when running via cron or from within an apache process. If this is the case you need to use the bash wrapper in the first link above.
Be sure that wkhtmltopdf is indeed in the folder you specify, with correct permissions: /usr/local/bin/wkhtmltopdf
I am successfully using KNP Snappy Bundle with Symfony 2.0, try using RenderView instead of render when generating the html (check my code that is working):
Controller:
$html = $this->renderView('YOPYourOwnPoetBundle:thePoet:poemPDF.html.twig', array(
'poem' => $customizedPoem,
'fontType' => $fontType,
'fontSize' => $formData['fontSize'],
'fontWeight' => $fontWeight,
'fontStyle' => $fontStyle,
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.$session->get('poemTitle').'.pdf"',
)
);
I had this same issue and i finally solved it, my advice is if you installed the wkhtmltopdf lib from your OS repos then remove it, and download the static version from the google code website, and don't use version 11rc, use the version 9 static lib, it's the one that worked with me.
http://code.google.com/p/wkhtmltopdf/downloads/list
It looks like the selinux is blocking your command, I had the same issue once but I solved it by disabling the SELinux and now I'm able to generate the pdf file using wkhtmltopdf+php.
exec("/usr/local/bin/wkhtmltopdf http://www.google.com /var/www/html/google.pdf");
To disable selinux run setenforce 0,
try again and see if it works.
Re-enable it with setenforce 1
But disabling selinux is not the best solution for this, you need to extend it instead using audit2allow, it will automatically create a custom policy module that will resolve this issue,
First install audit2allo if not already installed
yum -y install policycoreutils-python
grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpd.te
checkmodule -M -m -o httpdlocal.mod httpd.te
semodule_package -o httpdlocal.pp -m httpdlocal.mod
semodule -i httpdlocal.pp
try again and see if it works
I experienced the same issue on same scenario with wkhtmltopdf. And I got rid of with the following command:
setsebool httpd_execmem on

php custom C++ module works from command line, not on webserver

I made a custom PHP module with C++ and Swig. It works from the command line, but not with my webserver:
php index.php
php-cgi index.php
Both of those work fine.
I'm using lighttpd and php. I didn't configure these in any special way. I just installed them using sudo apt-get install.
Unfortunately if I make a webpage I get this:
Fatal error: Call to undefined function minikey_to_wif() in /var/www/index.php on line 6
Calling function_exists("minikey_to_wif") returns False too.
The phpinfo() does not show my module called minikey, and shows the same configuration path as the file I edited (/etc/php5/cgi/php.ini):
extension=/path/to/php-ext/minikey/minikey.so
I also tried copying it to where the other PHP extensions seem to be installed (/usr/lib/php5/20090626+lfs/) but that didn't work either.
I've been stopping, and starting lighttpd countless times. Each time, when I run ps aux | grep php, there are no results. I've also rebooted a few times to no effect. I have no idea what's up.
OK found the answer.
The extension relied on a library which was installed in a non-standard location. Normally I set LD_LIBRARY_PATH in ~/.bashrc. But when the web server ran the extension, it didn't have that environment variable.
Fix was to create a file in /etc/ld.so.conf.d/genjix.conf with /home/genjix/usr/lib and run ldconfig as root.
Try running phpinfo() using lighty. Make sure that its pointing to the correct php.ini.
If you think this is the problem you can launch php using the -c switch from inside lighttpd.conf with "bin-path" => "/path/to/php-cgi -c /path/to/php.ini":
e.g.
fastcgi.server = (
".php" => (
(
"bin-path" => "/path/to/php-cgi -c /path/to/php.ini",
"socket" => "/tmp/php.socket",
"max-procs" => 4,
"idle-timeout" => 30,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "1000"
)
)
)
)

Installing mcrypt on Mac OSX (10.5) from PHP 5.2.8 source fails tests, what do I do?

So I'm trying to install mcrypt on my local for development. I've never compiled from source before, so please bear with me, but the short of what I've done is:
Download and install libmcrypt-2.5.8 (from source)
Download compiled mcrypt.so from http://www.viames.it/mac-os-x.html (note: the compiled gd.so seems to work fine)
Update php.ini (to include relevant lines)
Restart web sharing (apache); pages can't be loaded
Remove extension=mcrypt.so line and restart apache, pages load again)
Download PHP 5.2.8 source from php.net, and try to configure and install mcrypt from /ext/mcrypt
At this point, when I run make test, things fail.
Number of tests : 36 36
Tests skipped : 0 ( 0.0%) --------
Tests warned : 0 ( 0.0%) ( 0.0%)
Tests failed : 36 (100.0%) (100.0%)
Expected fail : 0 ( 0.0%) ( 0.0%)
Tests passed : 0 ( 0.0%) ( 0.0%)
Just in case anyway, I went ahead and did sudo make install, update php.ini, and tried to load pages. Pages loaded fine. I went to my phpinfo page, but mcrypt isn't shown there at all. I went back and forth on this a couple of times, but nothing happened still.
I'm confused about what to do now, as I'm not sure what I was supposed to do when the make tests failed, which is, I suspect, why my mcrypt isn't working at all (even if the .so file is there). I'm including the make test failed summary result below.
Any help would be greatly appreciated :)
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test for blowfish compatibility [tests/blowfish.phpt]
Bug #35496 (Crash in mcrypt_generic()/mdecrypt_generic() without proper init). [tests/bug35496.phpt]
Bug #37595 (mcrypt_generic calculates data length in wrong way) [tests/bug37595.phpt]
Bug #41252 (Calling mcrypt_generic without first calling mcrypt_generic_init crashes) [tests/bug41252.phpt]
Bug #46010 (warnings incorrectly generated for iv in ecb mode) [tests/bug46010.phpt]
Bug #8040 (MCRYPT_MODE_* do not seem to exist) [tests/bug8040.phpt]
mcrypt_cbc [tests/mcrypt_cbc.phpt]
mcrypt_cbf [tests/mcrypt_cbf.phpt]
mcrypt_create_iv [tests/mcrypt_create_iv.phpt]
mcrypt_decrypt [tests/mcrypt_decrypt.phpt]
mcrypt_ecb [tests/mcrypt_ecb.phpt]
mcrypt_enc_get_algorithms_name [tests/mcrypt_enc_get_algorithms_name.phpt]
mcrypt_enc_get_block_size [tests/mcrypt_enc_get_block_size.phpt]
mcrypt_enc_get_iv_size [tests/mcrypt_enc_get_iv_size.phpt]
mcrypt_enc_get_key_size [tests/mcrypt_enc_get_key_size.phpt]
mcrypt_enc_get_modes_name [tests/mcrypt_enc_get_mode_name.phpt]
mcrypt_enc_get_supported_key_sizes [tests/mcrypt_enc_get_supported_key_sizes.phpt]
mcrypt_enc_is_block_algorithm [tests/mcrypt_enc_is_block_algorithm.phpt]
mcrypt_enc_is_block_algorithm_mode [tests/mcrypt_enc_is_block_algorithm_mode.phpt]
mcrypt_enc_is_block_mode [tests/mcrypt_enc_is_block_mode.phpt]
mcrypt_enc_self_test [tests/mcrypt_enc_self_test.phpt]
mcrypt_get_block_size [tests/mcrypt_get_block_size.phpt]
mcrypt_get_cipher_name [tests/mcrypt_get_cipher_name.phpt]
mcrypt_enc_get_iv_size [tests/mcrypt_get_iv_size.phpt]
mcrypt_get_key_size [tests/mcrypt_get_key_size.phpt]
mcrypt_list_algorithms [tests/mcrypt_list_algorithms.phpt]
mcrypt_list_modes [tests/mcrypt_list_modes.phpt]
mcrypt_module_get_algo_block_size [tests/mcrypt_module_get_algo_block_size.phpt]
mcrypt_module_get_algo_key_size [tests/mcrypt_module_get_algo_key_size.phpt]
mcrypt_module_get_supported_key_sizes [tests/mcrypt_module_get_supported_key_sizes.phpt]
mcrypt_module_is_block_algorithm [tests/mcrypt_module_is_block_algorithm.phpt]
mcrypt_module_is_block_algorithm_mode [tests/mcrypt_module_is_block_algorithm_mode.phpt]
mcrypt_module_is_block_mode [tests/mcrypt_module_is_block_mode.phpt]
mcrypt_module_open [tests/mcrypt_module_open.phpt]
mcrypt_module_self_test [tests/mcrypt_module_self_test.phpt]
mcrypt_ofb [tests/mcrypt_ofb.phpt]
Install Xcode via the AppStore
Install MacPorts (http://guide.macports.org/#installing.macports)
Install libmcrypt using port
port install libmcrypt
Download PHP source (http://php.net/downloads.php)
Compile the extension before installing it
cd /directory/to/php/source/ext/mcrypt
phpize .
./configure \
--with-php-config=`which php-config` \
--with-mcrypt=/opt/local
make
sudo make install

Categories