I've been tasked to create a PHP app which accesses an existing PostgreSQL database. This is my first time working with Postgre, not to mention the PHP has already been installed in the Linux box on which the app is supposed to run. I have no experience setting up this stuff, I just code.
My question is that I can't seem to get the Postgre extension working in PHP. I checked the php.ini file, there were no "extension=..." lines. So I added "extension=pgsql.so". I then checked the "extension_dir" and found that there were only 2 files in there (ldap.so, phpcups.so), I added a pgsql.so file taken from another Linux box. I restarted httpd. And it does not work. I couldn't find any "pgsql" or "postgre" in phpinfo().
Forgive my noobness. I know too little Linux. I would really appreciate it if you can point me to the right direction.
I used the suggestion given by number5:
Dude, I'm on RedHat. I used the "yum" version of the command you gave, and I got this:
[root#perseus ~]# yum install php-pgsql
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=extras error was
[Errno 4] IOError:
Error: Cannot find a valid baseurl for repo: extras
UNFORTUNATELY, the Linux server I'm using is NOT connected to the Internet. Any other way to install?
It depends on which Linux distro you are using.
If you are using Ubuntu/Debian, you need to:
sudo apt-get install php5-pgsql
Fedora/CentOS
yum install php-pgsql
usually you can find out which distro you are on by:
ls /etc/*-release
On CentOS extensions create separate *.ini file one per each php extension in /etc/php.d
So, don't alter main *.ini file, but create /etc/php.d/pgsql.ini and add there a line
extension=pgsql.so
Then you will need to restart Apache using
service httpd restart
But the best automated way is to just type
yum install php-pgsql
In your case that didn't work because of some problems in yum configuration. Go to /etc/yum-repos.d
Type
nano /etc/yum.repos.d/CentOS-Base.repo
Scroll down to [extras] section and ensure it is like this:
#additional packages that may be useful
[extras]
priority=1
name=CentOS-$releasever - Extras
=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Correct it if needed, save file (Ctrl-X) and do the following:
yum clean all
yum upgrade
Afterwards try to repeat
yum install php-pgsql
Remove the .so file you've copied from the other machine (though it might work, there's no need to take the risk)
Use the distribution's package manager to install the php_pgsql/php5_pqsql module
Restart the apache and try again. Maybe the module has been added to an .ini file automagically
If not, run <?php echo 'ini: ', get_cfg_var('cfg_file_path'); to see which php.ini you have to edit
edit this ini file
restart the apache
My operation system Linux mint kde and there was same issue
pg_connect()
You must install if you are use php5.6
sudo apt-get install php5.6-pgsql
After you must change extention name in "php.ini" file.
;extension=php_pgsql.dll
'dll' to 'so'
For example
extension=php_pgsql.so
Related
I am trying to setup webserver with PHP 7 RC3 + Nginx on Ubuntu 14.04 (for test purposes).
I installed Ubuntu in Vagrant using ubuntu/trusty64 and PHP 7 RC 3 from Ondřej Surý (https://launchpad.net/~ondrej/+archive/ubuntu/php-7.0).
I can not find the way to install MySQL PDO (PHP sees PDO class but not anything related to MySQL, like PDO::MYSQL_ATTR_DIRECT_QUERY etc.)
Looks like there is no lib php7.0-mysql (by analogy with standard php5-mysqlnd and php7.0-fpm etc. from Ondřej)
Section PDO in phpinfo():
PDO support enabled
PDO drivers no value
How can I get it?
For thoses running Linux with apache2 you need to install php-mysql
apt-get install php-mysql
or if you are running ubuntu 16.04 or higher just running the following command will be enought, no need to edit your php.ini file
apt-get install php7.2-mysql
If you are running ubuntu 15.10 or below:
Edit your php.ini file, it's located at /etc/php/[version]/apache2/php.ini and search for pdo_mysql
you might found something like this
;extension=pdo_mysql.so
Change it to this
extension=pdo_mysql.so
Save the file and restart apache
service apache2 restart
Check that it's available in your phpinfo()
First install php-mysql
sudo apt-get install php7.0-mysql
//change the version number based on the php version
then enable the module
sudo phpenmod pdo_mysql
and restart apache
sudo service apache2 restart
On ubuntu 18.04 following works for me
type this in your terminal
For php7.3
sudo apt-get install php7.3-gd php7.3-mysql
For php7.0
sudo apt-get install php7.0-gd php7.0-mysql
For php5
sudo apt-get install php5-gd php5-mysql
First, check if your php.ini has the extension enabled "php_pdo_mysql" and "php_mysqli" and the path of "extension_dir" is correct. If you need one of above configuration, then, you must restart the php-fpm to apply the changes.
In my case (where i am using the Windows OS in the company, i really prefer OSX or Linux), i solved the problem putting this values in the php.ini:
; ...
extension_dir = "ext"
; ...
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
; ...
I hope this helps.
Since eggyal didn't provided his comment as answer after he gave right advice in a comment - i am posting it here: In my case I had to install module php-mysql. See comments under the question for details.
If you are on windows, and your php folder is not in your PATH, you have set the absolute directory in your php.ini
for example:
extension_dir = "C:/php7/ext"
and uncomment
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
Restart apache2.4 and it should work.
I hope it helps.
download the source code of php 7 and extract it.
open your terminal
swim to the ext/mysqli directory
use commands:
phpize
./configure
make
make install (as root)
enable extension=mysqli.so in your php.ini file
done!
This worked for me
I had, pretty much, the same problem. I was able to see that PDO was enabled but I had no available drivers (using PHP 7-RC4). I managed to resolve the issue by adding the php_pdo_mysql extension to those which were enabled.
Hope this helps!
I resolved my problem on ubunto 20.4 by reinstalling php-mysql.
Remove php-mysql:
sudo apt purge php7.2-mysql
Then install php-mysql:
sudo apt install php7.2-mysql
It will add new configurations in php.ini
Had the same issue, resolved by actually enabling the extension in the php.ini with the right file name. It was listed as php_pdo_mysql.so but the module name in /lib/php/modules was called just pdo_mysql.so
So just remove the "php_" prefix from the php.ini file and then restart the httpd service and it worked like a charm.
Please note that I'm using Arch and thus path names and services may be different depending on your distrubution.
I'll start with the answer then context NOTE this fix was logged above, I'm just re-stating it for anyone googling.
Download the source code of php 7 and extract it.
open your terminal
swim to the ext/pdo_mysql directory
use commands:
phpize
./configure
make
make install (as root)
enable extension=mysqli.so in your php.ini file
This is logged as an answer from here (please upvote it if it helped you too): https://stackoverflow.com/a/39277373/3912517
Context:
I'm trying to add LimeSurvey to the standard WordPress Docker. The single point holding me back is "PHP PDO driver library" which is "None found"
php -i | grep PDO
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_odbc' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_odbc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: Module 'mysqli' already loaded in Unknown on line 0
PDO
PDO support => enabled
PDO drivers => sqlite
PDO Driver for SQLite 3.x => enabled
Ubuntu 16 (Ubuntu 7.3.0)
apt-get install php7.0-mysql
Result:
Package 'php7.0-mysql' has no installation candidate
Get instructions saying all I have to do is run this:
add-apt-repository -y ppa:ondrej/apache2
But then I get this:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 223: ordinal not in range(128)
So I try and force some type of UTF:
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/apache2
and I get this:
no valid OpenPGP data found.
Follow some other instructions to run this:
apt-get update
and I get this:
Err:14 http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic/main amd64 Packages
404 Not Found
Err:15 http://ppa.launchpad.net/ondrej/php/ubuntu cosmic/main amd64 Packages
404 Not Found
and - I think because of that - I then get:
The repository 'http://ppa.launchpad.net/ondrej/apache2/ubuntu cosmic Release' does not have a Release file.
By this stage, I'm still getting this on apt-get update:
Package 'php7.0-mysql' has no installation candidate.
I start trying to add in php libraries, got Unicode issues, tried to get around that and.... you get the idea... whack-a-mole. I gave up and looked to see if I could compile it and I found the answer I started with.
You might be wondering why I wrote so much? So that anyone googling can find this solution (including me!).
['class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost:3306;dbname=testdb',
'username' => 'user',
'password' => 'password',
'charset' => 'utf8',]
It's simple:
Just provide the port number along with the host name
and set default sock path to your mysql.sock file path in php.ini which the server is running on.
Just as an update for those working with installing Linux programs, please note, that things such as 'php7.0-common' are now simply known as 'php-common'.
I'm trying to make this code run:
<?php
$m = new MongoClient("mongodb://54.72.237.242");
$db = $m->tilbud;
?>
Everytime I got the same error:
Fatal error: Class 'MongoClient' not found in C:\xampp\htdocs\conexion.php
I've been reading about this problem the whole day but anything solves my issue (I guess it's something I'm doing wrong).
I downloaded the php_mongo.dll, I copied it in xampp/php/ext and I added extension=php_mongo.dll in the php.ini archive.
I've added 4 more dll's because I'm not sure which one I have to use:
extension=php_mongo-1.5.4-5.5-vc11-nts
extension=php_mongo-1.5.4-5.5-vc11
extension=php_mongo-1.5.4-5.5-vc11-nts-x86_64
extension=php_mongo-1.5.4-5.5-vc11-x86_64
So now im getting 5 warnings instead of one. At the end I guess one of them will work and I'll delete the other 4.
Things I tried and I'm sure they are ok:
The extension_dir is pointing to the correct folder.
The php.ini that I modified is the one that xammp loads.
Phpinfo dosen't show anything about mongo.
What more can I try ?
Edit
I tried
echo extension_loaded("mongo") ? "loaded\n" : "not loaded\n";
and it always says 'not loaded'.
Edit
Finally!
The problem was the dll's name. It has to be 'php_mongo.dll' and I was trying to load the full name dll as I said at the begining of this post. So I changed the correct dll for me (extension=php_mongo-1.5.4-5.5-vc11) for extension=php_mongo.dll and voilà!
You have not installed MongoDB PHP driver please see this link http://www.php.net/manual/en/mongo.installation.php
Update sources
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
Install MongoDB PHP Driver
sudo apt-get install php5-dev php5-cli php-pear -y
sudo pecl install mongo
Open your php.ini file and add to it:
extension=mongo.so
Restart apache
sudo /etc/init.d/apache2 restart
Other helping info:
this should help to find your php.ini file:
php -i | grep 'Configuration File'
On Ubuntu it shows this:
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
take a note, that you run this command from cli (command line) so for your true php.ini go to folder apache2 instead of cli :)
For those arriving on this page with PHP 7 installed:
The MongoCLient class was provided by pecl install mongo.
But pecl/mongo is not available for php7 and deprecated in favor of pecl/mongodb. But with pecl/mongodb you'll need to use MongoDB\Driver\Manager instead of MongoClient (warning on page says so too).
See here for further reading.
This said, you will need an abstraction layer on top of the PHP MongoDB\Driver\Manager. This is provided by mongodb/mongo-php-library.
You will need to refactor stuff like:
\MongoClient to \MongoDB\Client
\MongoCollection to \MongoDB\Collection
\MongoClient->selectDB to \MongoDB\Client->selectDatabase
\MongoClient->listDBs to \MongoDB\Client->listDatabases
also output is not an array but an iterator, so you'll need to use iterator_to_array, along with edits to how you use the resulting object
\MongoCollection->getName to \MongoDB\Collection->getCollectionName
\MongoCollection->update to \MongoDB\Collection->updateOne or updateMany
\MongoCollection->remove to \MongoDB\Collection->deleteOne
\MongoCollection->batchInsert to \MongoDB\Collection->insertMany
The answer is indeed to follow the instructions.
I was missing the very important require line that must come before creating the new mongodb object:
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:27017");
And of course you need to run this command in the root of your project as per the instructions:
composer require mongodb/mongodb
Getting the same error and now it's solved.
I am using Linux Mint. To solve this issue I added extension=mongo.so in two directories:
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini
install the driver, I have for example php5.6:
sudo apt-get install php5.6-mongo
From this page:
Note: Additional DLL dependencies for Windows Users:
In order for this extension to work, there are DLL files that must be available to the Windows system PATH
your php version and dll file version should be same check it if versions are not same then update your xampp php according to the available dll version.
I am trying to enable XSL on Ubuntu 12.04 but its failing. I did this locally on my Ubuntu 13.04 and it was successful. Basically the following worked on my local computer.
apt-get install php5_xsl
edit php.ini file and add extension=php5_xsl.so
restart apache
I repeated the same procedures on my production server running Ubuntu 12.04 and PHP version 5.5.12 but the extension is not getting loaded from the phpinfo. I have also changed the extension=php5_xsl.so to extension=xsl.so because this is what in the extension directory.
I read that I might need to recompile PHP but I am not sure of this steps.
Try this:
sudo apt-get install php5-xsl
sudo php5enmod xsl
sudo service apache2 restart
Why:
http://www.lornajane.net/posts/2012/managing-php-5-4-extensions-on-ubuntu
What's happened here is that all debian-flavoured unixes have adopted
this standard for their PHP 5.4 packages, so if you're using debian,
ubuntu, or any of their relatives with PHP 5.4, you'll see a directory
structure like this. When you add a module to PHP, you'll add a file
to the mods-available directory enabling the module and adding any
config specific to it. If you want to enable the module, just do:
php5enmod http
This simply creates a symlink from the usual conf.d directory to point
to where the real files are in mods-available, prefixed with a number
that indicates the priority of the module. By default, the priority is
20.
Using this approach means we can toggle things on and off without
commenting out big chunks of config files and leaving them lying
around - if this seems familiar then that's no surprise; debian-like
linuxes manage their apache configuration in just the same way. Any
packages that you install using aptitude will use these exact same
commands to set up the configuration and then symlink it correctly. To
unlink, use the delightfully predictably-named php5dismod :)
I guess when php was installed on my box --with-tidy arg was not included.
When browsing my php.ini the line:
;extension=php_tidy.dll
is missing.
How can I add the module to my php install? Note I tried adding:
extension=php_tidy.dll
but with no luck.
I checked the docs but all they say is:
This extension is bundled with PHP 5 and greater, and is installed using the --with-tidy configure option.
On Ubuntu, you can add tidy to your php5 installation by running this command in a terminal:
$ sudo apt-get install php5-tidy
If you want to check if it is already installed or validate that the command above worked:
$ php -i | grep libTidy
libTidy Release => 25 March 2009 // means tidy is installed
To install both php5 and tidy at the same time, use this command (as an alternative to the "--with-tidy" configuration option):
$ sudo apt-get install php5 php5-tidy
For PHP 7 just run
sudo apt-get install php-tidy
And restart Apache, That's it :)
Update: Thanks to #Arnis Juraga
For the version above PHP 7, you can mention the version code as follows.
apt-get install php7.4-tidy
I was having the same trouble, and wrote up my solution here:
Installing Tidy 2.0 PHP extension on Ubuntu 10.10
http://web.onassar.com/blog/2010/11/16/installing-tidy-2-0-php-extension-on-ubuntu-10-10/
It works on newer versions of Ubuntu as well.
While it may not be the most direct route, it works well.
I hope it helps others.
Put that line in php.ini next to the other extension=...dll lines and make sure php_tidy.dll is in the directory configured in php.ini under extension_dir.
In ubuntu: you need to run the following command in terminal
sudo apt-get install php5-tidy
and the restart the server
sudo service apache2 restart.
For those who are having trouble enabling Tidy extension for PHP (using PHP handler for Apache server) on Windows (WAMP server), please note that you may be editing the wrong php.ini file. Assuming that WAMP server is installed in C:\wamp[ver]\ where [ver] is a variable version number.
File that you're probably editing:
C:\wamp[ver]\bin\php\php[ver]\php.ini
File that you must edit:
C:\wamp[ver]\bin\apache\apache[ver]\bin\php.ini
You also might want to make sure what's the correct php.ini file to edit by creating an info php file and add this code to it:
<?php phpinfo();
Then look for Loaded Configuration File string.
Finally make sure you uncomment this line within the correct php.ini file:
extension=tidy
I am trying to use the new facebook api and it requires libcurl PHP. I used
sudo apt-get install php5-curl
sudo apachectl -k restart
And it didn't work. I get the same error and the phpinfo() page says nothing about libcurl.
The source of this problem is probably that I built some of the tools from source (apache2, php), but then I got bored so installed a lot of the extensions with the package manager. But I'm not exactly how to go about diagnosing the point of failure.
The apt-get install for curl definitely worked, and can be found in
/usr/lib/php5/20060613/curl.so
I think a lot of my confusion stems from not knowing which files go where, and what purpose they have. Any help would be appreciated, and please tell me if I need to provide more information.
edit:
The specific error I get is:
Exception: Facebook needs the CURL PHP extension.
from line
if (!function_exists('curl_init')) {
throw new Exception('Facebook needs the CURL PHP extension.');
}
Ubuntu: 9.10
PHP: 5.2.13
Loaded Configuration File: /etc/php5/apache2/php.ini
In general it's a bad idea to mix and match software from your distribution's package manager with stuff you've built yourself. The package manager will not know anything about the stuff you've built yourself and so can get confused.
Not only that but who's to say the stuff from the package manager is even binary compatible with the stuff you've built yourself? If you build it all yourself then at least you know it will all be compatible.
Sounds to me like you should uninstall the extensions and build them yourself. If you can't or don't want to do that then go back and install apache and friends through your package manager but I would recommend having patience and going for the former option.
Answer of Questions
What version of Ubuntu?
What version of PHP?
How is Apache and PHP set up?
What ini files does phpinfo() say is parsed? (should be near the top)
Perhaps apt failed to properly modify your php.ini file to load the curl extension?
Check out your php.ini and see if you have line like:
extension=curl.so
or maybe:
extension=/usr/lib/php5/20060613/curl.so
To check if php-curl is installed please follow these steps:
Create a file in your web server (in Ubuntu it would be in /var/www folder), name it info.php
Open that file and type this command:
<?php phpinfo(); ?>
Save that file
Open your favorite browser and open that file (ex: http://localhost/info.php)
Now you will see the Information about your PHP installation
Search for Curl, and if you cannot find it, it mean your php doesn’t have curl installed.
To install php-curl please follow these steps:
Open your terminal and type this command:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl php5-mcrypt
After it finish open php.ini file (mine is at /etc/php5/apache2/php.ini ) and add this command: extension=curl.so
Save the file and restart apache with this command:
/etc/init.d/apache2 restart
Check the PHP information page again, you will find PHP-CURL installed
That’s it
Source: http://www.ivankristianto.com/os/ubuntu/howto-install-curl-in-php-apache/379/