Hello all.
I am experimenting some problems, bad problems, trying to run my php script using the command line prompt.
I try to connect to a mysql database with this script but php says that mysql_connect function does not exists.
I know that I compile php with mysql extension because I use it with apache and there it runs fine. I also check, to be sure, phpinfo() output and effectively the mysql extension is there, listed.
During my long investigation I discover that php running from the command line does not load the php.ini file just because the interpreter can’t find it.
take a look:
carlosnblnx:/usr/local/lib # php --ini
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
So it obviously can’t find the extensions folder because does not locate the php.ini file saved in /etc/php5/cli. :S
Here is the pretty simple code that I’m trying to run.
Using web interface works fine because apache knows where the apache php.ini
<?php
echo "hola mundo
;";
mysql_connect("localhost","bla","bla");
// phpinfo();
?>
and its output
carlosnblnx:/home/carlos/development/php/fill_table # php test.php
hola mundo
;PHP Fatal error: Call to undefined function mysql_connect() in /home/carlos/development/php/fill_table/test.php on line 3
so I wonder how can I change the prefix or the default path to load my php.ini from explicit php call from command line.
Thanks!
I wonder why you needed to build your own php because the OpenSUSE version works fine.
$ php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/conf.d
Additional .ini files parsed: /etc/php5/conf.d/bz2.ini,
...
Unfortunately I “broke” my php installation compiling first from the source(I was making experiments) and later, without running “make uninstall”, the rpm version that probably originate this problem.
So why not install the OpenSUSE php5 package and then needed module packages and forget about your homebrew version?
You can also get the CLI interpreter with php5, as in
php5 --ini
wow!
only trying with “php5 test.php” works!. I always thought that php was just an alias of php5, now I see that I was wrong. However I still want to know how to do this change for future modifications .
Thank you ken_yap!
So why not install the OpenSUSE php5 package and then needed module packages and forget about your homebrew version?
I already do that removing just the php5 interpreter with the “rpm -e” command and reinstalling it from the opensuse repositories using yast.
The same result.
I was checking php-config tutorials and seems impossible to reset the defualt dir, only recompiling as a parameter of ./configure (–prefix “the/directory/”) is resettable.
carlosnblnx:/usr/bin # php-config
Usage: /usr/local/bin/php-config [OPTION]
Options:
--prefix [/usr/local]
--includes -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib]
--ldflags ]
--libs -lcrypt -lcrypt -lrt -lresolv -lm -ldl -lnsl -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt ]
--extension-dir [/usr/local/lib/php/extensions/no-debug-non-zts-20060613]
--include-dir [/usr/local/include/php]
--php-binary [/usr/local/bin/php]
--php-sapis [cli cgi]
--configure-options --with-rrdtool=/usr/bin/rrdtool --with-php-config=./scripts/php-config]
--version [5.2.5]
I don’t know why I can’t reset --prefix just doing somethis like this
carlosnblnx:/usr/bin # php-config --prefix /etc/php5/cli/
You’ll find that /usr/bin/php is a link to /etc/alternatives/php which is a link to the actual php binary, /usr/bin/php5. Since php4 is no longer supported in 11.0, there really isn’t any alternative. But php6 may appear some day and then this alternative system (adopted from Debian BTW) will allow selection of 5 or 6.
Your problem is probably that you installed your homebrew php in /usr/local/bin thus getting found first on $PATH. You should remove all traces of your homebrew install. Removing /usr/local/bin/php and /usr/local/bin/php-config would be a first step.
Pretty nice information!
So, you suggest to explicitly remove those binaries using rm command? and then reinstall from RPMs?
Yes, remove them. They don’t come from a RPM.