recompiling PHP - php

I have compiled php with some optional extensions like APC (for caching),APD (for debugging) and other vital extensions. Now I need to install another extension called mhash (for encryption) and my question is that:
Do i need to recompile php from scratch including the previous extensions and the last one or it is possible to recompile php just with last one (hopefully the previous extensions still supported)??

The other compiled extensions will still work.

Related

Not able to import XML data

I tried to import data from XML file using the importDump utility...
root#aace30d9b5f3:/var/www/html/mediawiki-1.36.1# php ./maintenance/importDump.php mrwiki-latest-pages-articles-multistream.xml
Got this error:
MWException from line 2108 of /var/www/html/mediawiki-1.36.1/includes/parser/Parser.php: PCRE needs to be compiled with --enable-unicode-properties in order for MediaWiki to function
I downloaded the source code of PCRE and run make / make install but that did not work. I am using the official docker image of mediawiki if that matters.
https://hub.docker.com/_/mediawiki
update:
I need to simplify what I am trying to ask...
Is PCRE compiled using --enable-unicode-properties in this dockerfile?
https://github.com/docker-library/php/edit/master/7.3/buster/apache/Dockerfile
Is that php image being used by mediawiki official repo?
https://github.com/wikimedia/mediawiki-docker/blob/51105612d2e1168f1b0545f47951847d63fb9613/1.36/apache/Dockerfile
PHP, unfortunately, usually uses its own PCRE library (from the manual: "By default, this extension is compiled using the bundled PCRE library"), as you can also see in this other answer.
What you need to do is recompile PHP itself in order to activate the PCRE changes. To do this you need to (you can do this on a cloned machine)
check out the exact PHP version
download and install the relevant source packages
get the exact compilation options from phpinfo()
change the PCRE options appropriately
make (you don't need install as you're not going use PHP in the cloned machine)
The only file that you need to change now is the basic PHP binary (/usr/bin/php, watch out for alternatives symlinks). If you used a cloned machine with the same distro and versions, you can easily rename that one binary on the original machine and move in the new one, and it will work (I've done this dozens of times), so you'll have the option to go back at any time.
Or you can install the development packages for PCRE on the cloned machine and supply --with-pcre-regex= and --with-pcre-dir= to the compiler. The new PHP binary will now use the system PCRE, so that pcretest -C will now yield reliable results. I am not sure whether you need the same PCRE version on both machines (you probably need the same major version, but a minor version mismatch shouldn't be a showstopper). Be aware that updating the system PCRE library might break compatibility with PHP if for any reasons the library calls change.

Is the php json extension still useful (php >= 5.2)?

From php.net, I found this line :
As of PHP 5.2.0, the JSON extension is bundled and compiled into PHP by default. http://php.net/manual/en/json.installation.php
So why this php extension still exist ? For example : php7.2-json
Are we talking about the same json extension ?
The fact that the extension is bundled (i.e. shipped inside the main zip without the need to download it from an external repository), or compiled (i.e. directly available from your PHP code without the need to explicitly activate it in ini files), does not mean that the source code of the extension was removed altogether.
The source code of many features in PHP is organised in extensions -- be them external, dynamic, or statically compiled and bundled).
You will still find the php json extension as a standalone lib ; but you should not need to install it on its own, nor activate it in ini files.

how to use --without-sqlite3 at compile time in php?

I was reading PHP documentation about how to disable the SQLite3 extension in PHP:
The SQLite3 extension is enabled by default as of PHP 5.3.0. It's possible to disable it by using --without-sqlite3 at compile time.
but i didn't realize how to use --without-sqlite3 ?
"Compile time" refers to when someones takes the PHP source code, and compiles it into binary files. Once PHP is installed from those binaries, there is no way to disable an extension that was included in the PHP binary. (You can disable extensions that are compiled into separate binaries, but that is not the case for the SQLite3 extension for PHP. So in order to disable SQLite3 in your PHP, you'd need to obtain the source code of PHP, and compile it manually; it's not an easy task, if you've never compiled something, but I'm sure there are walkthroughs you can find online, if you really need.

When installing just PHP on Windows, all php extensions are commented out by default?

I'm trying to get Laravel installed and when running composer I get lots of errors along the lines of the requested PHP extension mbstring is missing from your system except there are dozens. It's really tiring going one by one and uncommenting these. What am I doing wrong? Do I need to just install apache(edit: I meant XAMPP) and its default php.ini will have better default options?
Is there a way to get a .ini file that has the most common stuff available? Can I just uncomment all extensions or is there a reason that's a bad idea?
Can I just uncomment all extensions or is there a reason that's a bad idea?
Yes, you can uncomment all extensions, but that won't improve your user experience :)
In general: enable only PHP extensions, you really need
The more dynamic extensions PHP needs to load, the more stuff it has to load and process during startup and the more time it takes. So, the startup will be slower.
For instance, enabling the default extension php_pdo_firebird.dll doesn't gain you anything, except, when you really want to access the Firebird database from PHP via PDO.
Is there a way to get a .ini file that has the most common stuff available?
The PHP extensions shipped by PHP itself are all listed in php.ini.
There is also php.ini-development with some dev configurations.
If everything is off by default, then i suggest to enable curl + openssl, mysql, sqlite, mbstring for a start, because:
Curl and Openssl are needed to get Composer running,
Mysql and Sqlite to support these often used databases,
mbstring for UTF8 stuff
and whenever some library meows enable some more ,)

Understanding extensions in php.ini

I'm having trouble understanding these ;extension=xxx.dll files in php.ini
Is there any document I can refer to which explains these extensions in detail?
The .dll files are for PHP extensions. You can read about all of them here: http://php.net/manual/en/install.windows.extensions.php
PHP extensions give you extra PHP functionality. They are basically function libraries that add features like MySQL functions, LDAP functions, and even Java functions.
To activate the extensions provided by the default PHP install, simply uncomment the ;extension=xxx.dll line (remove the semicolon) so that it just looks like extension=xxx.dll.
However, not all extensions are bundled with PHP. For example, the PECL extensions, including APC, have to be installed externally. Instructions for installing PECL can be found here: http://www.php.net/manual/en/install.pecl.php
"Extension Writing Part I: Introduction to PHP and Zend"
You only need to worry about those if you're running on a Windows server - since they appear to be commented out (; at the start of the line) I would assume you're on a Linux server?
In any case, you should be able to look up each extension individually on Google.

Categories