PEAR not recognising correct PHP directory - php

I just installed PEAR but it is using an incorrect path for PHP, /usr/bin/php, rather than the correct one, /usr/bin/php74.
This means it won't run at all, so I can't even run pear uninstall pear, because it (like any other pear command) just errors out with /usr/bin/pear line 28: /usr/bin/php: No such file or directory
How do I fix this? Can I just rm -rf /usr/bin/pear and then reinstall with pacman?
(For reference I am using Arch Linux)

I was curious about this so I took a bit of fun time to play with pear.
So, first I installed it through my favorite - and not deprecated yet - AUR helper.
$ my-awesome-helper -S php-pear
Then I tried to install XML_Util (as an example)
# pear install XML_Util
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
downloading XML_Util-1.4.5.tgz ...
Starting to download XML_Util-1.4.5.tgz (19,191 bytes)
......done: 19,191 bytes
install ok: channel://pear.php.net/XML_Util-1.4.5
# echo $?
0
From here, I was sure that it is working so I uninstalled it.
# pear uninstall XML_Util
uninstall ok: channel://pear.php.net/XML_Util-1.4.5
Now, how can we break it or change the location of the PHP binary?
The way to go is to follow the documentation. For our case, it is located here.
It first states:
PEAR has a number of configuration options that you can change. Getting an overview of them is as easy as issuing a
$ pear config-show
I did it a bit more precisely:
# pear config-show | grep bin
PEAR executables directory bin_dir /usr/bin
PHP CLI/CGI binary php_bin /usr/bin/php
Signature Handling Program sig_bin /usr/bin/gpg
Yet another question: How to change the value of php_bin?
Let's get back to the documentation. It now states:
Reading single values is accomplished by using config-get. The following command will show you where all the .php files of your installed pear packages reside.
$ pear config-get php_dir
/usr/share/pear
Changing a value is as easy as retrieving it:
$ pear config-set preferred_state beta
config-set succeeded
Therefore, I changed it to something that is not the PHP binary.
# pear config-set php_bin /tmp/my-awesome-bin
config-set succeeded
Let's check the change:
# pear config-get php_bin
/tmp/my-awesome-bin
We are now sure that we changed the PHP binary location.
Let's rerun our first command:
# pear install XML_Util
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
downloading XML_Util-1.4.5.tgz ...
Starting to download XML_Util-1.4.5.tgz (19,191 bytes)
......done: 19,191 bytes
install ok: channel://pear.php.net/XML_Util-1.4.5
It's not broken. Weird !?
From here, I thought, I did something wrong so I rechecked everything I did and I indeed followed the documentation without success.
My last resort is always to look at the file or executable to try to understand its behavior. So I did this time too.
It turns out that pear is a simple Shell script. At the time I'm writing this it (/usr/bin/pear) looks like this:
#!/bin/sh
# first find which PHP binary to use
if test "x$PHP_PEAR_PHP_BIN" != "x"; then
PHP="$PHP_PEAR_PHP_BIN"
else
if test "/usr/bin/php" = '#'php_bin'#'; then
PHP=php
else
PHP="/usr/bin/php"
fi
fi
# then look for the right pear include dir
if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then
INCDIR=$PHP_PEAR_INSTALL_DIR
INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR"
else
if test "/usr/share/pear" = '#'php_dir'#'; then
INCDIR=`dirname $0`
INCARG=""
else
INCDIR="/usr/share/pear"
INCARG="-d include_path=/usr/share/pear"
fi
fi
exec $PHP -C -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" $INCDIR/pearcmd.php "$#"
Here is the relevant part regarding your question:
if test "x$PHP_PEAR_PHP_BIN" != "x"; then
PHP="$PHP_PEAR_PHP_BIN"
else
if test "/usr/bin/php" = '#'php_bin'#'; then
PHP=php
else
PHP="/usr/bin/php"
fi
fi
Basically:
If the PHP_PEAR_PHP_BIN environment variable is declared. Use it.
Otherwise, if the php_bin variable (pear config) is set, and is equal to /usr/bin/php use php as executable.
If both (1) and (2) failed; use the /usr/bin/php binary as executable.
That explains a lot about why it is still working.
So, I tried again to break it again but this time with the PHP_PEAR_PHP_BIN environment variable.
# PHP_PEAR_PHP_BIN=/tmp/my-awesome-bin pear install XML_Util
/usr/bin/pear: Zeile 28: /tmp/my-awesome-bin: Datei oder Verzeichnis nicht gefunden
This time I have the same error like the one you posted. Meaning that I could break pear and reproduce your issue.
Now the solution-s to your problem after understanding what is happening:
You can manually run export PHP_PEAR_PHP_BIN=/usr/bin/php74 before running pear. This solution is temporary and user-wide.
You can put the export PHP_PEAR_PHP_BIN=/usr/bin/php74 line into your ~/.bashrc file. This solution is persistent and user-wide.
You can put the PHP_PEAR_PHP_BIN=/usr/bin/php74 line into your /etc/environment file. This solution is persistent and system-wide.
You can put the export PHP_PEAR_PHP_BIN=/usr/bin/php74 line into /etc/profile.d/my_php_pear_solution.sh file. This solution is persistent and system-wide.
You can create a /usr/local/bin/my-pear (assuming that /usr/local/bin is in your $PATH) which handles this; given it one of - or all - the 3 executable bit and finally use the my-pear CLI instead of the official pear one. This solution is persistent and system-wide.
#!/usr/bin/env bash
# Set the location of our PHP binary.
export PHP_PEAR_PHP_BIN=/usr/bin/php74
# Start pear.
/usr/bin/pear ${#}
All of those may work. It's just a matter of scope, usability, and permission - somehow.
I hope this helps. Don't be afraid to ask if something is not clear.
P.S.: Welcome around here :-)

Related

Disabling xdebug when running composer

When running composer diagnose, I get the following error :
The xdebug extension is loaded, this can slow down Composer a little.
Disabling it when using Composer is recommended.
How can I disable xdebug only when I'm running Composer?
Update: For Xdebug 3+:
As of Xdebug 3, it is possible to disable the Xdebug completely by setting the option xdebug.mode to off, or by setting the environment variable XDEBUG_MODE=off.
It is very easy to disable Xdebug just for composer, by aliasing composer.
alias composer='XDEBUG_MODE=off \composer'
OR
alias composer='php -dxdebug.mode=off $(where composer | fgrep -v composer: | head -1)'
You can add the alias to your $HOME/.bashrc to make it permanent.
Update: For Xdebug 1.3 - 3.0.0 :
The issue has been fixed in Composer 1.3. Update composer to the latest version by executing composer self-update, instead of trying the following workaround.
For Xdebug < 1.3
Here is my modification of #ezzatron's code. I have updated the script to detect ini files from phpinfo output.
#!/bin/sh
php_no_xdebug () {
temporaryPath="$(mktemp -t php.XXXX).ini"
# Using awk to ensure that files ending without newlines do not lead to configuration error
php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' | grep -v xdebug > "$temporaryPath"
php -n -c "$temporaryPath" "$#"
rm -f "$temporaryPath"
}
php_no_xdebug /usr/local/bin/composer.phar $#
# On MacOS with composer installed using brew, comment previous line
# Install jq by executing `brew install jq` and uncomment following line.
# php_no_xdebug /usr/local/Cellar/composer/`brew info --json=v1 composer | jq -r '.[0].installed[0].version'`/libexec/composer.phar $#
This command will disable the PHP5 Xdebug module for CLI (and thus composer) :
sudo php5dismod -s cli xdebug
It removes the xdebug.ini symlink from /etc/php5/cli/conf.d/
This was suggested on http://blog.lorenzbausch.de/2015/02/10/php-disable-xdebug-for-cli/
Note that for Ubuntu 16.04 you probably need to run it like this:
sudo phpdismod -s cli xdebug
I don’t think there is an option to configure PHP so it can load different configurations according to the targeted script. At least, not without duplicating .ini files...
However, you can add thoses options when running composer with php:
php -n -d extension=needed_ext.so composer.phar
-n will tell PHP to ignore any php.ini. This will prevent xdebug from loading for this very command.
-d options permits you to add any option you want (for exemple, activate needed_ext.so). You can use multiple -d options. Of course, this is optional, you might not need it.
Then you can create an alias, to make it sugary again.
A typical solution (because composer needs json):
php -n -d extension=json.so composer.phar
greg0ire > my solution, based on that:
#!/bin/bash
options=$(ls -1 /usr/lib64/php/modules| \
grep --invert-match xdebug| \
# remove problematic extensions
egrep --invert-match 'mysql|wddx|pgsql'| \
sed --expression 's/\(.*\)/ --define extension=\1/'| \
# join everything together back in one big line
tr --delete '\n'
)
# build the final command line
php --no-php-ini $options ~/bin/composer $*
alias composer=/path/to/bash/script.sh
It looks ugly (I tried and failed to do that with xargs), but works… I had to disable some extensions though, otherwise I get the following warnings:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: undefined symbol: mysqlnd_connect in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_mysql.so' - /usr/lib64/php/modules/pdo_mysql.so: undefined symbol: pdo_parse_params in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_pgsql.so' - /usr/lib64/php/modules/pdo_pgsql.so: undefined symbol: pdo_parse_params in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/wddx.so' - /usr/lib64/php/modules/wddx.so: undefined symbol: php_XML_SetUserData in Unknown on line 0
You can disable Xdebug setting an environment variable:
XDEBUG_MODE=off composer install
It's available using XDebug 3.
By creating an alias you'll suppress that composer xdebug error message.
Just add this line to your ~/.bash_aliases within your system and it should work flawlessly.
alias composer="php -n /usr/local/bin/composer"
Reload the shell to make the new alias composer available.
source ~/.bash_profile
USAGE:
$ composer --version
NOTE:
You don't necessarily need to use any other parameter.
Depending on your system you might have a .bashrc instead of .bash_profile.
UPDATE:
As #AlexanderKachkaev mention in the comments it's worth nothing to add the memory_limit as follows to avoid crashing im some situations:
alias composer="php -d memory_limit=-1 -n /usr/local/bin/composer"
I came up with an answer that works pretty well for OSX, and could probably be adapted for any PHP version that loads its extensions using individual .ini files in the "additional ini dir":
#!/bin/sh
function php-no-xdebug {
local temporaryPath="$(mktemp -t php-no-debug)"
find /opt/local/etc/$1/php.ini /opt/local/var/db/$1/*.ini ! -name xdebug.ini | xargs cat > "$temporaryPath"
php -n -c "$temporaryPath" "${#:2}"
rm -f "$temporaryPath"
}
alias composer="php-no-xdebug php56 ~/bin/composer"
I usually create a shell script per project, since every project has another PHP version. It's in a /bin/ directory next to composer.phar and composer.json and I run it as ./bin/composer in my project directory.
It looks like this (for php56)
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
COMPOSER_DISABLE_XDEBUG_WARN=1 /opt/local/bin/php56 \
-d xdebug.remote_enable=0 -d xdebug.profiler_enable=0 \
-d xdebug.default_enable=0 $DIR/../composer.phar "$#"
The -d options effectively disable xdebug. The COMPOSER_DISABLE_XDEBUG_WARN=1 part disables the warning composer issues.
Disabling the xdebug extension is preferred (see composer troubleshooting), but I personally like the simpler script.
Some timings on my machine:
2
Run with xdebug and ini-enabled: 1m33
Run with xdebug but ini-disabled: 0m19
Run without xdebug: 0m10
If you use PHPStorm, the latest release (2016.2) comes with a feature to enable XDebug for CLI scripts on-demand, which means you can simply turn off XDebug globally on your development machine. The IDE will enable it on the fly when it is needed by code inside your projects.
https://blog.jetbrains.com/phpstorm/2016/06/xdebug-on-demand-for-cli-php-scripts-in-phpstorm-2016-2-eap/
PhpStorm 2016.2 introduces Xdebug On Demand mode where you can disable Xdebug for your global PHP install, and PhpStorm will only enable it when it needs to — when you’re debugging your scripts, or when you need code coverage reports.
You need to edit your PHP Interpreters preferences to include the path to XDebug, as described in the linked article.
To me this seems like the perfect solution, as I only usually want XDebug while I'm in the IDE.
However XDebug does have other potential uses when you are "offline" e.g. extended stack dumps in error logs, which you would lose by turning it off globally. Of course you shouldn't have XDebug enabled on production, so this would be limited to use cases like beta-testing or automated-testing CLI scripts in development.
Rather than muddle with temporarily enabling or disabling the PHP module, when you might have concurrent processes using PHP (for example as part of a CI pipeline), you can tell PHP to point at a different module loading directory.
While this is similar to some of the solutions mentioned above, this solves a few edge cases, which is very useful when being used by Jenkins or other CI runner which runs tests on the same machine concurrently.
The easiest way to do this is to use the environment variable PHP_INI_SCAN_DIR
Using this in a script or build task is easy:
export PHP_INI_SCAN_DIR=/etc/php.d.noxdebug
php composer install
Of course you would want to prepare /etc/php.d.noxdebug first, doing something like:
mkdir /etc/php.d.noxdebug
cp /etc/php.d/* /etc/php.d.noxdebug
rm /etc/php.d.noxdebug/xdebug.ini
This means you have an environment similar to the old php environment, with only one module missing. Meaning you don't need to worry about needing to load the phar/json modules as you would with the php -n solution.
Direct manipulation of PHP config
Here's my contribution based on a Homebrew-installed PHP installation on Mac OS X.
It's a shell-script wrapper, designed to be saved as an executable file at /usr/local/bin/composer, with the Composer binary at /usr/local/bin/composer.phar:
#!/bin/sh
sed -i '' -e 's:zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":;zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":' /usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
/usr/local/bin/php /usr/local/bin/composer.phar "$#"
sed -i '' -e 's:;zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":zend_extension="/usr/local/opt/php55-xdebug/xdebug.so":' /usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
Theory of Operation
The wrapper script:
uses sed to temporarily modify the configuration file, disabling Xdebug (line 2)
executes Composer, passing through args to the command (line 3)
uses sed to restore the configuration file, re-enabling Xdebug (line 4)
The script is coupled to an OS X/Homebrew installation of PHP 5.5. The paths should be adjusted to work with other PHP versions and other operating systems' and package managers' directory layouts. Note also that some versions of sed do not need the empty-string argument following the -i option.
Caveat Utilitor
The script is straightforward, in that it works directly on the main PHP configuration files, however this is also a drawback: Xdebug will also be disabled for any scripts that happen to be executed concurrently with this script.
In my development environment, this is an acceptable trade-off, given that Composer is executed manually and only occasionally; however you may not want to use this technique if executing Composer as part of an automated deployment process.
I came up with a solution for the Windows-based Composer installer - it should work for any Composer installation, it just basically makes a copy of the loaded INI file and comments out the xdebug zend extension, then loads that configuration file when it runs composer.
I've opened an issue to see if they'd like to integrate this change:
https://github.com/composer/windows-setup/issues/58
You can find my instructions and code there.
As noted in Joyce's answer, this issue no longer exists in the latest version of Composer.
The Composer documentation has been updated to note this. It details how you can enable xdebug with Composer (if required).
You can update your version of Composer by utilising self-update.
On my Mac I had to do: sudo php /opt/local/bin/composer self-update
Further details about this in the context of a Homebrew PHP install can be found in this issue.
Creating an alias for composer to disable xdebug and prevent memory errors:
Add this line to your ~/.bash_profile
alias composer='php -d xdebug.profiler_enable=0 -d memory_limit=-1 /usr/local/bin/composer'
Restart the terminal to make the new alias available.
In most cases you do not need xdebug on CLI mode. If this is acceptable for you than you can configure cli and cgi differently.
So if you make php-cli.ini and conf-cli.d near exiting php.ini file than you can configure cli and cgi differently (for cgi it would be php.ini and conf.d). Just do not put xdebug.ini into conf-cli.d.
If you install composer using brew on OS X
You can use this alias:
alias composer="php -n $(cat $(which composer) | grep composer.phar | awk '{print $7}')"
My quick solution for a macports installation, with multiple versions of PHP was to write this simple shell wrapper for Composer:
/user/local/bin/composer-nodebug.sh
#!/bin/bash
sudo mv /opt/local/var/db/php53/xdebug.ini /opt/local/var/db/php53/xdebug.NOT
sudo mv /opt/local/var/db/php54/xdebug.ini /opt/local/var/db/php54/xdebug.NOT
sudo mv /opt/local/var/db/php55/xdebug.ini /opt/local/var/db/php55/xdebug.NOT
composer $1 $2 $3 $4 $5 $6 $7
sudo mv /opt/local/var/db/php53/xdebug.NOT /opt/local/var/db/php53/xdebug.ini
sudo mv /opt/local/var/db/php54/xdebug.NOT /opt/local/var/db/php54/xdebug.ini
sudo mv /opt/local/var/db/php55/xdebug.NOT /opt/local/var/db/php55/xdebug.ini
Then run any composer commands like so:
sudo composer-nodebug.sh update
Drawbacks:
requires sudo (unless you chmod the INI files)
if you kill it mid-way the INI files are modified
will require future PHP versions added.
while it's running other PHP processes are affected
Not elegant, but simple.
(Windows)
Based on documentation I use environment variable PHPRC, so I can choose which INI file shloud be loaded, thus I can choose whether I want to enable or disable Xdebug before executing a command (like composer install).
I have two INI files, one with Xdebug enabled (php-xdebug.ini) and one with Xdebug disabled (php.ini - it's also default one).
I use some batches (placed in location which is included in PATH environment variable, so it can be executed from anywhere):
To enable Xdebug I call xon.bat:
#ECHO OFF
set PHPRC=C:/path-to-php/php-xdebug.ini
To disable Xdebug I call xoff.bat:
#ECHO OFF
set PHPRC=
By calling php --ini I can check which INI file was loaded.
Alternatively you can use environment variable PHP_INI_SCAN_DIR in which you set a path to directory from where additional INI files will be loaded. Advantage is that you can load multiple INI files.
Here is my quick solution to get rid off the Xdebug warning on PHP5-cli version. I have removed the support of Xdebug for PHP5-cli on Ubuntu 14.04.
cd /etc/php5/cli/conf.d/
sudo rm 20-xdebug.ini
Now no more Xdebug warning on PHP5-cli.

Php Pear Remote-Install "Error: remote-install expects either option "remoteconfig" be set, or remote_config configuration variable be used"

I am setting up PHP and Pear Remote install on my local server.
As per the instructions here: http://pear.php.net/manual/en/installation.shared.php
I have 'setup' the remote configuration using this, obviously replacing the details with my FTP details.
$ pear -c remote.conf config-set remote_config \
ftp://user:pass#myremotehost.com/.pearrc
remote.conf
a:13:{s:7:"php_dir";s:25:"/home/bentstuart/pear/php";s:8:"data_dir";s:26:"/home/bentstuart/pear/data";s:7:"www_dir";s:25:"/home/bentstuart/pear/www";s:7:"cfg_dir";s:25:"/home/bentstuart/pear/cfg";s:7:"ext_dir";s:25:"/home/bentstuart/pear/ext";s:7:"doc_dir";s:26:"/home/bentstuart/pear/docs";s:8:"test_dir";s:27:"/home/bentstuart/pear/tests";s:9:"cache_dir";s:27:"/home/bentstuart/pear/cache";s:12:"download_dir";s:30:"/home/bentstuart/pear/download";s:8:"temp_dir";s:26:"/home/bentstuart/pear/temp";s:7:"bin_dir";s:21:"/home/bentstuart/pear";s:10:"__channels";a:3:{s:12:"pecl.php.net";a:0:{}s:5:"__uri";a:0:{}s:11:"doc.php.net";a:0:{}}s:13:"remote_config";s:92:"IGZ0cDovL3VzZXI6MTgwNDc2MF9hZG1pbkB3aWtpcHJvamVjdC5teXByZXNzb25saW5lLmNvbS9wZWFyLy5wZWFycmM=";}
Then via the terminal pear remote-install
I get:
Error: remote-install expects either option "remoteconfig" be
set, or remote_config configuration variable be used
As you can see the remote.conf has been configured, perhaps the remote.conf needs to be in a specific folder that pear looks for it? the documentation on remote-install is very slim.
I would be delighted to hear from anyone whom has successfully installed pears remote-install package.
I am doing it this way obviously because I don't have SSH access and need pear packages.
Try to pass the remote configuration to your install command:
$ pear -c remote.conf remote-install ....

Installing phpDocumentor via PEAR, "command not found"

I'm having trobule installing phpDocumentor via PEAR on a CentOS machine and I don't even know if this is pear or php related.
Here are the commands that I executed and their output:
# pear -v install phpdoc/phpDocumentor
## http://pastebin.com/2ijRG9KW
# /usr/local/bin/phpdoc
-bash: /usr/local/bin/phpdoc: No such file or directory
# tree -a -h /usr/local/lib/php/phpDocumentor/
## http://pastebin.com/NjynYKPL
I've included the tree command because I'm thinking something is not OK there...
At first glance, is this a PEAR or phpDocumentor issue?
Edit
Tried
# whereis phpdoc
phpdoc: /usr/local/bin/phpdoc
But
# cd /usr/local/bin
# ls -l | grep -i phpdoc
lrwxrwxrwx. 1 root root 48 Nov 23 21:46 phpdoc -> /usr/local/lib/php/phpDocumentor2/bin/phpdoc.php
-rwxr-xr-x. 1 root root 1039 Nov 24 21:31 .tmpphpdoc*
Guess what...
-bash: cd: /usr/local/lib/php/phpDocumentor2: No such file or directory
But there is a phpDocumentor folder (instead of phpDocumentor2) whose tree is available on this pastebin
I encountered the same issue and found there was no phpdoc link in my folder /usr/local/bin
To remedy the problem, I used pear config-show to allow me to view where the PEAR Bin directory is and then created a symbolic link that the phpdoc file in that location.
My PEAR Bin directory is set to: /usr/local/Cellar/php55/5.5.8/bin/
My Local Bin directory is set to: /usr/local/bin
To create the link:
ln -s /usr/local/Cellar/php55/5.5.8/bin/phpdoc /usr/local/bin/phpdoc
You can use pear config-show to see what directory it uses as its bin_dir, which is where the PEAR installer puts its "binaries". I had thought that the main Linux distributions had preconfigured their PEAR setups to use /usr/bin as the right location, so you might try /usr/bin/phpdoc. Granted, /usr/bin is almost always in your default PATH, so just trying phpdoc along should usually be sufficient.
That memory limit error from the PEAR installer means that the PEAR installer itself crashed while attempting to install phpDocumentor. You'll need to edit your php.ini file to increase the value of the memory_limit parameter. It looks like right now it's defaulted to a tiny 8MB. I'd suggest at least 256MB unless this is a small/old computer. You should then try a reinstall (pear install --force phpdoc/phpdocumentor). I expect the --force will be necessary since PEAR might think it had installed it successfully already. If install gives trouble, then try update --force instead.
In the same folder where I've executed pear install I found an error_log file:
[23-Nov-2013 22:27:54 UTC] PHP Fatal error: Allowed memory size of
33554432 bytes exhausted (tried to allocate 8192 bytes) in
/usr/local/lib/php/PEAR/Installer.php on line 580
Gotcha.

installing PHP module from Elastic Beanstalk

I am trying to configure my AWS Elastic Beanstalk to work with mongo, all I need to do is install the mongo driver for PHP and update the php.ini file
To do this, usually I would ssh into the EC2 and run:
sudo pecl install mongo
But this would require using a custom AMI which isnt the best way to go.
It is better to use config files to install the software required onto the standard AMI.
So to do this, I have done the following:
created directory .ebextensions
created file mongo.config
in it I have put the following:
packages:
pecl: install mongo
However upon deployment, I get the following error:
"option_settings" in one of the configuration files failed validation. More details to follow.
and
'null' values are not allowed in templates
So I am wondering how this config file needs to be laid out in order to install the mongo extension?
I have read the info here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
but I am not quite understanding how to do this specific task
Help would be appreciated , thanks! :)
pecl is not a valid package manager on Amazon Linux and therefore cannot be used under the packages key of an .ebextensions config.
To install a PECL package it is enough to add a single command under the commands key. To avoid that Beanstalk tries to install the extension twice on follow-up deployments add a PHP console command to the test key that checks if the extension is already installed:
commands:
install_mongo_driver:
command: pecl install mongo
test: "php -r \"exit(extension_loaded('mongo') ? 1 : 0);\""
If the test result is true, i.e. exit(0), then the command gets executed - otherwise not. Please note that a exit code of 0 means "No errors" in a shell context.
See also the description at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands.
I have figured it out and thought I would share what I found. Thanks to Hudku (http://blog.hudku.com/2013/02/innocuous-looking-evil-devil.html#elastic-beanstalk.config) for the excellent article:
1) Create myapp.config
2) enter the following into it
packages:
yum:
dos2unix: []
container_commands:
01-command:
command: rm -rf /myapp/ebextensions
02-command:
command: mkdir -p /myapp/ebextensions
03-command:
command: cp -R .ebextensions/* /myapp/ebextensions/
04-command:
command: dos2unix -k /myapp/ebextensions/mongo.sh
05-command:
command: chmod 700 /myapp/ebextensions/mongo.sh
06-command:
command: bash /myapp/ebextensions/mongo.sh
Then create mongo.sh file and put in it something like:
#!/bin/bash
if [ ! -f /mongostatus.txt ];
then
pecl install mongo
echo "mongo extension installed" > /mongostatus.txt
apachectl restart
fi
This will install mongo php extension and restart apache so the install takes affect.
I just accomplished the same thing thanks to the answer above, and figured out it can be done with less lines and less files for those interested...
# ~/project/.ebextensions/project.config
# Logger messages can be viewed in /var/log/messages
files:
"/tmp/test.sh":
content: |
# This file will be created and can then
# be executed by a command call below.
logger TEST FILE CALLED
commands:
01-command:
command: logger CALLING TEST FILE; sh /tmp/test.sh;

sudo: pear: command not found

I have snow leopard which apparently has php with pear pre-installed. I enabled php but could not find any signs of PEAR. So I have installed it and now phpinfo() shows its installation
include_path .:/usr/lib/php/share/pear
Still when I type in any pear command
$ sudo pear
I get an error: sudo: pear: command not found
What am I missing?
Many ways to skin this cat, but I would type this if you have locate installed (which you probably do):
$ locate bin/pear
That should list one or more things, one of which will look like the path to pear. Let's say it says something like /usr/local/bin/pear. Then your next command is:
$ sudo /usr/local/bin/pear
Two caveats come to mind:
It's possible that locate will list multiple executable pear files. If that's the case, it may be important to pick the right one based on which PHP you're using.
You may want to add the directory where pear is located to your PATH environment variable.
You need to update your system $PATH variable in order for the pear command to work. Edit the bash profile file using the following(if you have textmate):
mate ~/.bash_profile
and add in this line:
export PATH=/usr/local/pear/bin:$PATH
reload your terminal after that and it should work now
Edited:
Thanks for highlighting my mistake trott. I have changed the path to locate where the bin should roughly be(depending on where one chooses to install it)
If you have installed pear directly on PHP (MAMP, for example) you should copy pear to /usr/local/bin:
cp /php5.3.2/pear /usr/local/bin/pear
then export var PATH, and test with "pear" in the shell.
I had a similar issue and required updating secure_path in sudoers as it overrides user's $PATH.
Check for secure_path on sudo
[root#host ~]# sudo -V | grep 'Value to override'
Value to override user's $PATH with: /sbin:/bin:/usr/sbin:/usr/bin
If $PATH is being overriden us visudo and edit /etc/sudoers
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

Categories