I need a standalone independent-from-system-libraries version of PHP to be able to distribute it as a .zip file containing binaries. Previously the .zip was containing libxml2.so.2, libpng12.so.0, php.ini and php executable.
Recently I needed to add some functionalities and recompile the PHP. I did it with:
./configure \
--prefix=/home/user/php/out \
--libdir=. \
--enable-static=YES \
--enable-shared=NO \
--with-pdo_mysql \
--with-gd \
--with-mysql \
--enable-zip \
--enable-zend-multibyte \
--enable-cgi \
--enable-fastcgi \
--with-ldap=shared
make && make install
Then I took php from out/bin and libmysqlclient.so.16 from /usr/lib/. But the new php doesn't want to pick up the library. Once I run it I get the following error:
./php: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
libmysqlclient.so.16 and php are in the same directory. If i put libmysqlclient.so.16 to /usr/lib, php works fine.
Is there any additional option that I've forgotten about during compilation? Why isn't the "--libdir=." option working?
First, the directive is --with-libdir not --libdir. Second, I think it is relative to /usr, so putting . there means you need to put the shared libraries into /usr.
If you have done any C coding with shared libraries, you must know about ld. The easiest way to handle shared libraries path is to use ld.
You can set the library path for the current (shell) session:
bash-4.1$ export LD_LIBRARY_PATH=/path/to/your/libs
You can also configure ld to do it all the time:
bash-4.1$ echo /path/to/your/libs >> /etc/ld.so.conf
bash-4.1$ ldconfig
Maybe you could use XAMPP and save yourself sometime? It comes prepackaged and pretty portable.
http://www.apachefriends.org/en/xampp.html
Related
I am trying to compile Mongodb module statically into PHP.
I have successfully compiled PHP (without Mongodb module) using the instructions here: https://aws.amazon.com/blogs/compute/scripting-languages-for-aws-lambda-running-php-ruby-and-go/
Then I compile Mongodb driver using the instructions here: http://php.net/manual/en/mongodb.installation.manual.php. The module mongodb.so is generated and stored successfully in the PHP source files.
But in order to re-compile PHP to bundle the Mongodb module, I tried the following instructions http://php.net/manual/en/install.pecl.static.php, but I don't know which flag I need to use to compile PHP with the Mongodb module.
I have tried --with-mongodb, --with-mongo, --enable-mongodb and --enable-mongo but none of those are valid flags.
Could somebody be so kind to help me out with this problem?
Many thanks in advance.
After spend lot of time on this, I finally can compile PHP with mongodb extension statically installed. I realized that the version of extension I was trying was not supported to accomplish this.
RUN git clone https://github.com/mongodb/mongo-php-driver.git mongodb && \
cd mongodb && \
git checkout 1.5.3 && git submodule update --init && \
cd ../ && mv mongodb ext/mongodb
RUN ./buildconf --force
RUN ./configure \
...
--enable-mongodb \
...
RUN make -j 5 && make install
When checkout the extension to tag 1.5.3 I could add the ---enable-mongodb flag on the /configure command.
I built a number of custom PHP extensions under windows 8-10 years ago. I made the move to Ubuntu Linux for all of my web stuff some years ago and find I need to create another custom extension. I'll be doing the development under Ubuntu this time.
I've created a very simple extension (a no-op actually) just to make sure I have the build process working. It's not.
Here is what I have done:
Cloned PHP from Git
Checked out PHP-5.5
Configured with --disable-all --enable-debug --enable-maintainer-zts \
--prefix=
Build PHP
Success php -i shows:
Zend Extension Build => API220121212,TS,debug
PHP Extension Build => API20121212,TS,debug
Created ext/a1 for my new, very simple extension
Created the basic extension (from Sara Goleman's book)
Ran phpize in ext/a1
Ran ./configure --enable-a1
Ran make
Build was successful.
Copied a1.so to the extensions directory
phpdir/bin/php -dextension=a1.so -v
Fails. Results in:
Module compiled with build ID=API20121212,NTS
PHP compiled with build ID=API20121212,TS,debug
So. Color me confused. According to what I've read, the phpize command is supposed to match the extension build settings to the php build settings.
I've apparently missed something basic here somewhere.
Help will be most appreciated.
Its hard to say what exactly was going wrong, I can only say that the extension was build using a different config than the php version.
I will describe some reproducible steps how to compile a most basic extension with debug symbols within the PHP source folder. The extension contains no code except of some boilerplate code created by ext_skel. It just describes the compilation process on UNIX. It is a shell script, you might execute it.
#!/bin/sh
# Should work for all PHP5 versions
VERSION="5.6.9"
# Download the PHP source code
wget \
--continue "http://de2.php.net/get/php-$VERSION.tar.gz/from/this/mirror" \
-O "php-$VERSION".tar.gz
tar xf "php-$VERSION.tar.gz" && cd "php-$VERSION/ext"
# Create a hello extension from skeletons
./ext_skel --extname="hello"
# Uncomment two lines in ext/hello/config.m4
# Read the comments there and you'll know what I'm doing
sed -ri.original \
-e 's/(dnl )(PHP_ARG_ENABLE\(hello)/\2/' \
-e 's/(dnl )(\[ --enable-hello)/\2/' \
hello/config.m4
# Build PHP and the extension
cd ..
./buildconf --force
./configure \
--enable-debug --enable-maintainer-zts \
--enable-hello=shared
make -j
# Test if it is working
sapi/cli/php \
-dextension=modules/hello.so \
-r 'var_dump(extension_loaded("hello"));'
You can now start to enter code to ext/hello/hello.c and create your extension. If you want to compile the changes you make just issue make without arguments.
Since we've compiled using --debug we you can now use gdb to debug the C code and explore how PHP internally works. To start a debugging session use:
gdb sapi/cli/php
...
(gdb) break main
(gdb) run -dextension=modules/hello.so some.php
Of course you'll mostly set breakpoints into your extension functions rather than in the php main() function once you've added code to the extension. However, this should show the basic steps to get there.
Have fun! :)
gdb
For offline development I would like to make make a standalone PHP 5.4 binary so I can use the PHP self hosting option.
eg php -S localhost:8000
Which would startup a server for hosting PHP files.
Since installing and configuring PHP 5.4 on mac is not trival for non tech people. I would like to be able to include a working PHP binary in my files. So essentially I can run.
./php -S localhost:8000 in my folder and it will work.
I have followed the instruction here to create a standalone PHP binary by running on the source code.
./configure --enable-static --enable-cgi --enable-mbstring\
--enable-force-cgi-redirect \
--with-config-file-path=/etc/php5cgi \
--prefix=/usr/local/php5cgi \
--with-curl \
--enable-sockets \
--with-zlib --with-zlib-dir=/usr/include \
--with-pear
Then editing the Makefile to have -all-static
BUILD_CGI = <other commands here> $(ZEND_EXTRA_LIBS) -all-static -o $(SAPI_CGI_PATH).
BUILD_CLI = <other commands here> $(ZEND_EXTRA_LIBS) -all-static -o $(SAPI_CGI_PATH).
This does work. File is standalone.
But when I run the binary.
./php-cgi -h
There is no "-S" option for the built in webserver?
Do I need to change something in my configure options to allow the builtin webserver? My source was downloaded from PHP.net (I did download the 5.5 latest source, but that still does have the -S option).
Thanks, John.
thanks to #devZer0
I cd'ed into
sapi/cgi/php-cgi
and tried to run this.
Needed to cd into sapi/cli/php
That works now! php -h return the -S option for webserver.
I'm currently using vim for my PHP development. A few weeks ago I bought myself a mac, and wanted to re-generate my tags for a new Zend Framework version.
I used the following script in the past (linux machine) to generate the tags:
#!/bin/bash
cd ~/www/ZF/
ctags-exuberant -f ~/.vim/tags/zend \
-h ".php" -R \
--exclude="\.svn" \
--totals=yes \
--tag-relative=yes \
--PHP-kinds=+cf \
--regex-PHP='/abstract class ([^ ]*)/\1/c/' \
--regex-PHP='/interface ([^ ]*)/\1/c/' \
--regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'
You can see I used the "ctags-exuberant" command. The problem is that this isn't found on my system (mac). I only have the ctags command. I tried installing the newest version of the ctags library (http://ctags.sourceforge.net/) but didn't gave me that command.
The ctags command does not have the same parameters as the ctags-exuberant. So 2 questions:
What's the difference between the 2 commands?
How can I install ctags-exuberant or use the normal ctags command for PHP?
Thanks!
Ward
Install Homebrew, then do:
brew install ctags
Install MacPorts, then do:
port install ctags
For a more friendly way to do this instead of using mac-ports or homebrew and running the risk of causing errors download ctags from here and compile with xcode (starting with version 4.3 command line tools are not installed by default but rather through Preferences -> Downloads) then simply move the compiled ctags to /usr/bin/ctags-exuberant to preserve the original.
Commands Used:
Change Directory to Downloads and ctags directory:
$cd$cd Down<tab>ctags<tab>
Configure:
$./configure
Make:
$make
Move to /usr/bin:
$sudo mv ctags /usr/bin/ctags-exuberant
NOTE: <tab> is equal to pressing the tab key.NOTE: XCode can now be downloaded from the Apple App Store!
Very useful for getting Tagbar for vim to work!
Tagbar is available here.
If I compile PHP 5 from source and realize I forgot a --with-curl in it, can I run the same ./configure command and add --with-curl at the end and it will add it? Or can I just do ./configure --with-curl and it will add it to the everything that is already installed?
You have to reconfigure and then recompile.
You need to added it to the end of your old configuration like this
./configure --with-something1 --with-something2 --with-curl
You should run ./configure (previous command + new addition), make, make install, make clean.
./configure doesn't remember the parameters you last used to call it, although you can fish them out of config.status if you have forgotten them.
You need to run the correct configure command and compile using the make command. If you wane more information about autoconf see http://www.gnu.org/software/autoconf/#introduction basically ./configure just sets up the build and you can change options using it.