Compile Zlib Statically for PHP 5.6 - php

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.

Related

CodeIgniter Error After Changing PHP from 5.6 to 7.0 on HostGator via SSH

So as the title describe, I am receiving this error right now on my CI after changing the PHP from 5.6 to 7.0. It works fine if I revert back to 5.6 but I need my server to be on 7.0.
A PHP Error was encountered
Severity: Core Warning
Message: PHP Startup: SourceGuardian: Unable to initialize module Module compiled with module API=20121212 PHP compiled with module API=20151012 These options need to match
Filename: Unknown
Line Number: 0
Backtrace:
From my 2013 blog post: https://delboy1978uk.wordpress.com/2013/10/30/manually-compiling-php-modules-successfully/
This look familiar?
PHP Warning: PHP Startup: memcached: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
I don’t know about you, but i like to be up to date! My PHP is on 5.5, and I had to install some modules. But sometimes, old versions can rear their ugly head, and cause all manner of grief. Package managers do a good job to take care of all this for you, but sometimes they just don’t work. Leaving you to compile yourself! So lets do it! I’m going to install memcached, and then the imagick libraries (now i know what i’m doing!)
I’m doing this on a CentOS 6 server, but as we are doing the old skool way of compiling etc, this should work on any other flavour of Linux, or indeed Mac OS X.
First step is to download your .tar.gz then unzip it with tar -zxvf file.tar.gz and change into the folder.
Bring up a web page displaying your servers php.ini. You are looking for the version of PHP API, and the extension_dir.
In your terminal, cd into the module source code folder, and type phpize.
If when you check the API versions , they are different from your php.ini, then an old version of php is being used in the terminal, and your module will not work! In this case, you need to get it to use the correct phpize.
type which phpize to find out where the offending file is. (mine was /usr/bin/phpize)
My PHP appeared to be in /usr/local, so I tried running /usr/local/phpize. The API’s matched. So then I did the following:
mv /usr/bin/phpize /usr/bin/phpize-old
ln -s /usr/local/bin/phpize /usr/bin/phpize
Half way there! We need to do the same for php-config
mv /usr/bin/php-config /usr/bin/php-config-old
ln -s /usr/local/bin/php-config /usr/bin/php-config
Now you have done that, installation should be trivial, and work as per loads of tutorial/instrruction pages on the web.
./configure
make
make install
Finally edit your php.ini and add ‘extension = memcached.so’ (or whatever module you compiled), and restart your apache server!
EDIT : you may need to run ‘phpize –clean’ if it is still compiling with the older stuff from within the modules source folder
Download latest SourceGuardian module, which support PHP 7.X:
https://www.sourceguardian.com/loaders/download.php

How to use Pthreads PHP extension in Ubuntu

I have problems with the Pthreads PHP extension. I have compiled PHP with ZTS enabled (--enable-maintainer-zts) and installed the pthreads via pecl and also tried to manually compile the extension.
It seems I don't actually know how to use it. I assumed I would be able to use the Thread class in PHP like any other built-in class, but with no luck as PHP doesn't recognize it. POSIX functions seem to work.
I am using Ubuntu 12.10 Server 64-bit with mod_php 5.4.6.
If you cannot access the extensions classes then it is not loaded.
I think you opened a bug report, to which I responded that your configure line is malformed.
The configure line you want to use is:
./configure --enable-pthreads --enable-maintainer-zts
The above command will build pthreads as a DSO.
./configure --enable-pthreads=static --enable-maintainer-zts
The above command will build pthreads statically into PHP.
Both are equally supported by 5.3, 5.4 and even 5.5.
Additionally, if you are overwriting your system installation then you should use a specific --prefix, for example, if you php executable is at /usr/bin ( which you can ascertain with "which php" ), then --prefix=/usr will overwrite your system installation.
Clean out your old installations ( do make uninstall if the sources are still available ). Start again, ensure you are either, overwriting the system installation or isolating this one completely.
Please update the bug report when you have worked it out.

Compiling a PHP extension as non-thread-safe

I am trying to compile the imagemagick (imagick) extension to use in a non-thread-safe environment on windows.
I am using PHP 5.3.10 and have set up Visual C++ express as my compiling environment.
The problem is that I am using a non-thread-safe version of PHP as a FCGI module in Apache 2.2.
Thus, my PHP is supplied with a php5.lib and not a php5ts.lib. I believe this is the reason why I am getting these errors:
imagick.obj : error LNK2019: unresolved external symbol __imp__tsrm_mutex_alloc referenced in function _zm_startup_imagick
I have only ever built and compiled things on linux, so am not too sure how to do this on a windows environment.
How can I compile the extension so that it is non-thread-safe?
I downloaded the threadsafe binary of PHP 5.3.10 to get a copy of php5ts.lib. I was then able to compile the extension.
I am guessing that setting the ZTS preprocessor directive to either 1 or 0 would cause the extension to compile as either threadsafe or non-thread-safe. (Not too sure about this, so if someone could let me know if this is correct or not, it would be much appreciated. :) )
I then set up a virtual machine running Windows 7 and installed the latest version of WAMP. Reason being that it used a threadsafe version of PHP.
I placed the dll in the ext folder in the PHP installation and enabled it in php.ini. However, even after trying both the ts and nts version in WAMP, I would get:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.10/ext/imagick.dll' - The specified module could not be found.
in Unknown on line 0
But the thing is that c:/wamp/bin/php/php5.3.10/ext/imagick.dll' does exist, and yes I have checked this a lot of times.
I then downgraded ImageMagick to 6.6.2-10-Q16, but still see the same problem.
The same issue occurs on my dev machine running a nts version of PHP 5.3.10 on Apache 2.2 (all installed manually).
Looks like I could be wrong regarding the ZTS preprocessor. If I set ZTS=0 and compile, using dependency walker on the compiled dll still shows that it requires php5ts.dll which is only present on threadsafe versions of PHP.
I did more tinkering with dependency walker and found that I had to statistically link to msvc100d.dll. I then removed ZTS in the preprocessor definition and was able to compile using php5.lib instead of php5ts.dll. I think this should get me a non-ts dll.
However, when loading the extension, I am still getting:
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'imagick.dll' in Unknown on line 0
And errors from dependency walker:
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
Installed visual c++ express 2008 and compiled using platform toolkit v90, but still facing the same issues.
Any tips appreciated :)
Solution Found! See my answer.
Got it! I hope this can help those compiling php extensions on windows in the future. What I have done is based on: https://wiki.php.net/internals/windows/stepbystepbuild
Note: I read an answer on this site that said compiling PHP extensions by itself on windows is unsupported. Based on my experiments yesterday, it seems to be a lot of work as well, so I am using the PHP build process.
The best way is to use the PHP build process.
Install Visual C++ Express 2008 (any version will do, but express is free) and Windows SDK 6.1 (note that we want the 6.1 version not anything older or newer).
Install the SVN client tools if you haven't done so and restart for your PATH variable to take effect.
Get the PHP SDK binary tools and extract it to C:\php-sdk.
Start the CMD Shell under Microsoft Windows SDK v6.1 in your start menu and run cd C:\php-sdk.
Run setenv /x86 /xp /release this creates a 32-bit release. You can use /x64 to build a 64-bit release (I have not tried this).
run bin\phpsdk_setvars.bat
run bin\phpsdk_buildtree.bat php53dev
Download the PHP source code and extract it to C:\php-sdk\php53dev\vc9\x86 so that you end up with C:\php-sdk\php53dev\vc9\x86\php5.3-xyz
Download the latest deps and extract everything to C:\php-sdk\php53dev\vc9\x86. You may be prompted to overwrite any existing folders, so press yes.
run cd C:\php-sdk\php53dev\vc9\x86
Check out the latest version of your extension from the svn repository: svn co http://svn.php.net/repository/pecl/imagick/trunk pecl/imagick I am checking out imagick here.
Install any dependencies. In my case, I need to install ImageMagick, so I downloaded the latest recommended windows binary. You will need to restart after installation to update your PATH variable, but you can do this after you have compiled. Make sure you install the C/C++ headers and includes as well.
Copy the contents of the includes directory from the ImageMagick install directory to C:\php-sdk\php53dev\vc9\x86\deps\include.
Copy the contents of the lib directory from the ImageMagick install directory to C:\php-sdk\php53dev\vc9\x86\deps\lib
Now, let's build: run cd C:\php-sdk\php53dev\vc9\x86\php5.3-xyz then buildconf then configure --help. Look at the help properly. It will show you all config flags and any avaliable extensions to enabled. In my case, since I added imagick, I had an option called --with-imagick
Run config: configure --enable-cli --with-imagick=shared --disable-zts If you want to build a non-thread-safe binary use --disable-zts, otherwise remove that configuration flag. I am not sure why, but sometimes extensions use the --with-myextension flag and sometimes --enable-myextension, so check configure --help for the flag to use. If you add =shared after the extension flag, it will be compiled as a separate DLL, which si what we want.
Compile: run nmake then nmake snap.
Done :) Check C:\php-sdk\php53dev\vc9\x86\php-5.3.10\Release (non-thread-safe) or C:\php-sdk\php53dev\vc9\x86\php-5.3.10\Release_TS (thread-safe). Your compiled binaries should be in there. The compiled extensions (pecl), should be in a ZIP file similiar to pecl-5.3.10-nts-Win32-VC9-x86.zip. Open this file and extract the extensio DLL to your ext folder in your PHP installation.
Enable the PHP extension and restart your webserver. Run phpinfo() and check that the extension is enabled.
If the extension does not work properly, make sure you reboot to update your PATH variable. In my case, I need to have the imagemagick install directory in my PATH variable.
???
Profit!
Is there a reason you need to compile? Why not download? It's usually much simpler/quicker on Windows.
VC6: http://www.sk89q.com/2010/03/vc6-windows-binaries-for-imagick-2-3-0/
VC9: http://valokuva.org/builds/

Enabling ZLib support in 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

OpenSSL not listed under PHP modules but shows up in the configure command

PHP 5.2.12
OS X 10.5.8
If I compile PHP from source with the following configure command
./configure --disable-all --with-openssl=shared,/opt/local
it succeeds. However, after a make and make install,
php -m
does not list the openssl module.
Based on what I've read, I think it may be due to multiple installs of the openssl library. Installing the latest version of openssl from source and trying to specify the path in the configure command, --with-openssl=/usr/local, always results in the following error:
Undefined symbols:
"_EVP_CIPHER_CTX_block_size", referenced from:
_zif_openssl_seal in openssl.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [sapi/cgi/php-cgi] Error 1
I've tried a few different variations on the path with no luck.
Based on
http://blog.yimingliu.com/2009/02/24/missing-library-symbols-while-compiling-php-528/, I've also tried editing the Makefile so that MH_BUNDLE_FLAGS comes later in the compilation line.
After spending a good portion of the day on this issue, I'm at a loss.
Any suggestions?
Ideally, I'd like to be using the compiled and most recent version of OpenSSL. But at this point, I'm willing to accept whatever works.
Duh. Of course php -m would not list the module. It's specified as "shared". Yes, I'm not all that familiar with compiling from source.
My solution consisted of
./configure
--disable-all \
--prefix=/usr/local \
--with-openssl=shared,/usr \
--with-config-file-scan-dir=/etc
...<snip>
then adding
extension=openssl.so
to /etc/php.ini
Restarted apache and everything now works as it should.

Categories