I am doing a tutorial and am getting this error:
Fatal error: Class 'MySQLi' not found (LONG URL) on line 8
The code on line 8 is:
$mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name);
I saw online someone said to see if it was turned on in my phpinfo(), but there wasn't anything listed in there under for "mysqli".
Also, I am running PHP version 5.2.5
Sounds like you just need to install MySQLi.
If you think you've done that and still have a problem, please post your operating system and anything else that might help diagnose it further.
You can check if the mysqli libraries are present by executing this code:
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'We don\'t have mysqli!!!';
} else {
echo 'Phew we have it!';
}
If you are on Ubuntu, run:
sudo apt-get install php-mysqlnd
And don't forget to restart the php service after this (Apache or php-fpm depends on the setup).
If you're calling "new mysqli(..)" from within a class that is namespaced, you might see a similar error Fatal error: Class 'foo\bar\mysqli' not found in. The way to fix this is to explicitly set it to the root namespace with a preceding backslash like so:
<?php
$mysqli = new \MySQLi($db_server, $db_user, $db_pass, $db_name);
In addition to uncommenting the php_mysqli.dll extension in php.ini, also uncomment the extension_dir directive in php.ini and specify your location:
extension_dir = "C:\software\php\dist\ext"
This made it work for me.
If you are on Docker...
Inside php-container RUN:
#docker-php-ext-install mysqli
#apachectl restart
My OS is Ubuntu. I solved this problem by using:
sudo apt-get install php5-mysql
How to Enable mysqli in php.ini
Edit/uncomment by removing ';'(colon) the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=C:/PHP/ext/php_mysql.dll
extension=C:/PHP/ext/php_mysqli.dll
Restart the IIS server
Make sure that mysql is running on the system.
How to load php.ini file
Rename any one of the file php.ini-production/php.ini-development to php.ini from C:\PHP(note now the extention will be ini i.e "php.ini").
After renaming to php.ini file restart server
See the changes in http://localhost/phpinfo.php
For anyone using docker, I ran into this issue, and resolved it by using my own Dockerfile instead of the php:fpm image:
FROM php:fpm
RUN docker-php-ext-install mysqli
Seems like problem with your installation.
Have you installed MySQLi?
Have you activated it in php.ini?
Restarted Apache and/or PHP-FPM?
http://www.php.net/manual/en/mysqli.installation.php
Open your PHP folder.
Find php.ini-development and open it.
Find ;extension=mysqli
delete the ; symbol
save file and change the file extension from php.ini-development to php.ini
Restart the server and test the code:
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'We don\'t have mysqli!!!';
} else {
echo 'mysqli is installed';
}
if it not working, change both extension_dir in php.ini from "ext" to "c:\php\ext"
and extension=mysqli to extension=php_mysqli.dll then test again
Remember to reset the server every time you test
The PHP zip includes most of the commonly used extensions (*.dll on windows such as php_mysqli.dll) under the \ext directory, however they are not enabled by default. You might be getting this Fatal Error when trying to use MySQLi:
( ! ) Fatal error: Uncaught Error: Class 'mysqli' not found in C:\myProject\ class.Database.php on line 24
To enable extensions, open php.ini (you might need to first copy php.ini-development as php.ini), and un-comment (or add) these two lines:
extension_dir = "ext"
And any particular extensions you are getting Fatal Errors for, i.e. for mysqli:
extension=mysqli
On a fresh install of PHP, remove ; before extension_dir in php.ini.
I thought I might help anybody with the same problem using Namesco servers.
I have been trying to fix this problem after moving a database from my local server on home pc to namesco. They would not assist they said it was a coding issue.
However, it was simple to fix from their CPANEl LINUX hosting
interface.
Click on php.
then click on php modules and from their list of preinstalled modules just click the box for mysqli.
Then click save. (No need to change code if it worked(s) on another server.)
Unfortunately, their support articles were a waste of time. After reading this I went to admin interface with a new determination.
Some distributions (such as Gentoo) support multiple installations of PHP, and you have to make sure you're using one with mysqli installed and enabled.
On Gentoo, I had installed a new PHP (with the mysqli USE flag enabled), but I needed to activate the new version of PHP (since the old one must have been missing mysqli):
# eselect php list apache2
[1] php5.3 *
[2] php5.5
# eselect php set apache2 2
You have to run `/etc/init.d/apache2 restart' for the changes to take effect
# /etc/init.d/apache2 restart
I checked all above and it didn't work for me,
There are some steps I found.
I used PHP Version 5.5.9-1ubuntu4.17 on Ubuntu 14.04
First check the folder
#ls /etc/php5/mods-available/
json.ini mcrypt.ini mysqli.ini mysql.ini mysqlnd.ini opcache.ini pdo.ini pdo_mysql.ini readline.ini xcache.ini
If it did not contain mysqli.ini, read other answer for installing it,
Open php.ini find extension_dir
In my case , I must set extension_dir = /usr/lib/php5/20121212
And restart apache2 : /ect/init.d/apache2 restart
on ubuntu:
sudo apt-get install php-mysql
sudo service apache2 restart
on Debian 10
apt install php-mysql
/etc/init.d/apache2 restart
I found a solution for this problem after a long analysing procedure.
After properly testing my php installation with the command line features I found out that the php is working well and could work with the mysql database. Btw. you can run code-files with php code with the command php -f filename.php
So I realized, it must something be wrong with the Apache.
I made a file with just the phpinfo() function inside.
Here I saw, that in the line
Loaded Configuration File
my config file was not loaded, instead there was mentioned (none).
Finally I found within the Apache configuration the entry
<IfModule php5_module>
PHPINIDir "C:/xampp/php"
</IfModule>
But I've installed the PHP 7 and so the Apache could not load the php.ini file because there was no entry for that.
I added
<IfModule php7_module>
PHPINIDir "C:/xampp/php"
</IfModule>
and after restart Apache all works well.
These code blocks above I found in my httpd-xampp.conf file. May it is somewhere else at your configuration.
In the same file I had changed before the settings for the php 7 as replacement for the php 5 version.
#
# PHP-Module setup
#
#LoadFile "C:/xampp/php/php5ts.dll"
#LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"
LoadFile "C:/xampp/php/php7ts.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
As you can see I have the xampp package installed but this problem was just on the Apache side.
install
phpXX-extension by PHP.
In my FreeBSD's case:
pkg install php74-extensions
I'm using xampp and my problem was fixed once i rename:
extension_dir = "ext"
to
extension_dir = "C:\xampp\php\ext"
PS: Don't forget to restart apache after making this change!
In php.ini :
extension_dir ="c:/wamp64/bin/php/php7.4.9/ext/"
Make sure the PHP version is correct.
All you have to do is go to the php.ini file and on line 926 (depending on version) delete #. It should look like this:
;extension=ldap
;extension=mbstring
;extension=exif
extension=mysqli
;extension=oci8_12c
;extension=odbc
Save the file and open console (cmd) as administrator. Go to the path Apache24 / bin and enter httpd -k restart. This command will restart your server. After that, refresh the page and everything should work.
When I tried my PHP web app it was giving me the same error.
By googling I found out the MySQL plugin for the PHP server was missing with my installation. I am using Ubuntu, so when I tried MySQL plugin for PHP I found out 2 are there,
php-mysql and php<version>-mysql
I issued command - php --version in my terminal, I was having php7.4,
again I issued apt install php7.4-mysql
It worked.
This issue can be also caused by the .htaccess file misconfiguration.
Related
i'm running phpMyAdmin 4.6.6deb5 on the following configuration:
Ubuntu Server 18.04.3
nginx/1.17.9
7.2.24-0ubuntu0.18.04.3
phpMyAdmin seems to work, but there's this red error message that says something about the blowfish secret. Somehow there's no way to get rid of it. The error-log contains the following entries:
2020/03/22 21:46:30 [error] 26664#26664: *53 FastCGI sent in stderr: "PHP message: phpmyadmin: Failed to load /var/lib/phpmyadmin/blowfish_secret.inc.php Check group www-data has read access and open_basedir restrictions.
PHP message: phpmyadmin: Failed to load /var/lib/phpmyadmin/config.inc.php Check group www-data has read access and open_basedir restrictions" while reading response header from upstream, client: 87.147.18.48, server: ***, request: "GET /phpmyadmin/js/get_image.js.php?theme=pmahomme&v=4.6.6deb5 HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "***
Both, the folder and the files, are assigned to www-data. I've also assigned the following permissions:
# chmod 755 /var/lib/phpmyadmin
# chmod 664 /var/lib/phpmyadmin/blowfish_secret.inc.php
# chmod 664 /var/lib/phpmyadmin/config.inc.php
Doesn't work...
What seems strange to me is the fact that the config.inc.php is empty and the blowfish_seceret.inc.php looks like this:
<?php
$cfg['blowfish_secret'] = 'j(<purKyJl>5D]yzlPoKFLNfH9es6.-T';
It seems like both files are broken. Could anybody tell me where I can find right files? I know that there are several config.inc.php files in different folders, some of them including the line for the blowfish_secret, but I don't know which of them is the right one to copy to /var/lib/phpmyadmin.
I've found similar issues while searchig on stackoverflow and other forums, but none of the suggested solutions worked for me.
Thanks in advance
Best Regards, Boris
There are a couple of odd things about your setup, one of which is that package managers would usually put configuration files in etc/phpmyadmin, not /var/lib/phpmyadmin. In addition, version 4.6.6 is quite old.
If you want to continue to troubleshoot your existing installation, I suggest you start looking in to whether there are any open _basedir restrictions. Look at the output of phpinfo().
Create a new text file in your webserver root directory. You can call it whatever you'd like, such as phpinfo.php. The text file should contain
<?php
phpinfo();
Load that up in your browser and search the output for open_basedir. That will show what you have configured, and also near the top there's a section that will tell you which configuration files are being read, so you can start guessing where to fix it if there is a misconfiguration.
Upgrading
If your PHP and MySQL versions will support it (and PHP 7.2 will, so you are probably okay), I suggest installing the recent version from the phpMyAdmin PPA. You should first remove what you can on your local system of the existing phpMyAdmin package, including the /var/lib/phpmyadmin and /etc/phpmyadmin folders (the usual disclaimer about making a backup first applies even though none of this should be destructive). You may wish to save your configuration file config.inc.php if you've made customizations that you want to keep.
These should be compatible and updated.
Easy automatic install
Probably you only need two lines to add the PPA, then you can search for 'phpmyadmin' with your favorite package managing tool such as aptitude:
sudo add-apt-repository ppa:phpmyadmin/ppa
sudo apt-get update
Manual install
If your system doesn't have apt-repository or something else goes wrong, there are manual instructions there, which are basically this:
You probably have to add the PPA as an apt source, which you can do with
sudo echo "deb http://ppa.launchpad.net/phpmyadmin/ppa/ubuntu bionic main" > /etc/apt/sources.list.d/phpmyadmin.list
Try to update apt: apt-get update. You'll probably get a key error, which we expect because you don't have the proper key to verify downloads yet. When you get the error, note the key ID.
Retrieve the key: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2EA3055293CB3F45 (at the moment, that is the key that I needed, but that could change, so it's better to copy and paste it from the error message and substitute that in this command).
Finally, you can update the package list again with apt-get update then install the phpmyadmin package with your favorite apt-flavored tool.
I am trying to install Symfony on my Mac. Using the Terminal I have carried out the first three lines of the guide:
sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony
symfony new my_project_name
This started to download the files and then I got this message:
Preparing project...
Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in phar:///usr/local/bin/symfony/src/Symfony/Installer/NewCommand.php on line 283
✕ Symfony 3.2.8 was successfully installed but your system doesn't meet its
technical requirements! Fix the following issues before executing
your Symfony application:
date.timezone setting must be set
Set the "date.timezone" setting in php.ini* (like Europe/Paris).
I've tried to find the php.ini file but it doesn't appear in a search.
So, where can I find it and if it is a hidden file - how do I unhide it?
Thanks
You should find it in /private/etc if it exists, otherwise:
sudo cp /private/etc/php.ini.default /private/etc/php.ini
https://stackoverflow.com/a/9343210/7888593
Or to answer your question,in terminal.app type
php --ini
In your Terminal just type the following:
php -i | grep ini
There you can see which php.ini is used (including the full path)
Your webserver might use a different ini but the installation should work.
You can find it also by adding
<?php phpinfo(); ?>
anywhere in a php file
This way you are sure to get the php.ini used by your project and not by your computer
I am trying to start a project using Symfony on a Mac Sierra.
I installed Symfony successfully, but I get this warning:
We selected the timezone 'UTC' for now, but please set date.timezone
to select your timezone. in
phar:///usr/local/bin/symfony/src/Symfony/Installer/NewCommand.php on
line 283 ✕ Symfony 3.2.1 was successfully installed but your system
doesn't meet its
technical requirements! Fix the following issues before executing
your Symfony application: * date.timezone setting must be set
> Set the "date.timezone" setting in php.ini* (like Europe/Paris).
I tried to change php.ini with brackets editor on the created project on folders:
project/vendor/doctrine/cache/test/travis/php.ini
project/vendor/doctrine/doctrine-cache-bundle/test/travis/php.ini
Didn't help.
As I read Symfony has built-in Apache Server.
Those php.ini files are totally unrelated to what you have to do.
Open up the Terminal and type php -i | grep "php.ini". That should reveal the location of the php.ini which is used by PHP in console mode.
XAMPP is known for using different php.ini file for the server. In order to find the the one used by the XAMPP, run a sample php file with phpinfo() from browser.
Also, note that Symonfy itself does not have the built-in server. In merely used the one PHP provided from version 5.4 and on.
Hope this helps...
I am Mac user, so , in Finder you need to go to /private/etc, find php.ini.default,
Yo need to copy that file to the desktop. To edit you need to unlock the document. Just click Unlock if asked. Rename to php.ini, set the date.timezone=Europe/YourCountry and do not forget to erase the semicolon before.And finally save it and put it back to etc.
Watch: https://www.youtube.com/watch?v=Wb6Fh-B3W-o
I am trying to install Symfony2 on my localhost (MAMP), I followed the installation instruction available on the official Symfony site.
First i installed the composer and moved it to a specific directory.
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
I then executed the installation command:
composer create-project symfony/framework-standard-edition *my-project-path-in-MAMP-htdocs*/ "2.5.*"
During Installation process I am prompted with a question if I want to instal Acme bundle I type 'y' to confirm that I do want to instal this Bundle....
But during the installation of that Bundle I get this Error message:
Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /Applications/MAMP/htdocs/Symfony/project1/vendor/monolog/monolog/src/Monolog/Logger.php line 233
Can anyone help me or suggest a solution...?
You need to set the parameter date.timezone in your php.ini for every valid timezone and after that do not forget to restart Apache, try if this solve your issue
Procedure
I'm not use LAMP environment since I work with Linux but things should be the same as Mac is *nix. Anyway, you should find where php.ini file is under your directory structure (again I not use MacOS so I can't help here) and open it with any text editor or console text editor (personally I prefer this one) and find for that string date.timezone when you found it just uncomment that line by removing the ; symbol at front of the string and add a valid timezone lets said for example Europe/Amsterdam then you should have something like:
date.timezone = Europe/Amsterdam
That's all, restart your LAMP environment if you use any stack application or just restart Apache service, that will be all
when running
phpunit
I get error
Warning: require(PHPUnit/Autoload.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 42
Fatal error: require(): Failed opening required 'PHPUnit/Autoload.php' (include_path='.:') in /usr/local/bin/phpunit on line 42
/usr/local/bin/phpunit displays the following on line 42:
require 'PHPUnit/Autoload.php';
any suggestions how to fix this?
Update (1):
I was missing php.ini in /etc/, so I symlinked it to read the MAMP php.ini. Now I get
php -r 'foreach (explode(":", get_include_path()) as $path) echo $path . PHP_EOL;'
.
/Applications/MAMP/bin/php/php5.3.6/lib/php
/usr/local/bin/pear
/usr/local/share/pear/PHPUnit
running
phpunit
is running but provides no output.
Any suggestions what to check next?
Update (2):
probably the root cause of this issue is related to question
MAMP PEAR configuration is pointing to local directories.
I hit a similar issue on MAC OSX Lion. I installed phpunit with the PEAR package manager, and when I try to run it I got the error as described by udo. I was able to resolve it with the following simple steps:
Get the latest php archive of pear curl http://pear.php.net/go-pear.phar > go-pear.php
Install the archive with sudo php -q go-pear.php
During installation, it detects if the include_path in your php.ini does not contain the PEAR PHP directory. You can choose to let it fix it for you automatically when given the option.
I ran into this problem when I was running phpunit.phar from my local directory, but also has PHPUnit installed as a composer dependency. Removing the PHPUnit composer dependency fixed my problem.
You must have the folder that contains the PHPUnit source files on your PHP include path. Also, PHPUnit/Autoload.php was added in 3.6, and it's possible you have an older 3.5.x source folder instead. Check the folders listed using
php -r 'foreach (explode(':', get_include_path()) as $path) echo $path . PHP_EOL;'
(or on Windows)
php -r"foreach (explode(':', get_include_path()) as $path) echo $path . PHP_EOL;"
and make sure one of them contains a PHPUnit folder with Autoload.php.
Update: Regarding your update, you probably want to remove /usr/local/share/pear/PHPUnit from the include path because you're including PHPUnit/Autoload.php which should be located in /usr/local/share/pear which is already in the include path.
To make sure PHPUnit is working first run phpunit --version so you can see the installed version. PHPUnit instantiates all of the test cases it plans to run before outputting anything. If any of your test cases cause a fatal error while loading, sometimes no output is shown at all. This is very frustrating. Start by creating the simplest test case possible that doesn't use any of your code.
class MyTest extends PHPUnit_Framework_TestCase {
function testThatItWorks() {
self::assertTrue(true);
}
}
Running this test should produce a single passing test. Try it and paste what you see in your question.
To add to the previous answers: double-check with php.ini file is being loaded and make sure you edit THAT file with additional paths. I used the following to check the loaded php.ini
php -r 'phpinfo();'
Which told me that the loaded php.ini file was /private/etc/php.ini
Then I used "which" to tell me where phpunit had been installed:
which phpunit
Then I added that path to the php.ini file, so it ended up looking like this:
;***** Added by go-pear
include_path=".:/Users/admin/pear/share/pear:/php/includes:/usr/bin:/usr/lib/php/"
Only after I had done all that did the "phpunit --version" and other commands work as expected.
It should be noted that most users who face the problem faced here must be running the command
$ phpunit
from the command prompt. when they get the above error. What Most of us fail to understand about the real issue is that the PHP used on the command prompt will mostly be very different from the one running things for you in your webserver. Personally i use lampp and even though i had correctly installed phpunit using pear successfully,i failed to realised this essential part for hours.
Remedy
- for anytime you need to run a PHP script that requires resources in the include_path, make sure that php.ini for the respective PHP binary your using is adequately furnished. case and point in my ubuntu 12.04 installation with xampp my two php binaries include
the command line one i.e php5-cli found in /etc/php5/cli/ directory
the xampp one i.e php that is used by apache to serve my pages found in /opt/lampp/etc/php.ini
Both the php.ini files must have your desirable and correct include_path declaration for you to correctly bootstrap any command line scripts and serverside(apache served scripts).
Back to our matter at hand after correctly configuring the php.ini remember to
Restart Apache so that the web server pick your changes
Restart you terminal/commandline session so that the cli prompt picks your changes
Common Mistakes that get you problems when Changing Files in Linux/*nix Systems
remember to run chwon to own the php.ini file or else you wont even manage to edit them
remember to run chmod and change the values to allow you to save your changes after which you can return everything (access control on file i.e chwon and chmod to the previous state) to the way they were and it should be ok after restarting the terminal and apache.
Good Luck
The remark of Howard Lo on Mac OSX is very useful with the remark of Sebastian Perez. Because the remark is not that nice formatted, it maybe overlooked. After the Mavericks update of OSX I ran for the second time to this issue, U decided to create this full Apple OSX solution for this problem. I have to say I have also installed MAMP-PRO with several different version of php, so I need to be very accurate.
Check if you have an php.ini installed into /private/etc. If not issue the command:
$ sudo cp /private/etc/php.ini.default /private/etc/php.ini
Get the latest php archive of pear
$ curl http://pear.php.net/go-pear.phar > go-pear.php
Install the archive with
$ sudo php -q go-pear.php
During installation, it detects if the include_path in your php.ini does not contain the PEAR PHP directory. You can choose to let it fix it for you automatically when given the option.
After these steps I had to install phpunit again using the following commands:
$ sudo pear channel-discover pear.phpunit.de
$ sudo pear channel-discover components.ez.no
$ sudo pear channel-discover pear.symfony-project.com
$ sudo pear install phpunit/PHPUnit
Many thanks to Howard Lo and Sebastian Perez.