Installing MySQLi with Apache 2 and PHP 5.5 - php

I'm really stuck on this I've been searching for hours...
I recently installed an Apache server on a remote Ubuntu box for my website and I wanted to get started with PHP and MySQL. MySQL is installed and running. PHP installed fine, that works, but I can't figure out how to enable the MySQL extension. I've already done sudo apt-get install php5-mysql and/or sudo apt-get install php5-mysqlnd but neither of those seemed to actually install anything, at least according to my Apache server. When I run php -m I see mysql, mysqli, and mysqlnd. I've also tried uncommenting the lines for loading the extensions in the Apache php.ini file but none of the mysql.so or mysqli.so or whatever exist in the default extension directory. There is another PHP extensions directory with those files in it, but when I tried pointing my Apache server to that extension directory, I got errors saying this:
/usr/local/lib/php/extensions/no-debug-zts-20131226/mysqli.so: undefined symbol: core_globals in Unknown on line 0
I've tried everything I've seen so far and nothing has worked. That error was the closest I got. Any help is appreciated.
Also here's my phpinfo() output: http://pastebin.com/VM8kyrKV
I also get this when I run sudo apt-get install php5-mysqlnd:
php5_invoke: Enable module mysqlnd for cli SAPI
php5_invoke: Enable module mysqlnd for apache2 SAPI
php5_invoke: Enable module mysql for cli SAPI
php5_invoke: Enable module mysql for apache2 SAPI
php5_invoke: Enable module mysqli for cli SAPI
php5_invoke: Enable module mysqli for apache2 SAPI
php5_invoke: Enable module pdo_mysql for cli SAPI
php5_invoke: Enable module pdo_mysql for apache2 SAPI
Which seems to look good but it's still not working... I can't find any mysql module files anywhere except the ones for CLI PHP.
Edit:
Long story short, don't compile your own binaries... I started over only using apt-get to install things and everything just worked.

I've already done sudo apt-get install php5-mysql and/or sudo apt-get install php5-mysqlnd but neither of those seemed to actually install anything, at least according to my Apache server.
Your output from phpinfo() shows both the mysql and mysqlnd modules are active. This suggests the install was successful and you just need to uncomment the line to load mysqli.so. Make sure you're editing the file for the Apache instance (/etc/php5/apache2/php.ini if I'm remembering correctly) and not the CLI instance. And of course don't forget to restart the service after any changes!

Related

phpMyAdmin does not connect [duplicate]

I receive this error after trying to set up LAMP by following this tutorial, and I find myself receiving the above error after trying to set up phpmyadmin.
Fatal error: Call to undefined function mb_detect_encoding() in
C:\WebServer\Apache\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc
on line 177
I followed the advice over here: PHP Fatal error when trying to access phpmyadmin mb_detect_encoding, and made those changes.
When I run phpinfo(), I see that support for MySQL and mb_string are enabled as shown below:
Install the gd library also.
check this link
http://www.php.net/manual/en/mbstring.installation.php
There's a much easier way than recompiling PHP. Just yum install the required mbstring library:
Example: How to install PHP mbstring on CentOS 6.2
yum --enablerepo=remi install php-mbstring
Oh, and don't forget to restart apache afterward.
Mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
In case your php version is 7.0:
sudo apt-get install php7.0-mbstring
sudo service apache2 restart
In case your php version is 5.6:
sudo apt-get install php5.6-mbstring
sudo service apache2 restart
On Windows open the file php.ini and make this changes:
Remove the comment and point to the ext directory
; extension_dir = "./" -> extension_dir = "C:/Php/ext"
Remove the comment of this extensions
extension=php_mbstring.dll
extension=php_mysqli.dll
Restart apache service
httpd -k restart
When I opened my php.ini file, "extension_dir" line looked like following :
extension_dir = "C:/wamp/bin/php/php5.4.16/ext/"
which i changed to:
extension_dir = "C:\wamp\bin\php\php5.4.16\ext\"
and it worked.
Under Windows / WAMP there doesn't seem to be any php_mbstring.dll dependencies on the GD2 extension, the MySQL extensions, nor on external dlls/libs:
deplister.exe ext\php_mbstring.dll
php5ts.dll,OK
MSVCR110.dll,OK
KERNEL32.dll,OK
deplister.exe ext\php_gd2.dll
php5ts.dll,OK
USER32.dll,OK
GDI32.dll,OK
KERNEL32.dll,OK
MSVCR110.dll,OK
Whatever php_mbstring already needs, it's built-in (statically compiled right into the DLL).
Call to undefined function mb_detect_encoding()
This error is also very specific and deterministic...
The function mb_detect_encoding() didn't fail because php_gd, php_mysql, php_mysqli, or another extension was not loaded; it simply was NOT found.
I'm guessing that all the answers that are reported as valid (for Windows / WAMP), that say to load other extensions, to change php.ini extension_dir paths (if this one was wrong to begin with, NO extensions would load), etc, work more due to a) un-commenting the extension = php_mbstring.dll line, or b) restarting Apache or the computer (for changes to take effect).
On Windows, most of the time the problem is that php_mbstring.dll is either:
Blocked by Windows. Unblock it by right-clicking it, check Properties.
Or PHP can't load php_mbstring.dll due to another version getting loaded (e.g., from some improper PHP DLLs install into C:\Windows\system32), some version mismatch, missing run-time DLLs, etc. Check Apache's and PHP's error log files first for clues.
More in-depth answer here: Call to undefined function mb_detect_encoding
For fedora/centos/redhat:
yum install php-mbstring
Then restart apache
you should use only english version of phpmyadmin if you are using all languages you should enable all languages mbstring in php.in file.....just search for mbstring in php.in
The problem could also be that Apache can't find php.ini
If you set PHPIniDir incorrectly.
Mine was set to: PHPIniDir "c:/php7"
But, the folder is actually just "php"
The clue was viewing phpinfo()
Which showed:
Configuration File (php.ini) Path C:\windows
I had the same problem with Ubuntu 17, Ispconfig was not processing the operations queued of any kind and also the server.sh command was not working.
I checked and the running PHP version after the OS upgrade was 7.1 so the solution was to type:
apt-get install php7.1-mbstring
and now is everything ok
Hope this helps some ppl, I got this error when i added the path and extension to "docref_root" "docref_ext" in my php.ini file, I then commented it out and it was ok, but cant get my help to work now.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
PHP.INI XAMP5.6 > In my case, while updating max_ values, I removed
; max_input_time
Default Value: -1 (Unlimited)
After undoing everything works normally.
; max_input_time
; Default Value: -1 (Unlimited)

PHP-5 mcrypt won't enable on nginx server ubuntu 14.04

I've been trying to install mcrypt extension for php5 on Ubuntu 14.04 ARM server running nginx.
PROBLEM
In phpinfo() I can only see the authors of mcrypt but the module itself is missing. I can't use mcrypt functionalities anywhere on that server.
WHAT I TRIED
Running php5 -m shows that mcrypt is installed.
In /etc/php5/fpm/php.ini I have the following extension = /usr/lib/php5/20121212+lfs/mcrypt.so. This I read in google after I tried only with extension = mcrypt.so. Neither gave result.
In /etc/php5/fpm/conf.d/20-mcrypt.ini I have this extension=/usr/lib/php5/20121212+lfs/mcrypt.so as well.
I restarted php5-fpm and nginx multiple times, I also tried php5enmod mcrypt which doesn't show any warnings or errors.
I created symlink between the .so and .ini file.
Any ideas?
Ok so it turns out that my only escape was to purge php5-fpm, reboot the server, then apt-get install php5-fpm, now everything is loaded correctly. I have no idea why this happens. If anyone has explaination I'll be happy to update my answer with it.

pdo_mysql is not available on centos 6.7

I have a CentOs 6.7 server.
I have problem to make pdo_mysql available on apache2.
following shows for Command line:
myserver$ php -m
PDO, pdo_mysql, pdo_sqlite
but phpinfo(), shows only PDO and pdo_sqlite
I already included following in php.ini
extension=pdo_mysql.so
extension=pdo.so
And restarted the Apache with:
sudo service httpd restart
It looks like, pdo_mysql is installed on a different php.
when I search the server for pdo.so and pdo_mysql.so, I get pdo.so in three places, but pdo_mysql in two places.
myserver$ locate pdo.so
/usr/lib64/php/modules/pdo.so
/usr/lib64/php-zts/modules/pdo.so
/var/opt/remi/php56/root/usr/lib64/php/modules/pdo.so
myserver$ locate pdo_mysql.so
/usr/lib64/php/modules/pdo_mysql.so
/usr/lib64/php-zts/modules/pdo_mysql.so
And Apache installation in phpinfo() shows:
Loaded Configuration File /opt/remi/php56/root/etc/php.ini
So my recent php upgrade to php 5.6 is missing pdo_mysql.
other php installation has it, but I don't know how to force the pdo_mysql installation to install it to /var/opt/remi/php56/
I used following for installing pdo-mysql:
yum install pdo-mysql
So, it installed it under, /usr/lib64/php/, but not under,/var/opt/remi/php56/ Any help or advice is appreciated
It seems you are confused by the 2 available PHP stacks in remi repository.
php-* packages = base packages with configuration in /etc
php56-php-* packages = software collections for parallel installation with configuration in /opt
Also see the FAQ
And Apache installation in phpinfo() shows: Loaded Configuration File /opt/remi/php56/root/etc/php.ini
This means you are using the SCL version. So you need php56-php-mysqlnd
I already included following in php.ini
You never have to change the php.ini, each package provides its configuration file which enable the extension (and ensure correct load order, e.g. pdo "before" pdo_mysql)
I recommend you follow the Configuration Wizard results
Ok, I finally found the solution to the problem.
I was trying to install missing pdo_msyql extension, but yum was saying the package is not available.
Then by installing following the problem was solved.
yum install php-ZendFramework-Db-Adapter-Pdo-Mysql.noarch
Thanks everyone for your helps.

How to install and activate PDO for PHP 7? [duplicate]

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'.

different versions of php being used

I am trying to install magento and it keeps throwing the error "PHP extension mcrypt must be loaded". When I tried to install mcrypt I got a message that it is already installed.
So I ran php -v, which php and php -i | grep mcrypt in the command line and got back
PHP 5.4.23 (cli)....
and
/usr/local/bin/php
and
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
So I added phpinfo(); die(); to my index.php magento file and that returned
Version 5.4.17
Configuration File (php.ini) Path /etc
Loaded Configuration File /etc/php.ini
but no reference to mcrypt
Am I right in reading that as magento is using a different version of php to what the commandline is? and if so how do I resolve this situation?
I am running other installs of Magento and so when I considered trying to delete /etc and letting Magento automatically pick up the correct version, I decided against it as I don't want the other installs to stop working.
You are right when you say that magento is using different php version (altough only subversion). It is most likely that your cli .ini is different from apache .ini
What you can try is add extension=mcrypt.so to /etc/php.ini and restart apache
Echo your phpinfo(). Via cmd it's possible to receive other information then needed. You'll see which PHP version is used and where your php.ini is located.
Open php.ini and search for ;php_mcrypt.dll. Remove the semicolon and restart Apache.
Edit: for Linux versions:
apt-get install php5-mcrypt
service apache2 restart - restart Apache
If you get the 'already installed' message you could use:
apt-get --reinstall install php5-mcrypt
Make sure that the semicolon is remove in php.ini: extension=mcrypt.so

Categories