Can't seem to set my php.exe path in pear.bat - php

I installed PEAR and when I try to run it, I receive this message:
PHP_PEAR_PHP_BIN is not set correctly. Please fix it using your
environment variable or modify the default value in pear.bat The
current value is: .\php.exe
In the pear.bat file that error message is generated as such:
:PEAR_PHPBIN_ERROR
ECHO PHP_PEAR_PHP_BIN is not set correctly.
ECHO Please fix it using your environment variable or modify
ECHO the default value in pear.bat
ECHO The current value is:
ECHO %PHP_PEAR_PHP_BIN%
GOTO END
At the top of the file there is a conditional set like so:
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=.\php.exe"
That's my starting point. I've changed that path to this:
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\hqp\xampp\php\php.exe"
Regardless of the change, I get the same error in the command line, as in it still thinks the value is .\php.exe. I can tweak the error message and my tweaks will appear in the command line so I'm confident this pear.bat file is being referenced.
So my assumption is, based on that condition, "%PHP_PEAR_PHP_BIN%"!="" and if that is the case, where is it being set so I can override it to my correct path? Ideas where I should look or how to troubleshoot this further?
Here's my pear.bat source code: http://codetidy.com/919/
Thanks!

I was able to override the path by removing the condition:
Replaced
IF "%PHP_PEAR_PHP_BIN%"=="" SET "PHP_PEAR_PHP_BIN=C:\hqp\xampp\php\php.exe"
with
SET "PHP_PEAR_PHP_BIN=C:\hqp\xampp\php\php.exe"
Though this solved my issue, I'd still like to know where that value was being set prior to this file. I confirmed the path was correct in the php_bin value in the pear.ini file as well, of course.

For Windows, must SET "PHP_PEAR_PHP_BIN" under user environment variable to path to php.exe. Like me, I set it to "C:\wamp\bin\php\php5.3.0\php.exe".
This will solve your problem.

For wamp on windows set environment variable as
Go to System>Advanced System Settings.
Then set environment variables as
PHP_PEAR_PHP_BIN
c:\wamp\bin\php\php5.3.13\php.exe
Save
Run cmd and type pear on command prompt.

you shall find it in user variables under environment variables in windows. I was facing the same issue, then changed the value for user variables and it worked.

continuing on in the installation the document at http://pear.php.net/manual/en/installation.checking.php under verify include paths states to run php --ini at the command line. doing this i noticed that Configuration File (php.ini) Path: was set to c:\windows (this is a widows xp machine) I thought this was strange so i went looking for the file to see what was in it. There was no php.ini file but there was a pear.ini file so i decided to look at that. It has to lines in it, the second like is where i found the path. The file read s:7:"php_bin";s:9:".\php.exe" near the end of the line i changed it to s:7:"php_bin";s:9:"C:\php\php.exe" and all was good.
Just thought i would update this as i dont like to change batch files that should not need to be changed.

change the ./php.exe to the actual path eg c:xampp\php\php.
thanks

A simple solution without going withing the environment variable of Windows.
You can edit the PEAR_ENV.reg file available after first installation of Pear. This file should be in your PHP folder. Within this file you will find the following line:
"PHP_PEAR_PHP_BIN"=".\\php.exe"
to
"PHP_PEAR_PHP_BIN"="F:\\PHP5.2\\php.exe"
Change "F:\PHP5.2" to whatever where is you PHP installation.
You can now double-click on the PEAR_ENV.reg file to setup correctly your environment variable.

Related

Make php variable/constant available to all scripts ad all sites

I have about 150 websites each on its own Apache virtual host running php7 on ubuntu 16. Each site has a config.php in the root dir with constants in it: define('MYVAR','myval');
I want to make a new constant that I will have to update every 2 months or so. I don't want to open each config and edit them. How can I have each site/virtual host be aware of this constant I want to set. I want to be available everywhere just like $_SERVER['REMOTE_ADDRESS']; is.
I do not want to create a file them symlink it to each site, thats messy. I would like to edit the apache config or edit a php config someplace to have a define() in it.
Is this possibe? or am I stuck sym linking a file or editing all my configs?
As pointed out in this link; PHP: possible to set constants in default php.ini file
You can't just invent variables in the PHP file, you'll need to auto-prepend a config file that has all the variables defined.
Ignore Below
You could store some global variables in your php.ini file.
The single php.ini file should be used by all your Apache virtual-hosts.
If you update your php.ini file and put a variable in like
my_custom_var = ABC123
Then you can access the variable with ini_get
echo ini_get('my_custom_var');
See more details on ini_get at http://php.net/manual/en/function.ini-get.php
I think you should try using OS environment variables.
Try setting the variables and then exporting them in your .profile file.
Ideally, this is where you should store sensitive credentials too. This way, even if your code is leaked, no one can get access to your existing server (never store Database or other credentials in your code)
You can either store your system variables in .profile or .bashrc file (I would recommend .profile). You can see how to set system variables here: https://unix.stackexchange.com/a/117470/209405
You can get the variables in PHP with the help of getenv($var) or with $_ENV[$var]. For more info, you can check here: http://php.net/manual/en/function.getenv.php and http://php.net/manual/en/reserved.variables.environment.php
The best non-intrusive way for me was to make sure mod_env was enabled then I added in the conf-enabled dir a conf file with the following in it
SetEnv MYLITTLEVAR thestringIwant
Then in php I can get it by:
print $_SERVER['MYLITTLEVAR'];
Tested and it works for me.
If want to make some variables globally available in PHP you need to add those variable in the apache config file.
if you're using ubuntu open /etc/apache2/apache2.conf file, And if you're using windows open httpd.conf. And add the following line.
SetEnv VARIABLE_NAME 'whatever value you want'

PHP session.save_path ignored

I was having problems with my PHP website (SuiteCRM) not being able to log users in and I found it was due to not being able to write on the sessions directory.
I am able to fix it by creating the directory /tmp/php_sessions and giving it write permissions for the Apache user www-data. I see the directory get populated with files as users log in.
However, Ubuntu Xenial is deleting my entire tmp directory on reboots, so I have to redo this all over again every time. I decided to move my save_path elsewhere.
After changing things in my php.ini file, and restarting Apache, I can check that they are effective by running this simple script:
<?php
echo ini_get("session.save_path");
phpinfo();
?>
This shows me a double confirmation of the new path, first echoing /var/tmp/php_sessions and then, in the middle of all the phpinfo information, showing the same value as both Local Value and Master value for directive session.save_path.
BUT the directory that php is using is still the first one, /tmp/php_sessions! It seems that my setting is being ignored.
Am I overlooking something? Where could that old setting be buried? Or how can I make the new one effective?
(P.S. - I am not using a redis handler as in another similar SO question)
Ok, I solved my own problem and the general answer is as follows:
There are two more things that can be changing the path and need to be checked,
the PHP code of the application might be changing the ini directive, search the code for ini_set(session.save_path
the PHP code might be using the session_save_path PHP command to override the ini. Search the code for that also (and notice the two underscores _!)
And the specific answer for my case was that SuiteCRM uses session_save_path command to set its path with a value coming from the file config.php found at the web root. That's where I found the old setting, and changing it solved my problem (for good, I hope).

Cannot get browscap to load on OSX no matter which version I use or where I put it

I am trying to get the following code to run:
$browser = get_browser(null, true);
print_r($browser);
The error that I get is as follows:
Warning: get_browser() [function.get-browser]: browscap ini directive not set in /Applications/XAMPP/xamppfiles/htdocs/series/firstfile/index.php on line 3
I am running OSX 10.8.4 with XAMPP. The browscap info in my php.ini file is as follows:
[browscap]
;browscap = /Applications/XAMPP/xamppfiles/etc/browscap.ini"
I have also tried the following paths:
/Macintosh HD/Applications/XAMPP/xamppfiles/etc/browscap.ini
I downloaded and placed the browscap.ini file myself into that directory and have also tried referencing it from other locatations in case it was a permission issue or something.
I am assuming that the problem is with how I write my path but I just cant find a way to get XAMPP to accept it and when you go to phpinfo() it is listed under 'core' as browscap - no value.
Obviously I have been restarting Apache etc. with each change to ensure that the php.ini is refreshed.
All of the information I can find seem to pertain to Windows rather than Mac so I am struggling!
I wonder what kind of valuable information you expect to get from this function.
But whatever it is, please be advised that it is considered bad practice, because you are essentially practicing server based client sniffing, and the only base of information is the user agent string, which can be anything and does not need to represent the real situation. Also, information like "javascript" can only represent the coded ability of the client, not the current configured abilities, which can be less.
If you still think the function to be of any use, you have to solve the task of getting a copy of that "browscap.ini" file this function wants to use, and you have to constantly update this file to include new browser versions.
There is a link to a file source on the documentation page of get_browser(). Download a file and point the INI setting to that location. Make sure to activate it by removing the semikolon.
I gave you the instructions to solve your problem,I think this will help you. your file path was absolutely right but you forgot to remove the semicolon and the double quotations mark [browscap]
;browscap = /Applications/XAMPP/xamppfiles/etc/browscap.ini"
download the file by clicking the link and put it in the file path which I explains you below
http://tempdownloads.browserscap.com/stream.asp?PHP_BrowsCapINI
Yeah, it seems XAMPP on Mac OSX installs differently, and you don't specify the root directory. First, find the file 'php.ini' installed in the following location: /Applications/XAMPP/xamppfiles/etc/php.ini Second, 'php.ini' is write protected in this location, so copy it to desktop thus allowing you to alter it. From desktop open in TextEdit and look for text reading '[browscap]' (we'll come back to this). Third, download a copy of file 'php_browscap.ini' from the Browser Capabilies Project.
Mac OSX (cont.) Fourth, change filename from 'php_browscap.ini' to 'browscap.ini'. Place a copy in the following location:** /Applications/XAMPP/xamppfiles/etc/extra/browscap.ini Fifth, now go back and update file 'php.ini' with the new location of 'browscap.ini' to read as follows: [browscap] browscap = /Applications/XAMPP/xamppfiles/etc/extra/browscap.ini Sixth, save 'php.ini' and copy from desktop back into original location: /Applications/XAMPP/xamppfiles­/etc/php.in
Seventh, restart XAMPP. ** Note: I think the location of 'browscap.ini' may be somewhat arbitrary. What seems most important is the pathname that is listed in file 'php.ini' under [browscap] (in my case, browscap = /Applications/XAMPP/xamppfiles­/etc/extra/browscap.ini). Good luck fellow Mac XAMPP users!

Netbeans Unit Testing

I am using Netbeans 7.2.1 and am having trouble with the PHP unit testing component.
I have created a .php file called 'Calculator.php'. When I try and create a Unit test for this file, I get the following error:
'"#php_bin#"' is not recognized as an internal or external command,
operable program or batch file.
Am I correct in saying that the problem is that the path to my PHP.exe is not correct in my environment variables?
Can I please have some help to fix this?
Thanks in advance.
EDIT
I have changed the System Environment Variable as follows:
Variable name: "#php_bin#" and Variable value: "C:\Program Files (x86)\PHP\php.exe"
This however does not fix the problem. Can I please have some help to get this working?
I think you are right, the error deals with the path specified in Enviorment variable, You should replace #php_bin# by the path to the php binary. I guess PEAR or PHPUnit installer was supposed to do that.
check out this Link and follow instructioins.

Windows XP path problem

My Environmental Variables (& I crosschecked every possible place in the Registry) show my PHP include path as: "C:\PHP\" --and PHP (5.2.9-2) works fine on the system, so that is correct. However, running
ini_get("include_path")
shows the path as "C:\PHP5\". This causes problems with PEAR, etc. I've searched the system (i.e. php.ini files, httpd.conf, & everywhere else I can think of--there are no .htaccess files) & can find nothing that points at PHP5. Where in the world is this coming from??
Try searching for the literal PHP5 using a grep search tool (like windows grep http://www.wingrep.com/) it will take a while, but I think it's the best approach after you've checked all config files and environment variables.
Cheers
If you run a script with a call to phpinfo() PHP will tell you where the values come from:
<php
phpinfo();
?>
The top table will tell you what php.ini files it's reading and you'll find the value of the include_path directive in the Core table.
Something could be setting it using ini_set.
Or, after running the aforementioned grep on the whole system, you can try these:
Debug PHP to see what causes this.
Use Filemon from Sysinternals to see what files PHP is accessing.
This isn't really an answer to your problem however if you install WAMP or XAMPP you can usually avoid all of these annoying configuration issues.

Categories