Enabling ZLib support in PHP - php

I'm installing a PHP script in my server and when I try to run the test page, I get an error saying:
PHP needs to be compiled with ZLib support enabled (--with-zlib[=DIR])
How can I fix this on Apache?

I assume this is on linux?
As the error says, you need to recompile your PHP installation.
Take a look at the Makefile in the folder where you have the PHP source to see the ./configure line that was used last time, use all of the same options with the addition of --with-zlib
./configure --with-zlib ...(other config options)...
make
make install

Related

Compile Zlib Statically for PHP 5.6

I am using the docker image 5.6.30-alpine https://hub.docker.com/_/php/. I am getting the error
PHP Notice: getimagesize(): The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled in /var/www/builds/stage81/platform/class/Wm/View/FileInfo.php on line 55
I cannot find a way to make zlib to be compiled statically. I tried all possible options including
Adding zlib-dev
./configure --with-zlib --with-zlib-dir=/usr
./configure --with-zlib=/usr --with-zlib-dir=/usr
None of them works and still getting the same message. Is there no way to make zlib to be compiled statically? Is there any workaround for this?
I found the issue. I am responding just in case somebody else comes across the same issue.
The root cause of the issue is my understanding on how Apache and PHP interacts. I was in the wrong assumption that Apache uses the installed PHP. It seems there are two different things. Installed PHP or PHP-cli never interacts with Apache. Apache uses libphp5.so for PHP integration. Since I was using php5-apache2 it comes along its own libphp5.so where the configuration is --with-zlib=shared. So even if the installed PHP has zlib statically it has no impact for Apache. I have raised an issue with Alpine for this https://bugs.alpinelinux.org/issues/7284.

Where are PHP extensions when installing from source?

When I try to run a PHP scripts I get the following errors:
Warning: PHP Startup: Unable to load dynamic library '/home/user/php-5.4.28/installdir/include/php/ext/php_bz2.so' - /home/user/php-5.4.28/installdir/include/php/ext/php_bz2.so: cannot open shared object file: No such file or directory in Unknown on line 0
php.ini:
extension_dir = "/home/user/php-5.4.28/installdir/include/php/ext"
Content at extension_dir path:
~/php-5.4.28/installdir/include/php/ext$ ls
date ereg gd iconv libxml mysqli pcre session sqlite3 xml
dom filter hash json mbstring mysqlnd pdo spl standard
Where do I locate the extension?
I have installed PHP from source.
All the errors and phpinfo() can be seen here on JSBin
You don't have to locate the extension. You have to recompile PHP passing the option --with-bz2 to the ./configure script. Bzip2 support is not enabled by default as official documentation says.
./configure --with-bz2
Keep in mind that in order to compile PHP with this extension you need development headers and/or libraries. If they are missing ./configure will fail saying what's missing. If this will happen simply use your package manager (apt, yum or zypper - distro dependent) to install required packages and retry.
It's also likely that your PHP apps are using other extensions. The procedure is exactly the same. You just add more options. Let's say that curl is also needed, then:
./configure --with-bz2 --with-curl
will work - again more headers and packages needed.
Remember to always use all the options you need as the results of former compilations are overwritten.

Configure SOAP with PHP

I need install SOAP for PHP on my server. Looking at the documentation on the PHP manual there is only this instruction
To enable SOAP support, configure PHP with --enable-soap
Can anyone tell me how I do this? I'm assuming that I need to do this on the command line somehow?
That means recompiling it and passing the --enable-soap switch to your ./configure script.
But you should run php -m from the command line first (or phpinfo(); ) to ensure that it's not already installed. It's a popular extension, and most hosts have it enabled by default.
If you need to compile PHP, you can find instructions on php.net for windows and linux platforms.

How to compile php extension for PHP 5.3.6 with debug, TS

I've tried to create some php extension.
For the first I compiled php 5.3.6 with --enable-debug --enable-maintainer-zts.
Then I ceated my extension and use standart procedure for it
phpize
./configure --with-EXTNAME
make
Then copy extname.so to my php extensions directory, and change php.ini
And when I try to use php from cli I got an error
Unable to initialize module
Module compiled with build ID=API20090626,NTS
PHP compiled with build ID=API20090626,TS,debug
When I try
./configure --enable-debug --enable-maintainer-zts
For extension I got warning that these options are not recognized by configure script.
So, how can I compile my extension to use with PHP compiled with options that I describer above without recompiling php itself?
You need ./configure --with-php-config=/path/to/correct/php-config.
The configure script is likely using another php-config (likely the centrally installed one).
in my server there are 2 phpize
/usr/bin/php/phpize
/usr/bin/php-zts/phpize
to make sure it compiled with Thread Safety instead using "phpize" do
/usr/bin/php-zts/phpize
./configure --with-php-config=/usr/bin/php-zts/php-config
make
make install

Needing an explanation regarding PHP extentions

Here is a quick overview:
I just finished compiling PHP 5.3.5 and made the attempt to compile "--with" a number of different extensions. Among the extensions that I need are mbstring and intl. I can manually phpize, configure, make, make install the mbstring extension and it seems to work fine. However, I am unable to do the same for intl.
My ./configure line looks like this:
./configure --with-openssl --with-pcre-regex --enable-calendar
--with-curl --enable-exif --enable-ftp --with-gd
--with-mhash --enable-mbstring --with-mysql --enable-zip
--enable-intl --with-icu-dir=...
The code compiles without problem: ./configure... make, make install
I used the php.ini-production for my php.ini configuration and I configured Apache to use php-cgi for a specific domain, and that works fine as well.
A quick:
<?php phpinfo() ?>
reveals that I am in fact running the newer version of PHP. However, the extensions specified in the "./configure..." line do not show up anywhere on the PHP info page.
After a bit of scouting I found that I could run phpize on a single extension in the PHP source folder, then compile a build of the specific module and install it in my PHP extension directory. After adding:
extension=MY_EXT
in my php.ini, the extension showed up on my phpinfo() page.
So can anyone explain why --with-mbstring doesn't seem to have an effect on my compilation?
I had no compilation problems for the intl extension, but moving the intl.so file to my PHP extensions directory and adding an extension line in my php.ini has no effect.
From php.net, have you tried
If your ICU is installed to a
non-standard directory then you might
want to specify its location in
LD_LIBRARY_PATH environment variable
so that dynamic linker can find it: $
export LD_LIBRARY_PATH=/opt/icu/lib
Otherwise, if PHP and ICU are
installed to their default locations,
then the additional options to
`configure' are not needed.

Categories