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.
Related
Background
I use a RedHat machine without root access, no access to the yum packet manager and no Docker support. This is the policy unfortunately at my work.
I have configured Apache and PHP using a tar file in a folder. Also done same for MongoDB, now I try to configure the PHP drivers for MongoDB according to these instructions:
https://docs.mongodb.com/drivers/php/
However I get stuck on the first bullet:
sudo pecl install mongodb
Problem
Do I need PECL? Can the extension be downloaded manually, and added to PHP?
I have tried to download the mongodb extension manually from:
https://pecl.php.net/package/mongodb
How to compile it mongodb.so? I tried to run pecl on a machine where I have root access then I saw it downloaded the mongodb-1.10.0.tgz and run make (in output when installing).
When I unpack the tgz file manually, I am not able to run make. How to use the makefile.frag? How to run make?
Here is a link on how to build mongodb.so:
https://www.php.net/manual/en/mongodb.installation.manual.php
git clone https://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
git submodule update --init
phpize
./configure
make all
sudo make install
You can also unpack the mongodb-1.10.0.tgz file with:
tar -xvf mongodb-1.10.0.tgz
phpize
make all
sudo make install
I need SQLite minimum version 3.8 to support a MediaWiki install on Amazon EC2. Amazon Linux is based on CentOS and the latest version available in the yum repository is SQLite 3.7.17.
The downloads available from sqlite.org don't include 64-bit Linux. There is a GitHub repository that has a prebuilt 64-bit version, however it's only the command line version. I put it at /usr/bin:
$ which sqlite3
/usr/bin/sqlite3
$ sqlite3 --version
sqlite3: /lib64/libtinfo.so.5: no version information available (required by sqlite3)
3.26.0 2018-12-01 12:34:55 bf8c1b2b7a5960c282e543b9c293686dccff272512d08865f4600fb58238b4f9
But MediaWiki still complains I have SQLite 3.7.17 installed. When I test it I get:
$ cat x.php
<?php
print_r(SQLite3::version());
?>
Run it:
$ php7 x.php
Array
(
[versionString] => 3.7.17
[versionNumber] => 3007017
)
I am guessing this is because of these libraries:
$ sudo find / -name "libsqlite*"
/usr/lib64/libsqlite3.so.0
/usr/lib64/libsqlite3.so.0.8.6
How can I download/rebuild or otherwise install a later version of these SQLite libraries?
The easiest option I found was to build it myself. Tested on Amazon Linux release 2 (Karoo).
Download the latest source code with the configure script from here. Currently this is:
curl https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz | tar xzf -
Go into the created directory and create the Makefile with our system dependant options:
cd ./sqlite-autoconf-3320300 && ./configure
Build the binary
make
Install it
sudo make install
Clean up
cd .. && rm -r ./sqlite-autoconf-3320300
Note: It's far from ideal to do this without a proper RPM package. If you update sqlite through yum, you will overwrite you manually built version.
Adding on to #halbgut answer, with some changes:
Download the latest source code with the configure script from here. Currently this is:
curl https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz | tar xzf -
Go into the created directory and create the Makefile with our system dependent options:
cd ./sqlite-autoconf-3320300 && ./configure
Build the binary
make
Install it
sudo make install
Now, you have created the sqlite3 file. You need to replace them everywhere you find the file sqlite3.
To find all these places - run the following command:
whereis sqlite3
sqlite3: /usr/bin/sqlite3 /usr/local/bin/sqlite3 /usr/include/sqlite3.h /opt/c9/bin/sqlite3 /usr/share/man/man1/sqlite3.1.gz
Now within the sqlite source folder ./sqlite-autoconf-3320300, find the sqlite3, sqlite3.h files and replace with the following cp command
sudo cp sqlite-autoconf-3320300/sqlite3 /usr/local/bin/sqlite3
sudo cp sqlite-autoconf-3320300/sqlite3 /usr/local/bin/sqlite3
sudo cp sqlite-autoconf-3320300/sqlite3 /opt/c9/bin/sqlite3 {I am using c9, hence this file, figure out what file is in the opt/ dir)
sudo cp sqlite-autoconf-3320300/sqlite3.h /usr/include/sqlite3.h
Once done, you would have upgraded both env and python-env. Now you need to just define the path to it. For it, use the local/lib in usr.
export LD_LIBRARY_PATH="/usr/local/lib"
Now you should have this :
$ python -c "import sqlite3; print(sqlite3.sqlite_version)"
3.23.3
$ sqlite3 --version
3.32.3
If you just need the sqlite3 binary, the SQLite amalgamation also works perfectly on Amazon Linux 2. For SQLite 33.9.04 (or others from the SQLite Download section):
wget "https://www.sqlite.org/2022/sqlite-amalgamation-3390400.zip"
unzip "sqlite-amalgamation-3390400.zip"
cd "sqlite-amalgamation-3390400"
gcc shell.c sqlite3.c -lpthread -ldl -lm -o sqlite3
And then use it as you would any other software compiled from source:
ln -n ./sqlite3 ${wherever}/sqlite3
export PATH="${wherever}:$PATH"
SQLite docs give a good explanation of further options if you need them.
Get the latest sqlite3 download link from https://www.sqlite.org/download.html
and update the link given in the WGET bash command example shown below.
Example:
wget https://www.sqlite.org/2022/sqlite-tools-linux-x86-3400000.zip
unzip sqlite-tools*.zip
cd sqlite-tools*
sudo cp sql* /usr/local/bin/ # Usually this directory is empty, so no need to worry about overwriting files
cd ~
sudo yum update -y
sudo amazon-linux-extras install epel -y
sudo yum install glibc.i686 -y
sqlite3 --version
I've been trying to install HHVM (Hack) on Alpine linux to no success.
Has anyone compiled HHVM on linux?
Any help would be welcome.
Up to now, there's no HHVM on Alpine yet.
There's an open request in the bug tracker, though:
http://bugs.alpinelinux.org/issues/4503
maybe you did this request :)
You can monitor the website to see if there are update, or check possibile pull requests from here:
https://github.com/alpinelinux/aports/pulls
Hope it helps.
Francesco
If you look at this page Building HHVM from source, it requires "GCC 5 or GCC 7". The first step would have to be `apk add --update build-base' or have a look here: How to get regular stuff working. buid-base contains "GCC, libc-dev and binutils packages" etc.
FROM alpine:3.7
RUN apk add --no-cache build-base git cmake patch curl-dev findutils libxml2-dev icu-dev bash libevent libevent-dev curl
RUN git clone git://github.com/facebook/hhvm.git
RUN cd hhvm
WORKDIR hhvm
RUN git submodule update --init --recursive
ENV GYP_DEFINES "linux_use_bundled_binutils=0 linux_use_bundled_gold=0 clang=0"
RUN cmake -DMYSQL_UNIX_SOCK_ADDR=/var/run/mysqld/mysqld.sock .
RUN make -j [number_of_processor_cores] # eg. make -j 4
RUN make install
Got stuck here:
-- Can't find minimal tcmalloc
ERROR: Unable to find Intel TBB install directory.
CMake Error at CMake/HPHPFindLibs.cmake:266 (if):
if given arguments:
"LESS" "5005"
Unknown arguments specified
Call Stack (most recent call first):
CMakeLists.txt:106 (include)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBGLOG_INCLUDE_DIR (ADVANCED)
used as include directory in directory /hhvm
used as include directory in directory /hhvm
Would get you going at least halfway.
Think the issue is around :https://pkgs.alpinelinux.org/package/edge/testing/x86/libtbb
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
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.