I'm currently working on a website. I used the host's control panel to activate several php modules. Now when I try to use them it returns
Fatal error: Class '...' not found
I checked phpinfo() and the classes appear there, but when I do php -m, they are missing. The server uses Nginx.
What can be the problem and how can I fix it?
Your PHP web installation and your PHP cli installation can be two completely seperate things, and hence they usually have their own ini configuration files.
As per your comment, this is the output you get from your CLI phpinfo:
Loaded Configuration File: (none)
Scan for additional .ini files in: /usr/opt/php56/etc/php
Additional .ini files parsed: (none)
As you can see there's no "Loaded Configuration File". As per this post you can specify what ini file to load when running cli scripts.
Since your regular web installation says:
Loaded Configuration File /home/a2869511/etc/php.ini
Then you can automatically have your CLI program execute with the same ini file:
php --with-config-file-path=/home/a2869511/etc/php.ini script.php
That said, I would recommend that you take a copy of the ini file and place it where your cli application is looking for ini files, which is in /usr/opt/php56/etc/php ("Scan for additional .ini files in").
So the short solution would be to do the following copy:
cp /home/a2869511/etc/php.ini /usr/opt/php56/etc/php/php.ini
Related
I'm using Ubuntu LTS 14.04 operating system and I'm trying to test my PHP scripts in the PHP CLI, but wherever my code attempts to connect to MySQL, with commands such as...
$mysqli = mysqli_connect($host,$user,$password,$database);
...,I get the following error:
Fatal error: Call to undefined function mysqli_connect()...
I've reviewed /etc/php5/cli/php.ini AND /etc/php5/apache2/php.ini and have found no difference.
I think that I must enable mysqli support for the command line interface (CLI), but I am uncertain.
How can I correct the error without affecting my current Apache php.ini/configuration/installation?
EDIT:
Based on comments, I ran the following command in terminal:
php --ini
Which displays:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Then, I copied /etc/php5/cli/php.ini to /usr/local/lib/php.ini.
Then, I ran php --ini again, which displays:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Then, I ran the PHP script from PHP CLI again, and the same error displayed.
Call to undefined function mysqli_connect()
Means the mysqli exension is not loaded.
I've reviewed /etc/php5/cli/php.ini AND /etc/php5/apache2/php.ini and have found no difference.
I would be very surprised if they were same. But in both cases, these are likely to be structured to work with extesnions distributed via packages - i.e. the ini file containing the directive to load the mysqli so extension will likely reside elsewhere and be included (or not) from these files.
Configuration File (php.ini) Path: /usr/local/lib
You have a Frankenstein system. You need to clean this up. Either use the distro's packaged apps or install apps from tarball. Don't use tarballs unless you know what you're doing. Don't mix and match unless you really know what you are doing.
Delete the tarball PHP files
reinstall the Ubuntu PHP cli
reinstall the Ubuntu PHP mysqli extension
test.php:
if (!extension_loaded('mysqli')) {
dl('mysqli.so');
}
in cli,run it:
php test.php
os output:
Warning: dl(): Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/mysqli' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mysqli: cannot open shared object file: No such file or directory in test.php
you can find and copy mysqli.so from any where, for example:
/usr/local/lib/php/extensions/no-debug-non-zts-20131226$ sudo cp /usr/lib/php5/20131226/mysqli.so ./mysqli.so
Hello I'm using latest version of Laravel, PHP 7.1.9 and MySQL 5.7.19. I'm also using WAMP stack.
When I run the command:
php artisan migrate
I get the following error:
I googled a lot and I' m 100% sure my php.ini file does not have the driver line commented out and the driver is properly working, as seen here:
The driver is obviously present:
Also the path to extension dir is absolute:
extension_dir ="c:/wamp64/bin/php/php7.1.9/ext/"
What else can I do? This thing is driving me crazy
There are 2 php.ini files in the WAMPServer implementation.
One for APACHE which is the one accessed from the menu system and one in each wamp\bin\php\phpx.y.z folder
As you are using the PHP CLI you have to check that all the required extensions are also activated in PHP you are using for the CLI wamp\bin\php\phpx.y.z
Do this from the command line
php --ini
It should show you something like this
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File: C:\wamp64\bin\php\php7.0.29\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Look at this param Loaded Configuration File: to see which php.ini file you should be checking.
This post may also be useful to you for making a batch file to run from the command prompt to switch easily from one version of PHP CLI to another from the command window How To Run PHP From Windows Command Line in WAMPServer
I'm using Ubuntu LTS 14.04 operating system and I'm trying to test my PHP scripts in the PHP CLI, but wherever my code attempts to connect to MySQL, with commands such as...
$mysqli = mysqli_connect($host,$user,$password,$database);
...,I get the following error:
Fatal error: Call to undefined function mysqli_connect()...
I've reviewed /etc/php5/cli/php.ini AND /etc/php5/apache2/php.ini and have found no difference.
I think that I must enable mysqli support for the command line interface (CLI), but I am uncertain.
How can I correct the error without affecting my current Apache php.ini/configuration/installation?
EDIT:
Based on comments, I ran the following command in terminal:
php --ini
Which displays:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Then, I copied /etc/php5/cli/php.ini to /usr/local/lib/php.ini.
Then, I ran php --ini again, which displays:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Then, I ran the PHP script from PHP CLI again, and the same error displayed.
Call to undefined function mysqli_connect()
Means the mysqli exension is not loaded.
I've reviewed /etc/php5/cli/php.ini AND /etc/php5/apache2/php.ini and have found no difference.
I would be very surprised if they were same. But in both cases, these are likely to be structured to work with extesnions distributed via packages - i.e. the ini file containing the directive to load the mysqli so extension will likely reside elsewhere and be included (or not) from these files.
Configuration File (php.ini) Path: /usr/local/lib
You have a Frankenstein system. You need to clean this up. Either use the distro's packaged apps or install apps from tarball. Don't use tarballs unless you know what you're doing. Don't mix and match unless you really know what you are doing.
Delete the tarball PHP files
reinstall the Ubuntu PHP cli
reinstall the Ubuntu PHP mysqli extension
test.php:
if (!extension_loaded('mysqli')) {
dl('mysqli.so');
}
in cli,run it:
php test.php
os output:
Warning: dl(): Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/mysqli' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/mysqli: cannot open shared object file: No such file or directory in test.php
you can find and copy mysqli.so from any where, for example:
/usr/local/lib/php/extensions/no-debug-non-zts-20131226$ sudo cp /usr/lib/php5/20131226/mysqli.so ./mysqli.so
In phpInfo, MAMP's Loaded Configuration File is different to the one output when running php --ini:
Loaded Configuration File: /Library/Application Support/appsolute/MAMP PRO/conf/php.ini
Even though, directly above it states the same .ini file as output in the command line:
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.5.10/conf
Is there a way to get MAMP to load the configuration file listed in the row Configuration File (php.ini) Path which is also output with php --ini? Or do I just have to edit the one that MAMP is using?
which php outputs that it is using MAMP's php system:
/Applications/MAMP/bin/php/php5.5.10/bin/php
One php.ini for CLI (command line) and one for web server.
Keep them separated.
If you want to change the way php behave do it depending of the context.
For cli, change the php.ini you find doing php --ini -> Loaded Configuration File
For web server change the file found when doing a phpinfo() from your browser.
I have set up PHP 5.3.10 on a RHEL 4 server.
When I ran php -i | grep "Loaded" it returned
Loaded Configuration File => (none)
It's OK with that setup. PHP is working the way we needed it to. I just need to know, if no php.ini is being used, where does PHP get all its settings? Thanks.
Update: I realized this after I hit submit. Sorry, how do I move this to Stack Overflow? -_-
Update 2: Result of 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)
If there is no php configuration file loaded it just takes the default values. Please check the documentation to have the list of the default values :
http://php.net/manual/en/ini.core.php
It may depend on your server setup.
It could be (depending on PHP version) that the PHP configuration is controlled from within the Apache configuration files:
How to change configuration settings
You can use the phpinfo() function to view your PHP configuration settings (including the config file directory). Create a file called info.php (for example in the folder that is the "DocumentRoot"), and edit the file to contain the following code:
<? phpinfo(); ?>
So, if your domain is:
http://example.com
And your "DocumentRoot" is:
".../www" or ".../public_html"
Place the file in that folder and then using a browser, go to:
http://example.com/info.php
This should show you all the settings.
First of all you got to understand that command line PHP uses another php.ini. And Apache (or NGINX etc.) module uses another php.ini.
You may try use more reliable command: php --ini rather than php -i to make sure it's not loading any configs.
Usually it loads php.ini from /etc/php5
If the command is not showing you anything, so you may try to add that file (/etc/php5/cli/php.ini) manually and check.
In RedHat it may be directly on /etc/ directory.