Statically Compile PHP - Not possible then?
Hi All,
Been trying to do this for a few hours looks like a lot of people have trouble doing this and so far i'm in the same boat as all of them. So just trying to get this to work so I can ship PHP where I want and it will just work when I move about to different machines etc. './configure' '--prefix=/opt/php123' '--enable-cli' '--disable-all' '--enable-session' '--enable-static' Code:
# file /opt/php123/bin/php I'm fully aware its EOL but in this case Needs MUST! If i change or 'mv' one of the shared linked in libs then php does fail with unable to load shared library.... what gives!? Thanks for any replies. Regards, M |
Those libs come from glibc, if I'm not mistaken. They handle everyday interfacing with the system. EVERYTHING is linked against ld-linux.so & libc.so.6. It's presumed you have access to /lib.
|
Stupid PHP i think is buggy on this.
Can get it working by editing Makefile just before make && make install. Change lines BUILD_CLI= blah where -export-dynamic Replace with -all-static Then everything gets sorted and statically linked. @php - does --enable-static actually do anything!? haha Cheers |
Quote:
are you sure it's enough? Usually PHP tends to load a lot of modules and those modules use shared libraries - the very thing you are trying to avoid For more details you can look here http://magicermine.com/docs/c_packaging.html#s_php |
Hi Valery,
Thanks for your comment. As you can see from my compile choices i'm loading very very little and anything that is being loaded is PHP built-ins. Thanks for the link though because I will have a look at that. The 'file' command shows the php bin built as static and 'ldd' also notes that the binary is static and isn't starting any shared libs. Only problem is - haha it doesn't seem to work. I am trying to load in a dynamic library however that's a .so file, and i get: PHP Warning: PHP Startup: Unable to load dynamic library '/opt/php/lib/XX.so' - /opt/php/lib/XX.so: undefined symbol: zend_register_string_constant in Unknown on line 0 See i've got a version of php exactly like this but not statically compiled which works fine (same version and compile options - even 'php -i' between this version and other normal version everything is basically the same except this static version shows up the error above). But when running php -i on this statically compiled version i get the above error. The library is being pulled in by the php.ini file which is exactly as planed and the whole reason i'm trying to do this in the first place. I needed a version php.5.2.x to run this particular library and thats all i needed, hence the compile options being so minimal. If you've got any other ideas they'l be greatly recieved and i'll look into that link you sent over now as well. Many Thanks, M |
Have you simply thought of setting LD_LIBRARY_PATH, running ldconfig or at a push, even running
cd /opt/lib lndir /usr/lib (which is awful) and then try the version you have? |
HI Business_kid,
I have already added the path of any shared libs to ld.so.conf and run ldconfig. using the following i can see that both versions of php static or shared are picking up any shared libraries that they still require without problem strace -e open [php binary] But if you have any other ideas i'm happy to hear them? Best, M EDIT:- Using the following strace against each binary... static compile version - strace -F -tt -o static.txt -e open php-5.2.17/bin/php -i dynamic compile version - strace -F -tt -o dynamic.txt -e open php-5.2.17_safe/bin/php -i So i know both versions are getting access to the libraries they ask for as well. So what i find interesting is the order in which these are being run. I think I read only a few min's ago that the ordering is important...??? Code:
# cat static.txt | grep 'O_RDONLY) = 3' |
It could be in the way you configure it, or in the file itself. Static may not just be a supported mode, and you may have to hack the Makefile. I presume you are doing something like ./configure --enable-static --disable-shared?
Why do you need/want a totally static php? It's normally a poor way to go. |
Quote:
and those modules (shared libraries) depend on other shared libraries and dlopen load them all. Linking PHP static is not meant it will be portable - link I posted before explains why in details. |
@business_kid:-
Latest set of configure command is Code:
'./configure' '--prefix=/opt/php-5.2.17' '--enable-cli' '--disable-all' '--enable-session' '--enable-static' '--with-config-file-scan-dir=/opt/php/lib' @Valery:- Yes that's great, but ermine is a pay for product. It looks great and I know you get a few days trial but thats not useful enough for me. I'd love to be using it and would be if it was free. I still can't understand the problem then, ok yes the other libraries that are being pulled in are pulling in more libraries for themselves, fair enough. But ive got the dynamic and static versions on the same box and thus as both can get to all the libraries they need plus shared libraries then the only thing I can think of why there's still a problem with the static version is something to do with the nss part of the link you sent over @valery? Any ideas how I can force it to include these other things without the need for ermire? Or that that a crazy mine field? Many Thanks, M |
you need --enable-static and --disable-shared together on the same config line. Perhaps also email the authors of testdisk. They do an executable that is totally portable. Ask them for tips.
dec@genius:~$ ldd /oldslack/usr/sbin/testdisk not a dynamic executable |
Quote:
Code:
cat static.txt | grep 'O_RDONLY) = 3' Having two libc in one process likely to be a bit of problem. And ld-linux.so is a very special thing too. Loading (and starting) it in the middle of the program execution may result in very interesting effects (and unlikely to make your program happy) NSS libraries, judging by strace you posted not in use, but they can be used when your PHP will do actual works. And it's not a crazy mine field. It's much, much worse :( |
Thanks for the continued responses guys its much appreciated!
@business_kid I was under the assumption that --disable-shared would stop me be able to load the library that I am trying to call in from the php.ini? But thanks, for the testdisk info i'll check them out and see if they can help at all. @Valery Reznic Thanks, i was looking to try and make the static version start the libraries in the same order by compiling with LD_PRELOAD and then the order that I wanted the libraries to be started in and to also make sure the libraries were pulled in but this didn't seem to make any difference at all. I'm so glad to hear its worse than a mine field and no wonder there's not many search results around for actually being able to sort this kind of thing out. I also note that my changing of the Makefile that actually gets PHP to build statically might be the same thing thats causing the library extension i've got PHP.ini trying to load also not work. -all-static according to this means (http://www.gnu.org/software/libtool/...html#Link-mode) means not to include shared library files to me during compile? Or even to not include any on program execution. |
Quote:
But I am no expert with libtool./ |
All times are GMT -5. The time now is 10:00 AM. |