Skip to content

Commit b1ca638

Browse files
committed
PHPLIB-790: Docs for common extension install errors
1 parent 396fedc commit b1ca638

File tree

1 file changed

+68
-13
lines changed

1 file changed

+68
-13
lines changed

docs/tutorial/install-php-library.txt

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,9 @@ your ``php.ini`` file:
5050

5151
extension=php_mongodb.dll
5252

53-
Windows binaries are available for various combinations of PHP version,
54-
thread-safety, and architecture. Failure to select the correct binary will
55-
result in an error attempting to load the extension DLL at runtime. Additional
56-
considerations for Windows are discussed in the
53+
Additional considerations for Windows are discussed in the
5754
:php:`Windows installation documentation <manual/en/mongodb.installation.windows.php>`.
5855

59-
.. note::
60-
61-
If your system has multiple versions of PHP installed, each version will have
62-
its own ``pecl`` command and ``php.ini`` file. Additionally, PHP may also use
63-
separate ``php.ini`` files for its web and CLI environments. If the extension
64-
has been installed but is not available at runtime, double-check that you
65-
have used the correct ``pecl`` command (or binary in the case of Windows) and
66-
have modified the appropriate ``php.ini`` file(s).
67-
6856
Installing the Library
6957
----------------------
7058

@@ -109,3 +97,70 @@ classes *and* functions are loaded for your application:
10997
#. Regardless of whether you are using an autoloader, manually require the
11098
``src/functions.php`` file. This is necessary because PHP does not support
11199
autoloading for functions.
100+
101+
Common Extension Installation Errors
102+
------------------------------------
103+
104+
PHP Headers Not Found
105+
~~~~~~~~~~~~~~~~~~~~~
106+
107+
For example:
108+
109+
.. code-block:: none
110+
111+
/private/tmp/pear/install/mongodb/php_phongo.c:24:10: fatal error: 'php.h' file not found
112+
113+
#include <php.h>
114+
^~~~~~~
115+
116+
This error indicates that PHP's build system cannot find the necessary headers.
117+
All PHP extensions require headers in order to compile. Additionally, those
118+
headers must correspond to the PHP runtime for which the extension will be used.
119+
Generally, the ``phpize`` command (invoked by ``pecl``) will ensure that the
120+
extension builds with the correct headers.
121+
122+
Note that the mere presence of a PHP runtime does not mean that headers are
123+
available. On various Linux distributions, headers are often published under a
124+
separate ``php-dev`` or ``php-devel`` package. On macOS, the default PHP runtime
125+
does not include headers and users typically need to install PHP (and headers)
126+
via `Homebrew <https://brew.sh/>`_ in order to build an extension.
127+
128+
Multiple PHP Runtimes Installed
129+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130+
131+
If your system has multiple versions of PHP installed, each version will have
132+
its own ``pecl`` and ``phpize`` commands. Additionally, each PHP runtime may
133+
have separate ``php.ini`` files for each SAPI (e.g. FPM, CLI). If the extension
134+
has been installed but is not available at runtime, double-check that you have
135+
used the correct ``pecl`` command and have modified the appropriate ``php.ini``
136+
file(s).
137+
138+
If there is any doubt about the ``php.ini`` file being used by a PHP runtime,
139+
you should examine the output of :php:`phpinfo() <phpinfo>` for that particular
140+
SAPI. Additionally, :php:`php_ini_loaded_file() <php_ini_loaded_file>` and
141+
:php:`php_ini_scanned_files() <php_ini_scanned_files>` may be used to determine
142+
exactly which INI files have been loaded by PHP.
143+
144+
Loading an Incompatible DLL on Windows
145+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146+
147+
PECL builds Windows binaries for various combinations of PHP version,
148+
thread-safety (TS or NTS), and architecture (x86 or x64). Failure to select the
149+
correct binary will result in an error when attempting to load the extension DLL
150+
at runtime:
151+
152+
.. code-block:: none
153+
154+
PHP Warning: PHP Startup: Unable to load dynamic library 'mongodb'
155+
156+
Ensure that you have downloaded a DLL that corresponds to the following PHP
157+
runtime properties:
158+
159+
- PHP version (``PHP_VERSION``)
160+
- Thread-safety (``PHP_ZTS``)
161+
- Architecture (``PHP_INT_SIZE``)
162+
163+
In addition to the aforementioned constants, these properties can also be
164+
inferred from :php:`phpinfo() <phpinfo>`. If your system has multiple PHP
165+
runtimes installed, double-check that you are examining the ``phpinfo()`` output
166+
for the correct environment.

0 commit comments

Comments
 (0)