LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2011, 07:23 AM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
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
/opt/php123/bin/php: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for GNU/Linux 2.6.4, not stripped
# ldd /opt/php123/bin/php
	linux-gate.so.1 =>  (0xffffe000)
	libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7f7f000)
	librt.so.1 => /lib/librt.so.1 (0xb7f76000)
	libresolv.so.2 => /lib/libresolv.so.2 (0xb7f63000)
	libm.so.6 => /lib/libm.so.6 (0xb7f3e000)
	libdl.so.2 => /lib/libdl.so.2 (0xb7f39000)
	libnsl.so.1 => /lib/libnsl.so.1 (0xb7f24000)
	libc.so.6 => /lib/libc.so.6 (0xb7e04000)
	libpthread.so.0 => /lib/libpthread.so.0 (0xb7df0000)
	/lib/ld-linux.so.2 (0xb7fc3000)
This is when trying to compile php 5.2.17
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
 
Old 02-04-2011, 09:30 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,276

Rep: Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829
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.
 
Old 02-04-2011, 09:54 AM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
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
 
Old 02-05-2011, 08:23 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by helptonewbie View Post
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
While you was able to statically link PHP, and it's definitely an accomplishment
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
 
Old 02-05-2011, 10:18 AM   #5
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
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
 
Old 02-06-2011, 03:34 AM   #6
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,276

Rep: Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829
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?
 
Old 02-06-2011, 08:14 AM   #7
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
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'
14:29:14.333706 open("/usr/share/locale/locale.alias", O_RDONLY) = 3
14:29:14.334542 open("/usr/lib/locale/en_GB.utf8/LC_CTYPE", O_RDONLY) = 3
14:29:14.334915 open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
14:29:14.335301 open("/etc/localtime", O_RDONLY) = 3
14:29:14.336840 open("/opt/php-5.2.17/lib/php.ini", O_RDONLY) = 3
14:29:14.339825 open("/opt/php/lib/php.ini", O_RDONLY) = 3
14:29:14.343026 open("/opt/php/lib/php520_cybersource.so", O_RDONLY) = 3
14:29:14.344088 open("/etc/ld.so.cache", O_RDONLY) = 3
14:29:14.344419 open("/usr/local/src/simapi-php-5.0.1/lib/libspapache.so", O_RDONLY) = 3
14:29:14.345171 open("/usr/local/src/simapi-php-5.0.1/lib/libxerces-c.so.21", O_RDONLY) = 3
14:29:14.345978 open("/usr/local/src/simapi-php-5.0.1/lib/libxalan-c1_5_0.so", O_RDONLY) = 3
14:29:14.346749 open("/lib/libc.so.6", O_RDONLY) = 3
14:29:14.347599 open("/lib/libdl.so.2", O_RDONLY) = 3
14:29:14.348311 open("/lib/libgcc_s.so.1", O_RDONLY) = 3
14:29:14.349024 open("/lib/libpthread.so.0", O_RDONLY) = 3
14:29:14.349854 open("/usr/local/src/simapi-php-5.0.1/lib/libstdc++.so.4", O_RDONLY) = 3
14:29:14.350662 open("/lib/libm.so.6", O_RDONLY) = 3
14:29:14.351514 open("/lib/ld-linux.so.2", O_RDONLY) = 3
14:29:14.371984 open("/opt/php/lib/php520_cybersource.so", O_RDONLY) = 3
14:29:14.372864 open("/etc/ld.so.cache", O_RDONLY) = 3
14:29:14.373186 open("/usr/local/src/simapi-php-5.0.1/lib/libspapache.so", O_RDONLY) = 3
14:29:14.373869 open("/usr/local/src/simapi-php-5.0.1/lib/libxerces-c.so.21", O_RDONLY) = 3
14:29:14.374640 open("/usr/local/src/simapi-php-5.0.1/lib/libxalan-c1_5_0.so", O_RDONLY) = 3
14:29:14.375557 open("/lib/libdl.so.2", O_RDONLY) = 3
14:29:14.376363 open("/lib/libgcc_s.so.1", O_RDONLY) = 3
14:29:14.377061 open("/usr/local/src/simapi-php-5.0.1/lib/libstdc++.so.4", O_RDONLY) = 3
14:29:14.377819 open("/lib/libm.so.6", O_RDONLY) = 3
# cat dynamic.txt | grep 'O_RDONLY) = 3'
14:29:04.833939 open("/etc/ld.so.cache", O_RDONLY) = 3
14:29:04.834744 open("/lib/libcrypt.so.1", O_RDONLY) = 3
14:29:04.835466 open("/lib/librt.so.1", O_RDONLY) = 3
14:29:04.836087 open("/lib/libresolv.so.2", O_RDONLY) = 3
14:29:04.836764 open("/lib/libm.so.6", O_RDONLY) = 3
14:29:04.837356 open("/lib/libdl.so.2", O_RDONLY) = 3
14:29:04.838030 open("/lib/libnsl.so.1", O_RDONLY) = 3
14:29:04.838695 open("/lib/libc.so.6", O_RDONLY) = 3
14:29:04.839423 open("/lib/libpthread.so.0", O_RDONLY) = 3
14:29:04.843643 open("/usr/share/locale/locale.alias", O_RDONLY) = 3
14:29:04.844545 open("/usr/lib/locale/en_GB.utf8/LC_CTYPE", O_RDONLY) = 3
14:29:04.844936 open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
14:29:04.845398 open("/etc/localtime", O_RDONLY) = 3
14:29:04.846989 open("/opt/php-5.2.17/lib/php.ini", O_RDONLY) = 3
14:29:04.850856 open("/opt/php/lib/php520_cybersource.so", O_RDONLY) = 3
14:29:04.852898 open("/etc/ld.so.cache", O_RDONLY) = 3
14:29:04.853250 open("/usr/local/src/simapi-php-5.0.1/lib/libspapache.so", O_RDONLY) = 3
14:29:04.855012 open("/usr/local/src/simapi-php-5.0.1/lib/libxerces-c.so.21", O_RDONLY) = 3
14:29:04.857039 open("/usr/local/src/simapi-php-5.0.1/lib/libxalan-c1_5_0.so", O_RDONLY) = 3
14:29:04.858883 open("/lib/libgcc_s.so.1", O_RDONLY) = 3
14:29:04.860656 open("/usr/local/src/simapi-php-5.0.1/lib/libstdc++.so.4", O_RDONLY) = 3
Looks to me like dynamic PHP pulls in a few different shared lib's right at the start of loading PHP. I can't understand why statically built php seems to still have dependencies on other libraries within /lib? And i know the static version appears to try to run twice through or something? Well that explains why I get the same error several times over.

Last edited by helptonewbie; 02-06-2011 at 08:41 AM.
 
Old 02-07-2011, 02:39 AM   #8
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,276

Rep: Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829
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.
 
Old 02-07-2011, 03:30 AM   #9
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by helptonewbie View Post
HI Business_kid,

Looks to me like dynamic PHP pulls in a few different shared lib's right at the start of loading PHP. I can't understand why statically built php seems to still have dependencies on other libraries within /lib? And i know the static version appears to try to run twice through or something? Well that explains why I get the same error several times over.
Your perfectly static PHP read file php.ini, and load (via dlopen) modules from /usr/local/src/simapi-php-5.0.1/lib/
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.
 
Old 02-08-2011, 03:27 AM   #10
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
@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'
I'm already hacking with the Makefile as explained in my OP. The reason i'm trying to build a static PHP is so that I can do exactly what its meant for and make it portable between systems and just pick-up and move it, for it to work out of the box.

@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
 
Old 02-09-2011, 03:35 AM   #11
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,276

Rep: Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829Reputation: 829
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
 
Old 02-09-2011, 04:26 AM   #12
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by helptonewbie View Post
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
When you dlopen shared libraries, their dependencies includes /lib/ld-linux and libc.so as you can see in your
Code:
cat static.txt | grep 'O_RDONLY) = 3'
But you already have libc linked statically in your executable!
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
 
Old 02-10-2011, 08:43 AM   #13
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
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.
 
Old 02-10-2011, 11:06 AM   #14
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by helptonewbie View Post
@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.
dlopen happened not during compilation, but at run time. So I don't think -all-static will affect it.
But I am no expert with libtool./
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to compile iputils package statically and getting error manya Programming 4 09-13-2010 05:28 PM
compile wget statically iggi Linux - Software 2 11-12-2007 06:50 AM
How to compile statically? futhark Linux - Software 2 04-16-2006 01:39 PM
Can't compile MPlayer statically. Nezzo Linux - Software 3 11-04-2003 06:29 PM
How do I statically compile a src.rpm? WeNdeL Linux - General 1 05-19-2003 10:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration