What is the default path for PHP extensions in php.ini? - php

I'm getting back in to web development so have decided to re-install my Mac's dev environment from scratch with homebrew (I'm following the tutorial at https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions which is probably the best tutorial on the subject that I've ever read).
Everything is going fine apart from using PECL to install extensions like APCU and Xdebug. I think I can get extensions working in a slightly hacky way, but I'd rather properly understand what's going on here.
My php.ini file is located at /usr/local/etc/php/7.1/php.ini. When PECL installs an extension, it seems to add a line to the top of php.ini immediately above the [PHP] line, e.g.:
1 zend_extension="xdebug.so"
2 extension="apcu.so"
3 [PHP]
4
5 ;;;;;;;;;;;;;;;;;;;
6 ; About php.ini ;
7 ;;;;;;;;;;;;;;;;;;;
8 ; PHP's initialization file, generally called php.ini, is responsible for
9 ; configuring many of the aspects of PHP's behavior.
The tutorial advises going to /usr/local/etc/php/7.1/conf.d/ and creating individual config files for each extension. i.e., lines 1 and 2 in php.ini would be deleted, and /usr/local/etc/php/7.1/conf.d/ext-apcu.ini and /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini would be created, with config settings for each extension included in the relevant ext-xx.ini file.
Neither the default PECL approach of referencing the extension in php.ini nor the recommended approach of using an ext-xx.ini file for each extension seems to load the extensions successfully. I can hack round this by specifying a path to the extensions (/usr/local/lib/php/pecl/somedatestamp/extension.so), but I'd rather not have to. So:
(I'm pretty sure the answer to this is "yes", but just to be sure): does the server just scan through the conf.d folder and try to load any extension.so that is described in every ext-extension.so file it finds?
How do I set the equivalent of $PATH for my PHP configuration? phpinfo() refers to an extension_dir variable and gives the value as /usr/local/Cellar/php#7.1/7.1.20/lib/php/20160303, and there's an extension_dir variable set in php.ini but it's commented out. So where is PHP getting the value it's displaying through phpinfo(), and is it possible to specify multiple directories where PHP will look for extensions?

Server doesn't scan for *.so files automatically, it loads extensions mentioned in php config files in extension=extension.so and zend_extension=extension.so configurations. To check all config files which are loaded during server start run the command php --ini, my example output is:
$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.1
Loaded Configuration File: /usr/local/etc/php/7.1/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.1/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.1/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.1/conf.d/ext-phalcon.ini,
/usr/local/etc/php/7.1/conf.d/ext-xdebug.ini,
/usr/local/etc/php/7.1/conf.d/php-memory-limits.ini
In you case it looks like you might have messed versions: your config file is located in /usr/local/etc/php/7.1/php.ini (version 7.1) but you are trying to put additional config files in /usr/local/etc/php/5.6/conf.d/ (version 5.6). Try to put them in /usr/local/etc/php/7.1/conf.d
You should specify extension dir path in your php.ini, I have the value
extension_dir = "/usr/local/lib/php/pecl/20160303"
This value is valid for php version 7.1, timestamp 20160303 specifies PHP API version for the extensions.
You can also check that PECL configuration for the extension dir has the same value as in php config using the command
pecl config-get ext_dir
After these steps you can check if extension is loaded with the command
php -m
It lists all the loaded php modules and extensions. If some extension is mentioned in config file but could not be loaded, you will get warning.

Related

Missing php_yaml.dll file

I'm using XAMPP with PHP 5.5.27 PHP and Windows 10 (x64). I'm triyng to install the YAML extention. Link from other topic is dead so I dowloaded files version PHP 5.5, x64, TS and NTS.
I placed file php_yaml.dll into c:\xampp\php\ext and yaml.dll files into c:\xampp\.
Then I added entry extension=php_yaml.dll just after extension=php_xsl.dll (as last entry of Dynamic Extensions.
At the end I restarted Apache.
Result is:
phpinfo() doesn't display info about YAML extention.
You want the Thread Safe(TS) version and as to 32/64bit it should match your XAMPP version rather than your OS version so if you have a 32bit XAMPP you need the 32bit php_yaml.dll Also you should only need to place it in the c:\xampp\php\ext folder
Also remember that there are 2 php.ini files. One in the c:\xampp\apache\bin folder that Apache uses and one in c:\xampp\php\php.ini, it is this one that controls PHP's config when being used from the CLI (Command Line Interface) So you also need to add the extension=php_yaml.dll to this php.ini file as well if you want command line PHP to load this extension.
To check which php.ini file is being loaded in the CLI do this from the command line
php -ini | more
Look for this entry
Loaded Configuration File => D:\wamp\bin\php\php5.6.15\php.ini
Check that yours says something sensible for your system

Composer can't find ext-mbstring even though it is installed

When I attempt to install Laravel 5 I get a dependency error. I'm using Uniform Server on Windows 7. I have enabled php_mbstring.dll and I checked it's loading properly. (I think)
Here is the console output (Composer):
Here are the extensions in my php.ini
Here are the phpinfo() mbstring details:
I don't know where to go from here.
Any idea?
Pay attention that, both in Windows and Linux, PHP can run with multiples php.ini configuration files.
In general, when you find this kind of issue, you have to double check that the configuration file loaded is the same that you are editing or you need to find the right path and add the extension also to the right php.ini configuration file.
While running a script through a web server, you can find the configuration file using the function
phpinfo();
and checking the line "Loaded Configuration File" (or just look for php.ini)
For what concern the CLI you can run in CMD
php --ini
and check the first lines in order to find the Loaded Configuration File value.

Windows, NetBeans: Where's the php.ini?

I have been away from PHP for quite a while, so hopefully this is a simple oversight. But, I am not able to include the MySQL extension.
Setup
Windows 8 Pro 64-bit
NetBeans 7.2.1 (Built-in PHP Web Server)
MySQL
PHP 5.4.8
Problem
Fatal error: Call to undefined function mysql_connect()
Attempted Resolution
Copy php.ini-development to php.ini (files are where I installed PHP, E:\Software\php-5.4.8-Win32-VC9-x86)
Edit php.ini by uncommenting the lines
extension_dir = "ext"
extension=php_mysqli.dll
Added E:\Software\php-5.4.8-Win32-VC9-x86\ext to NetBeans PHP Include Path in Project Properties
Still fails with the same error
Diagnostic Output
Added a call to phpinfo() at the top of the page. That indicates:
Configuration File (php.ini) Path C:\Windows
However, there is no php.ini in C:\Windows. In fact, I searched all disks and found only the one php.ini file that I previously edited.
Question
Where is NetBeans / PHP pulling the configuration from when I run my project, and how can I edit that configuration?
Restart the web server/netbeans :-)
If there's no php.ini file listed as being loaded by phpinfo() then there is not one. PHP will use default values for everything in this case. Anything that needs to be overridden can be placed in a new php.ini in one of the locations specified by phpinfo() as being scanned for ini files.
From your description what you did to php.ini (excerpt):
extension=php_mysqli.dll
^
But in your question you write:
Fatal error: Call to undefined function mysql_connect()
Which is a different extension, namely on windows:
extension=php_mysql.dll
(without the i)
Probably it's just a little oversight you're missing here. You have two options then:
Port the code to mysqli_* functions (recommended for new code)
Activate the old php_mysql.dll extension (for legacy code)
Do what fit's your needs. On windows, the folloing filenames (search your disk) are interesting:
php.ini - normally inside the directory where you find php.exe
php_mysql.dll - normally inside the ext subdirectory of the just said directory.

mongodb PHP extension not found?

I followed the manual, I mpved the php_mongo.dll into the PHP extension folder,
and added extension=php_mongo.dll to the php.ini file and it's given me an error when I try and you rockmango that "To make things right, you must install php_mongo module. Here for installation documents on PHP.net." but I have alread done this any solutions? I am running the lattest version of PHP and mongodb
Check php --ini shows the correct config file being used.
Check php -i (phpinfo) and make sure the module is actually loaded.
Double check you have the right flavour of the module for your version of PHP. (VC6, VC8, VC9, TS, NTS, etc.)
I got my mongo module (1.2.9) for PHP 5.4 32bit on windows from stealth35. It works like a charm.
Often there are multiple PHP locations with different php.ini files.
If you are worried about working in mod_php (through apache) or as a fastcgi then create a file with the following contents.
<?php phpinfo();
Then visit that file in a browser. It will have all the settings and modules listed that are currently being loaded. It will also tell you which php.ini file and modules directory being used.
Please make sure that the ini listed is the one you added mongo dll line.

Eclipse and Xdebug does not parse additional ini files in /etc/php5/conf.d

I have setup Eclipse 3.6.2 on Ubuntu 11.4 for AMD64 and Xdebug.
Eclipse was installed with zip download from eclipse.org.
PHP and Xdebug were setup with apt-get.
When I run the PHP script in the shell they will use the /etc/php5/php.ini file and parse additional ini files in /etc/php5/conf.d/.
When I run in Eclipse (run mode or debug mode) it will only parse php.ini and no additional ini files.
Basically, all extensions, are not loaded.
It is an intentional bug.
PDT executes php with "-n" option always. It makes additional ini files unavailable.
see https://bugs.eclipse.org/bugs/show_bug.cgi?id=339547
also https://bugs.eclipse.org/bugs/show_bug.cgi?id=347618
BTW, you'll be able to add a shell script which trims "-n" option as PHP Executable.(Preferences>PHP>PHP Executables)
For example,
#!/bin/sh
if [ $1 = "-n" ]; then
shift;
fi
/usr/bin/php $*
The answer #atlanto gives as a work around did and does still work, but recent version of Eclipse (I'm on Neon) has a fix that may work for you if you don't mind using the php.ini and conf.d set by default for the php executable.
The failing to load additional files only happens now if you put in an explicit php.ini file when defining a PHP executable. Leave this blank and check the box Use system default php.ini configurate.
Now if you use the location/php.ini that was specified as default when the executable was built, it will respect scanning of conf.d directories.
Here's how to check if your php has scanning conf.d enable and where the approriate default location is:
php -i "(command-line 'phpinfo()')" | grep "Configure Command"
You should see something like:
Configure Command => './configure' '--prefix=/usr/local/Cellar/php5/5.6.29_5'
'--localstatedir=/usr/local/var' '--sysconfdir=/usr/local/etc/php/5.6'
'--with-config-file-path=/usr/local/etc/php/5.6'
'--with-config-file-scan-dir=/usr/local/etc/php/5.6/conf.d'
'--mandir=/usr/local/Cellar/php56/5.6.29_5/share/man'
... and so on...
The items that matter are:
with-config-file-path: this where it will look for your php.ini file
with-config-file-scan-dir: this is the conf.d that will be scanned
If you still wish to choose a different in location than the default for the executable your options are:
Inline the module directives from and file in conf.d into your alternate php.ini
Rebuild php and set the above options to your new location as default
Use the wrapper script #atlanto indicates

Categories