Cannot install PDO on CentOS - php

I know there is several instances of this question throughout stackoverflow but I am not finding a solution.
I am running CentOS with Apache and PHP 5.3
A .php script is giving me this error:
Fatal error: Class 'PDO' not found in ...
I ran phpinfo(); and the only place "pdo" exists on the page is in the "Configure Command" '--disable-pdo' line.
I attempted #yum install php-pdo but no packages exist.
I also attempted #pecl install pdo and i get these errors at the end:
/root/tmp/pear/PDO/pdo_dbh.c: In function 'pdo_stmt_instantiate':
/root/tmp/pear/PDO/pdo_dbh.c:410: error: 'zval' has no member named 'refcount'
/root/tmp/pear/PDO/pdo_dbh.c:411: error: 'zval' has no member named 'is_ref'
/root/tmp/pear/PDO/pdo_dbh.c: In function 'pdo_stmt_construct':
/root/tmp/pear/PDO/pdo_dbh.c:435: error: 'zend_fcall_info' has no member named 'object_pp'
/root/tmp/pear/PDO/pdo_dbh.c:458: error: 'zend_fcall_info_cache' has no member named 'object_pp'
/root/tmp/pear/PDO/pdo_dbh.c: In function 'zim_PDO_setAttribute':
/root/tmp/pear/PDO/pdo_dbh.c:752: error: 'zval' has no member named 'refcount'
/root/tmp/pear/PDO/pdo_dbh.c: In function 'zim_PDO_getAttribute':
/root/tmp/pear/PDO/pdo_dbh.c:818: error: 'zval' has no member named 'refcount'
/root/tmp/pear/PDO/pdo_dbh.c: In function 'pdo_hash_methods':
/root/tmp/pear/PDO/pdo_dbh.c:1122: warning: assignment discards qualifiers from pointer target type
/root/tmp/pear/PDO/pdo_dbh.c:1126: warning: assignment discards qualifiers from pointer target type
make: *** [pdo_dbh.lo] Error 1
ERROR: `make' failed
Then on the php.net doc it basically says the package comes standard in php installations since PHP 5.1.
I added the line extension=pdo.so to php.ini and restarted Apache and the problem persists. Any suggestions?

I too have had a similar issue. I am using codeigniter and was getting a "pdo_mysql.so not found" error and tried everything to fix it. I must of searched thru the first 10 pages of google search results for multiple queries. I found tons of people with the same problems but for some reason none of them had an answer/fix. Thru all this reading I learned that "PDO and the PDO_SQLITE driver is enabled by default as of PHP 5.1.0." This got me thinking, "Perhaps I should remove the extension=pdo_mysql.so and pdo.so lines from my php.ini!" I figured php was trying to load an extension that was no longer there since it comes built in now. Sure enough, solved all my php error mess.
PHP 5.4.31 (cli) (built: Aug 19 2014 10:38:48)
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
Server version: Apache/2.2.27 (Unix)
Server built: Aug 19 2014 10:33:30
Cpanel::Easy::Apache v3.26.5 rev9999

I'm pretty sure that you're missing the PHP_PDO package. Try to find the PDO package by running the command bellow:
# rpm -qa| grep "pdo"
Mine shows php53u-pdo-5.3.26-1.ius.el5
If you are using php 5.3 then try
# yum install php53u-pdo

I dont know if it is too late for the answer, but I'll post if someone finds this error.
First, I had installed php-pdo in Centos 7 with yum. I viewed phpinfo and it shows the pdo extension but not pdo-mysql.
So, If you then installs php-mysql (yum install php-mysql) it will install automatically the pdo-mysql extension.

Related

curl shows as installed and enabled, but throwing undefined function errors when executed in php

Running on Centos 7 system. phpinfo() says curl is enabled, but when I run this code:
<?php
// API
$url = 'https://api.openai.com/v1/embeddings';
// Create a new cURL resource
$ch = curl_init($url);
?>
I get error: PHP Fatal error:
Uncaught Error: Call to undefined function curl_init()
If I try to install it says it's already installed:
yum install php-curl
Package php-common-8.1.14-1.el7.remi.x86_64 already installed and latest version
All out of answers. What can I try from here? Why is curl not executing?
php --version
PHP 8.1.14 (cli) (built: Jan 4 2023 06:45:14) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.14, Copyright (c) Zend Technologies
with Zend OPcache v8.1.14, Copyright (c), by Zend Technologies
phpinfo();
cURL support enabled
cURL Information 7.29.0
php -i | grep "curl"
/etc/php.d/20-curl.ini,
curl
curl.cainfo => no value => no value
In /etc/php.d/20-curl.ini:
extension=curl.so
yum list *curl*
Installed Packages
curl.x86_64 7.29.0-59.el7_9.1 installed
libcurl.x86_64 7.29.0-59.el7_9.1 installed
libcurl-devel.x86_64 7.29.0-59.el7_9.1 installed
python-pycurl.x86_64 7.19.0-19.el7 #base
Available Packages
collectd-curl.x86_64 5.8.1-1.el7 epel
collectd-curl_json.x86_64 5.8.1-1.el7 epel
collectd-curl_xml.x86_64 5.8.1-1.el7 epel
curlftpfs.x86_64 0.9.2-14.el7 epel
flickcurl.x86_64 1.25-2.el7.nux nux-dextopflickcurl-debuginfo.x86_64 1.25-2.el7.nux nux-dextopflickcurl-devel.x86_64 1.25-2.el7.nux nux-dextopfuse-curlftpfs.x86_64 0.9.1-1.el6.rf rpmforge
libcurl.i686 7.29.0-59.el7_9.1 updates
libcurl-devel.i686 7.29.0-59.el7_9.1 updates
nbdkit-plugin-curl.x86_64 1.2.7-2.el7 epel
ocaml-curl.x86_64 0.7.5-3.el7 epel
ocaml-curl-devel.x86_64 0.7.5-3.el7 epel
perl-WWW-Curl.x86_64 4.15-13.el7 base
php-pear-Net-Curl.noarch 1.2.5-10.el7 epel
python34-pycurl.x86_64 7.43.0-7.el7 epel
python36-pycurl.x86_64 7.43.0-7.el7 epel
uwsgi-alarm-curl.x86_64 2.0.18-8.el7 epel
uwsgi-plugin-curl-cron.x86_64 2.0.18-8.el7 epel
I spent an hour working with ChatGPT3 on trying to resolve this. I can't say that the AI actually resolved it, but early in the session it did say this:
The PHP script you are trying to run is not using the correct PHP
version. Make sure that you are running the script with the correct
PHP version that has cURL extension installed.
The PHP script is being run by a user that does not have access to the
cURL extension. Try running the script with a different user or set
the correct permissions on the script.
The PHP script may have some syntax errors, which is causing the
curl_init() function to not be recognized. Verify that your script
does not contain any syntax errors.
The PHP script may have been corrupted during upload or download. Try
re-uploading or re-downloading the script and make sure it is not
corrupted.
There could be a problem with the installed version of curl. Try to
update the curl version and see if that resolves the issue.
Corruption of the file turned out to be the culprit. In any event, the steps it took me through to narrow down the issue eventually helped me to resolve it. I really can't recommend it enough if you're stuck and can't seem to get any responses here, you may want to try: https://chat.openai.com/chat
FYI, the full troubleshooting conversation I had with the AI is here: https://sharegpt.com/c/GJVQs0n
At any rate, after exhaustively verifying that curl was installed and enabled in php and apache was calling the correct php version, I finally realized the problem was in the code itself. Not the syntax, but apparently there were invisible characters in the code that were causing the error. After re-entering the same code, it worked.
<?php
// API
$url = 'https://api.openai.com/v1/embeddings';
// Create a new cURL resource
$ch = curl_init($url);
?>
If anyone knows of a way to detect these characters in a text file, please leave that info in the comments. Thanks!

How to fix PHP module problems after update

I think this question is asked already, but with so many different conditions, I think my problem is a bit unique, correct me if I'm wrong.
I have this response after make a PHP update on my old MacBook. Using curl PHP install command:
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
and this is my result after install and I check my version with "PHP -v" command on terminal
PHP Warning: PHP Startup: curl: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20180731
These options need to match
in Unknown on line 0
Warning: PHP Startup: curl: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20180731
These options need to match
in Unknown on line 0
etc
also in the end of the line there is this error:
Deprecated: Directive 'track_errors' is deprecated in Unknown on line 0
PHP 7.3.0beta3 (cli) (built: Sep 3 2018 11:26:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
PHP 7.3.0beta3 is my previous version.
Been tried to re-install the same version of PHP using command line but still doesn't work.
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3.0beta3
I know something un-match with the version. But how exactly I fix it.
I've been search the whole internet, and not found any solution that works well with me. Most question that I search here, is not marked as "worked solution" yet.
Probably I understand it wrong.
Anyone have the solution, please?!
I desperately need the answer. Thank you
FYI:
My MacOS is Yosemite 10.10.5
////////////////////
UPDATE 1:
I've been checked on this solution on THIS LINK
But it's not going to work since the solution require me to install PECL / PEAR, and that installer would work through PHP command. Which is broken for me.
////////////////////
UPDATE 2:
I've checked a shortcut file on 'usr/local/php5' and it's refer to a wrong directory, so I rename it to 'php5-old' and created a new alias from my old php directory and rename it 'php5'.
When I run 'php -v' command, it says a different error:
dyld: Library not loaded: /usr/local/php5/lib/libtidy-0.99.0.dylib
Referenced from: /usr/local/php5-7.3.0beta3-20180903-112811/bin/php
Reason: no suitable image found. Did find:
/usr/local/php5/lib/libtidy-0.99.0.dylib: stat() failed with errno=20
Trace/BPT trap: 5
I don't know what to do. I did check on that "libtidy-0.99.0.dylib" file, and still on the same directory.
////////////////////
UPDATE 3:
This is not the best practice. But I've got temporary solution already. I start to understand that the problem from my UPDATE 2 is from 'usr/local/php5', but instead I create a new alias that doesn't work, I rename the 'php5' refers directory and add "-old" prefix. And the original folder that should work "php5-7.3.0beta3-20180903-112811", I rename into the folder name that 'php5' alias refers to. And the PHP now working.
But still one more problem: "Apache web server" still not running.
So this problem looks like occur when my Mac itself has another problem (which I don't really know what it is).
So the best solution so far (been tried to avoid this from the beginning) is to create a new user and do install it all as a new laptop... And that's it. Works Normal

Having installed PHP7 can i also use php5_module along?

I just upgraded from php5.6. => php7.2.5
All of my websites are working except one that it only workd correctly with the php5_module and not with the php7_module.
Is there soem way to only have installed php7.2.5 but also use the php5_module as well?
This the error iam getting from a domain when i upgraded from php56 => php72
[Mon May 21 10:33:21.490109 2018] [proxy_fcgi:error] [pid 19775] [client 66.249.66.193:39398] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Call to undefined function split() in /home/akis/public_html/wp-content/themes/business_for_sale_1-1/library/misc.php:19\nStack trace:\n#0 /home/akis/public_html/wp-content/themes/business_for_sale_1-1/library/navigation.php(271): theme_trim_long_str('\xCE\x91\xCF\x81\xCF\x87\xCE\xB9\xCE\xBA\xCE\xAE', '45')\n#1 /home/akis/public_html/wp-content/themes/business_for_sale_1-1/library/navigation.php(343): theme_MenuItem->get_start(0)\n#2 /home/akis/public_html/wp-content/themes/business_for_sale_1-1/library/navigation.php(315): theme_MenuWalker->display('', Array)\n#3 /home/akis/public_html/wp-content/themes/business_for_sale_1-1/library/navigation.php(92): theme_MenuWalker->walk(Array, Array)\n#4 /home/akis/public_html/wp-content/themes/business_for_sale_1-1/library/navigation.php(17): theme_get_list_menu(Array)\n#5 /home/akis/public_html/wp-content/themes/business_for_sale_1-1/header.php(62): theme_get_menu(Array)\n#6 /home/akis/public_html/wp-includes/template.php(688...\n'
Your error states:
Call to undefined function split()
After a quick google search I found this article in the PHP documentation:
http://php.net/manual/en/function.split.php
Warning. This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
Alternatives to this function include:
preg_split()
explode()
str_split()
Please conciser using one of the alternatives.
This is why you shouldn't use deprecated functions when writing code, because they will soon disappear and your code will crash when upgrading versions.
Yeah.. why not, you can have both versions installed. And you can enable or disable your PHP versions using the below commands if your are on a linux machine (ubuntu)
sudo a2dismod php7.2 (**Replace it with your PHP7 version**)
sudo a2enmod php5.6 (**To enable your PHP5.x version**)
sudo service apache2 restart (**Restart Apache**)
Again, if you want to enable 7.2 just replace it vice versa.
Note : Remember though, you can't have both versions working at the same time.
I think you can give https://github.com/cfebs/phpvm a go, this works well with my local environment.
Another option is to use Docker, create a container with both PHP versions and put your app into those containers to compare. Another good thing with a docker is that you can change docker-compose file to a version that suits you best.

pg_connect undefined function on osx mavericks

I have looked at multiple SO threads and none of them seem to have my problem. I have compiled and install the pro_pgsql extension as outlined here: http://blog.rupey.org/post/63221360055/adding-postgres-support-to-php-on-os-x-mavericks and verified that it is loaded by running php -m apache has been restarted, php_info shows the following:
But when I run this script:
echo "hi!";
$ebdb_conn = pg_connect('dbname=mydb user=frank password=frank123') or die(pg_last_error());
I get the following error in the log:
[Mon Jun 09 12:39:05 2014] [error] [client ::1] PHP Fatal error: Call to undefined function pg_connect() in /Users/frank/Code/ebus/test.php on line 4
This is on OSX Mavericks, with Apache and PHP 5.2.24. Any ideas?
This problem was eventually solved by uninstalling everything that had to do with the Enterprise DB postgres package and reinstalling it with a consistent set of packages. I still, unfortunately have a non-matching psql client on the machine but other than that it is working fine. For others seeing this, I recommend:
DO NOT use enterprise DB installer found on the postgres website on OSX Mavericks use one of the following
1) postgres app (http://postgresapp.com) nice because its has postGIS and other extensions built in
2) map ports packages (https://trac.macports.org/browser/trunk/dports/databases/postgresql82/Portfile)
3) brew installer (http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/)
pg_connect isn't a part of the PDO library. It's contained in the direct postgresql library for PHP. In MacPorts, that's php5-postgresql, which macports gets from http://lil.fr.packages.macports.org/php5-postgresql.

PHP unable to load dynamic library (mongo.so)

i'm trying to use rockmongo. After installation, i'm unable to use it. It says "To make things right, you must install php_mongo module. Here for installation documents on PHP.net."
i have already installed mongoDB driver extension via sudo pecl install mongo.
locate mongo shows /usr/lib/php5/20090626+lfs/mongo.so
However, php -v shows few warnings (which i think is related to mongo)
PHP: syntax error, unexpected $end, expecting ']' in /etc/php5/cli/conf.d/mongodb.ini on line 3
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20100525+lfs/mongo.so' - /usr/lib/php5/20100525+lfs/mongo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.4.28-1+deb.sury.org~precise+1 (cli) (built: May 5 2014 09:39:26)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
i opened /usr/lib/php5/ and found out that there are another directory(20090626+lfs) which contains mongo.so.
i tried various online tutorial, but nothing helped.
Edit: Here's my mongodb.ini
;----- start -----
extension=mongo.so
\[mongo\]
; If the driver should reconnect to mongo
mongo.auto_reconnect = true
; Whether to allow persistent connections
mongo.allow_persistent = On
; Maximum number of persistent connections (-1 means unlimited)
mongo.max_persistent = -1
; Maximum number of links (persistent and non-persistent, -1 means unlimited)
mongo.max_connections = -1
; Default host for mongo connection
mongo.default_host = www.example.com
; Default port for mongo database
mongo.default_port = 42
; When saving files to the database, size of chunks to split them into
mongo.chunk_size = 1024
; Specify an alternate character to $ to use for special db functions ($set, $push, $exists, etc.)
mongo.cmd = "$"
;----- end -----
I solved this problem using the 1.1.9 version of mongodb driver for php 5. First uninstall the current version of mongodb and then install the 1.1.9 version:
sudo pecl uninstall mongodb
sudo pecl install mongodb-1.1.9
composer update
My php version is 7.0, but it should work version 5.x too.
If you have this in the file /etc/php/7.0/mods-available/mongo.ini
extension=mongodb.so
Comment that line. After that restart php and it should work.
For me this works well
sudo apt-get install php7.2-mongodb
Change the '7.2' for your php version
Add the full path to your mongo.so extension in mongodb.ini:
extension=/usr/lib/php5/20090626+lfs/mongo.so
Also the [mongo] should be written exactly like that NOT \[mongo\].
Don't forget to reload/restart your web server to load the new configuration.
You can check that everything is ok with:
php -i | grep mongo
After OS update, I had a similar error while running any PHP CLI, simply running "php -v" produced the error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/mongodb.so'
I checked the folder, I found the file '/usr/lib/php/20131226/mongodb.so' existed. So, I simply commented on the line "extension=mongo.so" in '/etc/php/5.6/cli/php.ini' file. It fixed my issue.
When checked mongo --version, it was working fine.

Categories