Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Basically I am just wondering if I can drag and drop the libphp5.so file to another server without PHP and have the functionality of PHP and all the extensions statically compiled into it. (Compiled from source with a bunch of extensions)

I tried using the ld tool on the so file (on my server) but it just spit out a bunch of undefined references. Which are irrelevant since its a working install.

Edit:

I realize now that I was using ld instead of ldd. Now I get a list of the dependencies. I am guessing I would need all these files correct? So my question is if I recursively get all the shared object files and put them in their same locations on a destination server (probably via a custom RPM) would PHP function a new server without a formal install of PHP?

Could I be missing any hidden dependencies that are not found by ldd?

share|improve this question
4  
+1 for "metric crap-ton", excellent SI unit, others probably will not like this however. –  Orbling Dec 3 '10 at 1:57
    
Can you convert that to Imperial units? –  Zoredache Dec 3 '10 at 4:57
2  
@Zoredache: 0.91 ultratons. –  Ignacio Vazquez-Abrams Dec 3 '10 at 5:06
1  
If you're going the custom RPM route then it's probably easier to rebuild once for each system than to worry about static building and dependencies. –  Ignacio Vazquez-Abrams Dec 3 '10 at 5:07

1 Answer 1

A .so library is a shared library - exactly the opposite to a static library. If you statically compile a PHP install you will have a single (very large) executable probably called "php" but there will be no .so files.

I believe it is not possible (or at least a very bad idea) to "statically" compile a .so file. The reason is that you will effectively be copying hundreds if not thousands of functions into the .so file which will not only make it huge, but can also cause errors when the library is loaded. For example, if an application (such as a web server) loads the standard C library with the function strcpy() in it, then it loads your 'static' .so file which also has a strcpy() function in it, there could be a conflict. You could work around this by carefully exporting only the necessary symbols or using dlopen() in the app instead, but at best you will end up with a massively oversized .so file that wastes a lot of memory.

What you could do is use ldd to pick out all the .so files you need to run all the extensions, then put them all in the same folder as the .so file. If you then set the LD_LIBRARY_PATH environment variable to that directory before running an application, it should pick up PHP and all its dependencies from that one folder. This wouldn't give you the magic single-file approach, but it would at least allow you to contain everything to one folder.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.