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?
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 theLD_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.