Configure command

Build PHP from source

Packages without -dev typically do not contain necessary header files.

If you are using Debian or Ubuntu you can use apt-get build-dep php5 to install a large number of optional build-dependencies in one go. If you are only aiming for a default build, many of them will not be necessary though.

Building PHP

The latest PHP is PHP 5.6.6 at the time of writing, and we have latest Debian 7.8 Wheezy. Let’s get the dependencies we need to build PHP from source:

Needed dependecies, for sure:

apt-get -y install \
    libdb-dev libxpm-dev libbz2-dev libc-client-dev \
    libcurl4-openssl-dev libevent-dev libfreetype6-dev libgmp3-dev \
    libicu-dev libjpeg-dev libpng-dev libpspell-dev libsasl2-dev \
    libsnmp-dev libxml2-dev libxslt-dev unixodbc-dev

Download and unzip sources:

cd /usr/local/src
wget http://php.net/get/php-5.6.6.tar.bz2/from/this/mirror -O php.tar.bz2
tar -xvf php.tar.bz2

cd php-5.6.6/

Configure and compile PHP

In order to enable FPM in your PHP build you must add --enable-fpm to your configure line.

I have chosen to install it in /usr/local/php566-fpm. We must use the prefix switch in order for your new PHP to be installed inside a single directory.

The exact ./configure is so huge that I decided to put it in separate file.

./configure ... lot of stuff ...

Now, we make and install it, this could take a while:

# build
make --jobs=4

We can always clean up everything that make did with make clean.

For a faster build, -j N replace N with the number of CPU cores you have available - grep "cpu cores" /proc/cpuinfo.

By default PHP will build binaries for the CLI and CGI SAPIs, which will be located at sapi/cli/php and sapi/cgi/php-cgi respectively. To check that everything went well, try running sapi/cli/php -v.

# install php
# apt-get install checkinstall
checkinstall -D --pkgname="php-5.6.6-custom" make install

Note the neat trick about using a checkinstall tool. Option -D commands to build a Debian package.

When asked, use a name php-5.6.6-custom, so later I can remove it with apt-get remove php-5.6.6-custom

Plesk: Install PHP 5.4 on Debian Squeeze CheckInstall


Adding a folder conf.d which PHP will search for additional ini-files.

mkdir -p /etc/php5/php566/fpm/conf.d

When this is complete, the PHP is installed in place, and we need to copy the default php.ini file to the install directory:

cp php.ini-production /etc/php5/php566/fpm/php.ini

I have added the following to an ini-file in php.d, to enable OPCache and adjust some configuration files:

tmp=$(cat /etc/timezone)
sed -i "s#;date.timezone =#date.timezone = $tmp#" /etc/php5/php566/fpm/php.ini

cat <<'EOF' > /etc/php5/php566/fpm/conf.d/10-opcache.ini
; configuration for Zend opCache
post_max_size = 32M
upload_max_filesize = 32M
zend_extension=/usr/local/php566/lib/php/20131226/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=2001
opcache.revalidate_freq=5
opcache.fast_shutdown=1
opcache.enable_cli=0
opcache.enable=1
EOF
Adding the PHP to Plesk

This can be done for every SAPI type, EXCEPT for php-fpm.

plesk bin php_handler --add \
    -displayname "5.6.6" \
    -path /usr/local/php566/bin/php-cgi \
    -phpini /usr/local/php-5.6.6/etc/php.ini \
    -type fastcgi \
    -id "fastcgi-5.6.6"

But for php-fpm, I will just switch executable in service script /etc/init.d/php5-fpm. Only the line DAEMON=/usr/sbin/$NAME will be changed.

sed -i -re 's/^(DAEMON=\/usr\/sbin\/\$NAME)/# \1\'$'\nDAEMON=\/usr\/local\/php566\/sbin\/php-fpm/g' /etc/init.d/php5-fpm
service php5-fpm restart

Sources & Articles


Configure command

By default most extensions will be compiled statically, i.e. they will be part of the resulting binary.

Only the opcache extension is shared by default, i.e. it will generate an opcache.so shared object in the modules/ directory. You can compile other extensions into shared objects as well by writing --enable-NAME=shared or --with-NAME=shared, but not all extensions support this.

php-fpm and php-cgi are mutually exclusive, as the php-cgi binary is not created if PHP is compiled with --enable-fpm. If you want to use PHP as FastCGI module and with the FPM daemon you must compile PHP several times until you get all the binaries you need.

Problems when compiling PHP with fpm and cgi

In this multi-line command, I used this trick about comments.

Configure command:

./configure \
    --with-pic                                                      `# compiler libtool directive `\
    \
    --prefix=/usr/local/php566 \
    --with-config-file-path=/etc/php5/php566/fpm                    `# will use php.ini located we already use `\
    --with-config-file-scan-dir=/etc/php5/php566/fpm/conf.d         `# use the same search path for .ini files `\
    \
    --enable-fpm                                                    `# build the fpm SAPI and not php-cgi `\
    --with-fpm-group=www-data                                       `# UID of web server, based on /var/run/php5-fpm.sock ownership `\
    --with-fpm-user=www-data                                        `# GID `\
    \
    --enable-opcache                                                `# enable zend opcache support `\
    \
    --enable-bcmath                                                 `# enable bc style precision math functions `\
    --with-bz2                                                      `# include bzip2 support `\
    --enable-calendar                                               `# enable support for calendar conversion `\
    --with-curl                                                     `# cURL support / --with-curl=shared,/usr `\
    \
    --enable-dba=shared                                             `# My PHP supported: db4 cdb cdb_make inifile flatfile qdbm ~ http://php.net/manual/en/dba.installation.php `\
    `# --with-db4                                                   # or: --with-db4=/usr `\
    `# --with-qdbm                                                  # DBA: this one is not bundled or enabled by default `\
    \
    --enable-exif                                                   `# Enable EXIF (metadata from images) support `\
    --enable-ftp                                                    `# Enable FTP support `\
    \
    --with-gd                                                       `# http://php.net/manual/en/image.installation.php `\
    --with-png-dir=shared,/usr                                      `# or: --with-png-dir=/usr/local/php566  `\
    --with-jpeg-dir=shared,/usr                                     `# or: --with-jpeg-dir=/usr/local/php566  `\
    --with-xpm-dir=shared                                           `# /usr/local/php566 or: --with-xpm-dir=shared,/usr/X11R6  `\
    --with-freetype-dir=shared,/usr                                 `# or: --with-freetype-dir=/usr/local/php566  `\
    --enable-gd-native-ttf                                          `# Enable TrueType string function `\
    \
    --with-gettext                                                  `# Include GNU gettext support `\
    --with-mhash                                                    `# Include mhash support `\
    \
    --with-imap                                                     `#  or: --with-imap=shared,/usr ~ http://php.net/manual/en/imap.installation.php`\
    --with-imap-ssl                                                 `#  `\
    --with-kerberos                                                 `#  IMAP: Include Kerberos support ~ or: --with-kerberos=/usr  `\
    \
    --enable-mbstring                                               `# Multibyte string support ~ http://php.net/manual/en/mbstring.installation.php `\
    \
    --with-mysql                                                    `# mysqlnd is default ~ http://php.net/manual/en/mysql.installation.php `\
    --with-mysqli                                                   `# for every mysql extension ~ http://php.net/manual/en/mysqli.installation.php `\
    \
    --with-openssl                                                  `# OpenSSL support ~ http://php.net/manual/en/openssl.installation.php or: with-openssl=/usr `\
    \
    --with-pdo-mysql                                                `# --with-pdo-mysql=mysqlnd is not needed, as native driver is default now `\
    --with-pdo-sqlite                                               `# SQLite PDO support `\
    \
    --enable-shmop                                                  `# shmop support ~ http://php.net/manual/en/shmop.installation.php `\
    --enable-soap                                                   `# SOAP support ~ http://php.net/manual/en/soap.installation.php `\
    --enable-sockets                                                `# sockets support ~ http://php.net/manual/en/sockets.installation.php `\
    \
    --enable-sysvmsg                                                `# sysvmsg support ~ http://php.net/manual/en/sem.installation.php `\
    --enable-sysvsem                                                `# `\
    --enable-sysvshm                                                `# `\
    \
    --enable-wddx                                                   `# WDDX support ~ http://php.net/manual/en/wddx.installation.php `\
    --with-xsl                                                      `# --with-xsl=shared,/usr ~ http://php.net/manual/en/xsl.installation.php  `\
    --enable-zip                                                    `# include zip read/write support ~ http://php.net/manual/en/zip.installation.php `\
    --with-zlib                                                     `# include ZLIB support ~ http://php.net/manual/en/zlib.installation.php `\
    --with-xmlrpc                                                   `# XML-RPC support ~ http://php.net/manual/en/xmlrpc.installation.php `\
    \
    --with-mcrypt                                                   `# Must be enabled for Laravel PHP framework. Include mcrypt support `\
    \
    `# --build=x86_64-linux-gnu                                     # don't touch as system types are guessed `\
    `# --host=x86_64-linux-gnu                                      # no need to force anything `\
    \
    `# --enable-mbregex                                             # enabled by default ~ http://php.net/manual/en/mbstring.installation.php `\
    `# --enable-ctype                                               # enabled by default ~ http://php.net/manual/en/ctype.installation.php `\
    `# --with-iconv                                                 # enabled by default ~ http://php.net/manual/en/iconv.installation.php `\
    `# --with-libxml-dir=/usr                                       # enabled by default ~ http://php.net/manual/en/libxml.installation.php `\
    `# --with-pcre-regex                                            # enabled by default, --with-pcre-regex=/usr ~ http://php.net/manual/en/pcre.installation.php `\
    `# --enable-pdo                                                 # enabled by default ~ http://php.net/manual/en/pdo.drivers.php `\
    `# --enable-simplexml                                           # enabled by default ~ http://php.net/manual/en/simplexml.installation.php `\
    `# --with-sqlite3                                               # enabled by default ~ http://php.net/manual/en/sqlite3.installation.php `\
    `# --enable-xmlreader                                           # enabled by default ~ http://php.net/manual/en/xmlreader.installation.php `\
    `# --enable-xmlwriter                                           # enabled by default ~ http://php.net/manual/en/xmlwriter.installation.php `\
    `# --disable-dom                                                # enabled by default `\
    `# --with-flatfile                                              # enabled by default ~ DBA: FlatFile support is bundled `\
    `# --with-cdb                                                   # enabled by default ~ DBA: CDB support is bundled `\
    `# --with-inifile                                               # enabled by default ~ DBA: INI support is bundled `\
    `# --with-pdo-pgsql                                             # postgre sql was disabled in my php `\
    `# --with-mysql-sock=/var/run/mysqld/mysqld.sock                # optional ~ http://php.net/manual/en/ref.pdo-mysql.php `\
    `# --with-zlib-dir=/usr                                         # optional to specify `\
    `# --without-gdbm                                               # disabled by default ~ part of "--enable-dba" `\
    `# --without-mssql                                              # disabled by default ~ microsoft ~ http://php.net/manual/en/mssql.installation.php `\
    `# --without-sybase-ct                                          # disabled by default ~ http://php.net/manual/en/sybase.installation.php `\
    \
    `# --with-onig=/usr                                             # Can't find enywhere what "onig" is? `\
    \
    `# The Phar extension is now built into PHP ~ http://php.net/manual/en/phar.installation.php `\
    `# POSIX functions are enabled by default ~ http://php.net/manual/en/posix.installation.php `\
    `# Reflection functions are part of the PHP core ~ http://php.net/manual/en/reflection.installation.php `\
    `# SPL available and compiled by default ~ http://php.net/manual/en/spl.installation.php `\
    `# Tokenizer funtions are enabled by default ~ http://php.net/manual/en/tokenizer.installation.php `\
    `# XML Parser is enabled by default ~ http://php.net/manual/en/xml.installation.php `\
    \
    `# WARNING: unrecognized options: `\
    `# --with-fpm-systemd                                           # my system doesn't support systemd integration to report health `\
    `# --with-libevent-dir=/usr                                     # no more libevent requirement ~ http://php.net/manual/en/install.fpm.install.php#101754 `\
    `# --with-system-tzdata                                         # unrecognized! system-supplied time zone database is used `\
    \
    --localstatedir=/var                                            `# read variable machine data from here, as default is different `\
    --mandir=/usr/share/man                                         `# `\
    --sysconfdir=/etc                                               `# read system configuration from here, as default is different `\
    \
    --with-layout=GNU                                               `# Minor diff in loc of ext dir ~ http://serverfault.com/a/293523/69638  `\
    \
    --with-pear=/usr/share/php                                      `# Install PEAR in DIR `\
    --with-regex                                                    `# php is already a default TYPE (=php) ~ http://php.net/manual/en/regex.installation.php `\
    \
    --disable-rpath                                                 `# disable passing additional runtime library search paths `\
    --disable-static                                                `# don't  build static libraries `\
    --without-mm                                                    `# disable mm support for session storage  `\

Configure usage from help

./configure usage:

By default, make install will install all the files in /usr/local/bin, /usr/local/lib etc. You can specify an installation prefix other than /usr/local using --prefix, for instance --prefix=$HOME.

Enable-disable, with-without, yes-no. Explanation:

--disable-option-checking  ignore unrecognized --enable/--with options
--disable-FEATURE          do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG]     include FEATURE [ARG=yes]
--with-PACKAGE[=ARG]       use PACKAGE [ARG=yes]
--without-PACKAGE          do not use PACKAGE (same as --with-PACKAGE=no)
--with-libdir=NAME         Look for libraries in .../NAME rather than .../lib
--disable-rpath            Disable passing additional runtime library search paths
--enable-re2c-cgoto        Enable -g flag to re2c to use computed goto gcc extension

| Installation directories: | | | –prefix=PREFIX | install architecture-independent files in PREFIX [/usr/local] | | –exec-prefix=EPREFIX | install architecture-dependent files in EPREFIX [PREFIX] | | | | | Fine tuning of the install dirs: | | | –bindir=DIR | user executables [EPREFIX/bin] | | –sbindir=DIR | system admin executables [EPREFIX/sbin] | | –libexecdir=DIR | program executables [EPREFIX/libexec] | | –sysconfdir=DIR | read-only single-machine data [PREFIX/etc] | | –sharedstatedir=DIR | modifiable architecture-independent data [PREFIX/com] | | –localstatedir=DIR | modifiable single-machine data [PREFIX/var] | | –libdir=DIR | object code libraries [EPREFIX/lib] | | –includedir=DIR | C header files [PREFIX/include] | | –oldincludedir=DIR | C header files for non-gcc [/usr/include] | | –datarootdir=DIR | read-only arch.-independent data root [PREFIX/share] | | –datadir=DIR | read-only architecture-independent data [DATAROOTDIR] | | –infodir=DIR | info documentation [DATAROOTDIR/info] | | –localedir=DIR | locale-dependent data [DATAROOTDIR/locale] | | –mandir=DIR | man documentation [DATAROOTDIR/man] | | –docdir=DIR | documentation root [DATAROOTDIR/doc/PACKAGE] | | –htmldir=DIR | html documentation [DOCDIR] | | –dvidir=DIR | dvi documentation [DOCDIR] | | –pdfdir=DIR | pdf documentation [DOCDIR] | | –psdir=DIR | ps documentation [DOCDIR] | | | | | System types: | | | –build=BUILD | configure for building on BUILD [guessed] | | –host=HOST | cross-compile to build programs to run on HOST [BUILD] | | –target=TARGET | configure for building compilers for TARGET [HOST] | | | | | SAPI modules: | | | –with-apxs=FILE | Build shared Apache 1.x module. | | –with-apxs2=FILE | Build shared Apache 2.0 Handler module. FILE is the optional pathname to Apache apxs tool apxs | | –disable-cli | Disable building CLI version of PHP (this forces –without-pear) | | –enable-fpm | Enable building of the fpm SAPI executable | | –with-fpm-user=USER | Set the user for php-fpm to run as. (default: nobody) | | –with-fpm-group=GRP | Group for php-fpm. For a system user, usually be set to match the fpm username (default: nobody) | | –with-fpm-systemd | Activate systemd integration | | –with-fpm-acl | Use POSIX Access Control Lists | | –enable-phpdbg | Build phpdbg - PHP Debugger | | –enable-phpdbg-debug | Build phpdbg in debug mode | | –disable-cgi | Disable building CGI version of PHP | | | | | General settings: | | | –enable-debug | Compile with debugging symbols | | –with-layout=TYPE | Set how installed files will be laid out. Type can be either PHP or GNU [PHP] | | | | | –with-config-file-path=PATH | Set the path in which to look for php.ini [PREFIX/lib] | | –with-config-file-scan-dir=PATH | Set the path where to scan for configuration files | | –disable-short-tags | Disable the short-form <? start tag by default | | –disable-ipv6 | Disable IPv6 support | | –enable-dtrace | Enable DTrace support | | –enable-fd-setsize | Set size of descriptor sets | | | | | Extensions: | | | –with-EXTENSION=shared[,PATH] | NOTE: Not all extensions can be build as ‘shared’. | | | | | –disable-all | Disable all extensions which are enabled by default | | –with-regex=TYPE | Regex library type: system, php. TYPE=php | | –disable-libxml | Disable LIBXML support | | –with-libxml-dir=DIR | LIBXML: libxml2 install prefix | | –with-openssl=DIR | Include OpenSSL support (requires OpenSSL >= 0.9.6) | | –with-kerberos=DIR | OPENSSL: Include Kerberos support | | –with-system-ciphers | OPENSSL: Use system default cipher list instead of hardcoded value | | –with-pcre-regex=DIR | Include Perl Compatible Regular Expressions support. DIR is the PCRE install prefix BUNDLED | | –without-sqlite3=DIR | Do not include SQLite3 support. DIR is the prefix to SQLite3 installation directory. | | –with-zlib=DIR | Include ZLIB support (requires zlib >= 1.0.9) | | –with-zlib-dir=

| Define the location of zlib install directory | | –enable-bcmath | Enable bc style precision math functions | | –with-bz2=DIR | Include BZip2 support | | –enable-calendar | Enable support for calendar conversion | | –disable-ctype | Disable ctype functions | | –with-curl=DIR | Include cURL support | | –enable-dba | Build DBA with bundled modules. To build shared DBA extension use –enable-dba=shared | | –with-qdbm=DIR | DBA: QDBM support | | –with-gdbm=DIR | DBA: GDBM support | | –with-ndbm=DIR | DBA: NDBM support | | –with-db4=DIR | DBA: Oracle Berkeley DB 4.x or 5.x support | | –with-db3=DIR | DBA: Oracle Berkeley DB 3.x support | | –with-db2=DIR | DBA: Oracle Berkeley DB 2.x support | | –with-db1=DIR | DBA: Oracle Berkeley DB 1.x support/emulation | | –with-dbm=DIR | DBA: DBM support | | –with-tcadb=DIR | DBA: Tokyo Cabinet abstract DB support | | –without-cdb=DIR | DBA: CDB support (bundled) | | –disable-inifile | DBA: INI support (bundled) | | –disable-flatfile | DBA: FlatFile support (bundled) | | –disable-dom | Disable DOM support | | –with-libxml-dir=DIR | DOM: libxml2 install prefix | | –with-enchant=DIR | Include enchant support. GNU Aspell version 1.1.3 or higher required. | | –enable-exif | Enable EXIF (metadata from images) support | | –disable-fileinfo | Disable fileinfo support | | –disable-filter | Disable input filter support | | –with-pcre-dir | FILTER: pcre install prefix | | –enable-ftp | Enable FTP support | | –with-openssl-dir=DIR | FTP: openssl install prefix | | –with-gd=DIR | Include GD support. DIR is the GD library base install directory BUNDLED | | –with-vpx-dir=DIR | GD: Set the path to libvpx install prefix | | –with-jpeg-dir=DIR | GD: Set the path to libjpeg install prefix | | –with-png-dir=DIR | GD: Set the path to libpng install prefix | | –with-zlib-dir=DIR | GD: Set the path to libz install prefix | | –with-xpm-dir=DIR | GD: Set the path to libXpm install prefix | | –with-freetype-dir=DIR | GD: Set the path to FreeType 2 install prefix | | –with-t1lib=DIR | GD: Include T1lib support. T1lib version >= 5.0.0 required | | –enable-gd-native-ttf | GD: Enable TrueType string function | | –enable-gd-jis-conv | GD: Enable JIS-mapped Japanese font support | | –with-gettext=DIR | Include GNU gettext support | | –with-gmp=DIR | Include GNU MP support | | –with-mhash=DIR | Include mhash support | | –disable-hash | Disable hash support | | –without-iconv=DIR | Exclude iconv support | | –with-imap=DIR | Include IMAP support. DIR is the c-client install prefix | | –with-kerberos=DIR | IMAP: Include Kerberos support. DIR is the Kerberos install prefix | | –with-imap-ssl=DIR | IMAP: Include SSL support. DIR is the OpenSSL install prefix | | –with-interbase=DIR | Include InterBase support. DIR is the InterBase base install directory /usr/interbase | | –enable-intl | Enable internationalization support | | –with-icu-dir=DIR | Specify where ICU libraries and headers can be found | | –disable-json | Disable JavaScript Object Serialization support | | –with-ldap=DIR | Include LDAP support | | –with-ldap-sasl=DIR | LDAP: Include Cyrus SASL support | | –enable-mbstring | Enable multibyte string support | | –disable-mbregex | MBSTRING: Disable multibyte regex support | | –disable-mbregex-backtrack | MBSTRING: Disable multibyte regex backtrack check | | –with-libmbfl=DIR | MBSTRING: Use external libmbfl. DIR is the libmbfl base install directory BUNDLED | | –with-mcrypt=DIR | Include mcrypt support | | –with-mssql=DIR | Include MSSQL-DB support. DIR is the FreeTDS home directory /usr/local/freetds | | –with-mysql=DIR | MySQL support. DIR is the MySQL base directory, if no DIR or =mysqlnd, MySQLnd will be used | | –with-mysql-sock=SOCKPATH | Location MySQL unix socket pointer. If unspecified, default loc’s searched | | –with-zlib-dir=DIR | MySQL: Set the path to libz install prefix | | –with-mysqli=FILE | MySQLi support. FILE is the path to mysql_config. if no FILE or =mysqlnd, MySQLnd will be used | | –enable-embedded-mysqli | MYSQLi: Enable embedded support. Note: Does not work with MySQL native driver! | | –enable-opcache | Enable Zend OPcache support | | –enable-pcntl | Enable pcntl support (CLI/CGI only), Process Control support in PHP | | –disable-pdo | Disable PHP Data Objects support | | –with-pdo-dblib=DIR | PDO: DBLIB-DB support. DIR is the FreeTDS home directory | | –with-pdo-mysql=DIR | PDO: MySQL support. DIR is MySQL base directory. if no DIR or =mysqlnd, MySQLnd will be used | | –with-zlib-dir=DIR | PDO_MySQL: Set the path to libz install prefix | | –with-pdo-pgsql=DIR | PDO: PostgreSQL support. DIR is the PostgreSQL base install dir or the path to pg_config | | –without-pdo-sqlite=DIR | PDO: sqlite 3 support. DIR is the sqlite base install directory BUNDLED | | –with-pgsql=DIR | Include PostgreSQL support. DIR is the PostgreSQL base install dir or the path to pg_config | | –disable-phar | Disable phar support | | –disable-posix | Disable POSIX-like functions | | –with-pspell=DIR | Include PSPELL support. GNU Aspell version 0.50.0 or higher required | | –with-libedit=DIR | Include libedit readline replacement (CLI/CGI only) | | –with-readline=DIR | Include readline support (CLI/CGI only) | | –with-recode=DIR | Include recode support | | –disable-session | Disable session support | | –with-mm=DIR | SESSION: Include mm support for session storage | | –enable-shmop | Enable shmop support | | –disable-simplexml | Disable SimpleXML support | | –with-libxml-dir=DIR | SimpleXML: libxml2 install prefix | | –with-snmp=DIR | Include SNMP support | | –with-openssl-dir=DIR | SNMP: openssl install prefix | | –enable-soap | Enable SOAP support | | –with-libxml-dir=DIR | SOAP: libxml2 install prefix | | –enable-sockets | Enable sockets support | | –with-sybase-ct=DIR | Include Sybase-CT support. DIR is the Sybase home directory /home/sybase | | –enable-sysvmsg | Enable sysvmsg support | | –enable-sysvsem | Enable System V semaphore support | | –enable-sysvshm | Enable the System V shared memory support | | –with-tidy=DIR | Include TIDY support | | –disable-tokenizer | Disable tokenizer support | | –enable-wddx | Enable WDDX support | | –with-libxml-dir=DIR | WDDX: libxml2 install prefix | | –with-libexpat-dir=DIR | WDDX: libexpat dir for XMLRPC-EPI (deprecated) | | –disable-xml | Disable XML support | | –with-libxml-dir=DIR | XML: libxml2 install prefix | | –with-libexpat-dir=DIR | XML: libexpat install prefix (deprecated) | | –disable-xmlreader | Disable XMLReader support | | –with-libxml-dir=DIR | XMLReader: libxml2 install prefix | | –with-xmlrpc=DIR | Include XMLRPC-EPI support | | –with-libxml-dir=DIR | XMLRPC-EPI: libxml2 install prefix | | –with-libexpat-dir=DIR | XMLRPC-EPI: libexpat dir for XMLRPC-EPI (deprecated) | | –with-iconv-dir=DIR | XMLRPC-EPI: iconv dir for XMLRPC-EPI | | –disable-xmlwriter | Disable XMLWriter support | | –with-libxml-dir=DIR | XMLWriter: libxml2 install prefix | | –with-xsl=DIR | Include XSL support. DIR is the libxslt base install directory (libxslt >= 1.1.0 required) | | –enable-zip | Include Zip read/write support | | –with-zlib-dir=DIR | ZIP: Set the path to libz install prefix | | –with-pcre-dir | ZIP: pcre install prefix | | –with-libzip=DIR | ZIP: use libzip | | –enable-mysqlnd | Enable mysqlnd explicitly, will be done implicitly when required by other extensions | | –disable-mysqlnd-compression-support | Disable support for the MySQL compressed protocol in mysqlnd | | –with-zlib-dir=DIR | mysqlnd: Set the path to libz install prefix | | | | | PEAR: | | | –with-pear=DIR | Install PEAR in DIR [PREFIX/lib/php] | | –without-pear | Do not install PEAR | | | | | Libtool: | | | –enable-shared=PKGS | Build shared libraries default=yes | | –enable-static=PKGS | Build static libraries default=yes | | –enable-fast-install=PKGS | Optimize for fast installation default=yes | | –with-gnu-ld | Assume the C compiler uses GNU ld default=no | | –disable-libtool-lock | Avoid locking (might break parallel builds) | | –with-pic | Try to use only PIC/non-PIC objects default=use both | | –with-tags=TAGS | Include additional configurations automatic | | | |

0 - Options used for original PHP build script (php-config)

./configure
--prefix=/usr


--enable-ctype
--enable-intl=shared
--mandir=/usr/share/man
# --with-apxs2=/usr/bin/apxs2 # Build shared Apache 2.0 module
--with-bz2
--with-enchant=shared,/usr
--with-gmp=shared,/usr
--with-layout=GNU
--with-ldap-sasl=/usr
--with-ldap=shared,/usr
--with-mcrypt=shared,/usr

--with-onig=/usr
--with-pear=/usr/share/php
--with-pgsql=shared,/usr
--with-pspell=shared,/usr
--with-recode=shared,/usr
--with-snmp=shared,/usr
--with-tidy=shared,/usr
--with-unixODBC=shared,/usr
--with-xmlrpc=shared
--without-t1lib

1-1 - Configure PHP ceromedia

./configure \
--prefix=/usr/local/php5514

--enable-intl
--enable-pcntl
--with-bz2

--with-gmp
--with-libdir=lib64
--with-mcrypt
--with-snmp
--with-xmlrpc

1 - Configure PHP build script - Stayallive

./configure \
--prefix=/php/php-5.6.4 \

--cache-file=./config.cache \
--enable-intl \
--enable-pcntl \
--with-bz2 \
--with-gmp \
--with-ldap \
--with-ldap-sasl \
--with-libdir=lib64 \
--with-mcrypt \
--with-pear=/php/php-5.6.4/pear \
--with-pspell \
--with-snmp \
--with-unixODBC=/usr \

2 - Configure PHP build script - http://aarvik.dk/, Debian

./configure \
--prefix=/usr/local/php5515

--enable-intl
--enable-pcntl
--with-bz2
--with-gmp
--with-libdir=lib64
--with-mcrypt
--with-snmp
--with-vpx-dir=/usr/local/php5515
--with-xmlrpc

3 - Configure PHP build script

./configure \
--prefix=/usr/local/php55

--with-bz2
--with-pear
--with-xmlrpc

4 - From Plesk - http://kb.sp.parallels.com/en/118378

./configure
--prefix=/usr/local/php563-cgi

--cache-file=../config.cache
# --enable-fastcgi # If this is enabled, the CGI module will be built with support for FastCGI also. No longer exists and is enabled by --enable-cgi instead.
--enable-intl
--enable-pcntl
--with-bz2
--with-config-file-path=/usr/local/php563-cgi/etc
--with-config-file-scan-dir=/usr/local/php563-cgi/php.d
--with-gmp
--with-ldap
--with-ldap-sasl
--with-libdir=lib64
--with-pear=/usr/local/php563-cgi/pear
--with-pspell
--with-snmp
--with-unixODBC=/usr
--with-xmlrpc
--with-xsl
Location of built extensions

Make install will put shared extensions in different directories depending on ZTS options. Directory will be called $PREFIX/lib/php/extensions/no-debug-non-zts-API_NO for release builds without ZTS, or debug-non-zts-API_NO, no-debug-zts-API_NO, debug-zts-API_NO where API_NO placeholder above refers to the ZEND_MODULE_API_NO and is just a date like 20100525, which is used for internal API versioning.

As I don’t want this zts naming, I found out ZEND_MODULE_API_NO on my PHP by typing grep ZEND_MODULE_API_NO Zend/zend_modules.h from PHP src-dir.

--extension-dir # shared modules will be built into /usr/lib/php5/20131226 (was 20100525)
Original config
Usage: /usr/bin/php-config5 [OPTION]
Options:
  --prefix            [/usr]
  --includes          [-I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib ]
  --ldflags           [-L/usr/lib/php5  -L/usr/lib/x86_64-linux-gnu]
  --libs              [-lcrypt   -lz -lcrypt -lonig -lstdc++ -lcrypto -lssl -ldb -lqdbm -lbz2 -lz -lpcre -lcrypto -lssl -lrt -lm -ldl -lnsl  -lxml2 -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lxml2 -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lxml2 -lcrypt ]
  --extension-dir     [/usr/lib/php5/20100525]
  --include-dir       [/usr/include/php5]
  --man-dir           [/usr/share/man]
  --php-binary        [/usr/bin/php]
  --php-sapis         [apache2handler apache2filter cgi cli fpm ]
  --phpapi            [20100525]
  --configure-options [--prefix=/usr --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php5/apache2 --with-config-file-scan-dir=/etc/php5/apache2/conf.d --build=x86_64-linux-gnu --host=x86_64-linux-gnu --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --disable-debug --with-regex=php --disable-rpath --disable-static --with-pic --with-layout=GNU --with-pear=/usr/share/php --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-db4 --with-qdbm=/usr --without-gdbm --with-iconv --enable-exif --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex=/usr --enable-shmop --enable-sockets --enable-wddx --with-libxml-dir=/usr --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --with-system-tzdata --with-mysql-sock=/var/run/mysqld/mysqld.sock --without-mm --with-curl=shared,/usr --with-enchant=shared,/usr --with-zlib-dir=/usr --with-gd=shared,/usr --enable-gd-native-ttf --with-gmp=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6 --with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-imap=shared,/usr --with-imap-ssl --enable-intl=shared --without-t1lib --with-ldap=shared,/usr --with-ldap-sasl=/usr --with-mcrypt=shared,/usr --with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config --with-pspell=shared,/usr --with-unixODBC=shared,/usr --with-recode=shared,/usr --with-xsl=shared,/usr --with-snmp=shared,/usr --with-sqlite3=shared,/usr --with-mssql=shared,/usr --with-tidy=shared,/usr --with-xmlrpc=shared --with-pgsql=shared,/usr]
  --version           [5.4.36-0+deb7u3]
  --vernum            [50436]

Fixing the problems

Installing with make install…

========================= Installation results =========================== Installing shared extensions: /usr/local/php566/lib/php/20131226/ Installing PHP CLI binary: /usr/local/php566/bin/ Installing PHP CLI man page: /usr/share/man/man1/ Installing PHP FPM binary: /usr/local/php566/sbin/ Installing PHP FPM config: /etc/ Installing PHP FPM man page: /usr/share/man/man8/ Installing PHP FPM status page: /usr/local/php566/share/php/fpm/ Installing PHP CGI binary: /usr/local/php566/bin/ Installing PHP CGI man page: /usr/share/man/man1/ Installing build environment: /usr/local/php566/lib/php/build/ Installing header files: /usr/local/php566/include/php/ Installing helper programs: /usr/local/php566/bin/ program: phpize program: php-config Installing man pages: /usr/share/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/share/php/ [PEAR] Archive_Tar - installed: 1.3.12 [PEAR] Console_Getopt - installed: 1.3.1 [PEAR] Structures_Graph- installed: 1.0.4 [PEAR] XML_Util - installed: 1.2.3 [PEAR] PEAR - installed: 1.9.5 Wrote PEAR system config file at: /etc/pear.conf You may want to add: /usr/share/php to your php.ini include_path /usr/local/src/php-5.6.6/build/shtool install -c ext/phar/phar.phar /usr/local/php566/bin ln -s -f /usr/local/php566/bin/phar.phar /usr/local/php566/bin/phar Installing PDO headers: /usr/local/php566/include/php/ext/pdo/

======================== Installation successful ==========================

Done. The new package has been installed and saved to

/usr/local/src/php-5.6.6/php_5.6.6-1_amd64.deb

You can remove it from your system anytime using:

  dpkg -r php

On testing /usr/local/php566/bin/php --ini we get:

Failed loading /usr/lib/php5/20100525/ioncube_loader_lin_5.4.so:
/usr/lib/php5/20100525/ioncube_loader_lin_5.4.so: undefined symbol:
execute

PHP Warning:  PHP Startup: Unable to load dynamic library
'/usr/local/php566/lib/php/20131226/pdo.so' -
/usr/local/php566/lib/php/20131226/pdo.so: cannot open shared object
file: No such file or directory in Unknown on line 0

If I change extension_dir = "/usr/lib/php5/20100525" in /etc/php5/fpm/php.ini, I get for every extension:

Failed loading /usr/lib/php5/20100525/ioncube_loader_lin_5.4.so:  /usr/lib/php5/20100525/ioncube_loader_lin_5.4.so: undefined symbol: execute
PHP Warning:  PHP Startup: PDO: Unable to initialize module
Module compiled with module API=20100525
PHP    compiled with module API=20131226
These options need to match

So, that’s not an option.

ionCube Loader

ionCUbe Loader is Zend extension module for loading protected/crypted PHP files.

I checked it out and I found out that ionCube Loader is not required for my installation and I can switch and install my version because Plesk uses totally different and separate module (/usr/lib/x86_64-linux-gnu/php/modules/sw-engine/ioncube_loader_lin_5.5.so).

So, it’s safe to disable or upgrade ionCube. Standard location is in /usr/lib/php5/20100525/.

Installing IonCube Loader

Fix missing extension modules

pdo.so curl.so gd.so imap.so mysql.so mysqli.so pdo_mysql.so pdo_sqlite.so sqlite3.so xsl.so


scripts/php-switch at master · tobiasgies/scripts

Adding an extension as module

You can install Mcrypt from the PHP source tree as a module. You first need to ensure you have libmcrypt, libmcrypt-devel, and mcrypt installed, then do:

/usr/local/php566/bin/phpize


make
checkinstall -D --pkgname="php-memcached-custom" make install

remove it anytime with `dpkg -r php-memcached-custom`

The problem was non-working:

/usr/local/php566/bin/pecl install memcached




cd /usr/local/src/php-5.6.6/ext/mcrypt/
/usr/local/php566/bin/phpize
./configure --with-php-config=/usr/local/php566/bin/php-config
make && make install

Compiled module is now in /usr/local/src/php-5.6.6/ext/mcrypt/modules. Enable the module by adding: extension=mcrypt.so to PHP.ini

cp /usr/local/src/php-5.6.6/ext/mcrypt/modules/mcrypt.so /usr/local/php566/lib/php/20131226/

And enable extension:

echo '
; Extension needed for Laravel PHP framework
;
extension=mcrypt.so
' > /etc/php5/php566/fpm/conf.d/10-mcrypt.ini

Very handy if you need to install a single module but don’t wish to recompile your whole PHP install.

C

Error: configure: error: mcrypt.h not found. Please reinstall libmcrypt.

I have to install libmcrypt with:

apt-get -y install mcrypt libmcrypt-dev

Optimize PHP-FPM

Monitor server reached max_children setting (), consider raising it messages.

tail -f /var/log/php5-fpm.log

How to calculate values

Find out free RAM without PHP-FPM (free -h). Look at the line -/+ buffers/cache as this is real free amount.

Divide the RAM you want dedicate to php (12G?) with average memory usage by a single process, and you have your max_children value.

Average memory usage by single PHP-FPM process:

ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("Number of PHP-FPM processes: %d\nAverage mem usage per process %dM\n", NR, sum/NR/1024) }'

Maximum memory usage by single PHP-FPM process:

ps --no-headers -o "rss,cmd" -C php-fpm | tail -n1 | awk '{ printf ("Max memory usage per process: %dM\n", $1/1024) }'

Do the same, but for some specific domain:

ps --no-headers -o "rss,cmd" -C php-fpm | grep "save-up.ch" | awk '{ sum+=$1 } END { printf ("Number of PHP-FPM processes: %d\nAverage mem usage per process %dM\n", NR, sum/NR/1024) }'
ps --no-headers -o "rss,cmd" -C php-fpm | grep "save-up.ch" | tail -n1 | awk '{ printf ("Max memory usage per process: %dM\n", $1/1024) }'

So, in my case I could set more than 700 but I believe that value of 200 will be more then enough.

Sources & Articles

In Plesk

If you want custom PHP-FPM pool values in Plesk, just add this as custom PHP directive. Plesk will automaticly put it where it should be.

Location of main PHP-FPM configuration file is /etc/php5/fpm/php-fpm.conf, and included ones - per domain are located at /etc/php5/fpm/pool.d/*.conf

** THIS IS NOT WORKING **

In file itself, it states:

If you need to customize this file, use either custom PHP settings tab in Panel or override settings in /var/www/vhosts/system/save-up.ch/conf/php.ini. To override pool configuration options, specify them in [php-fpm-pool-settings] section of /var/www/vhosts/system/save-up.ch/conf/php.ini file.

Default value was correct (ondemand spawning), and I just want to increase couple of values.

cat <<'EOF' > /var/www/vhosts/system/save-up.ch/etc/php.ini
[php-fpm-pool-settings]
pm.max_children = 100
EOF

Sources & Articles

  • PROBLEM

Extra Optimizations:

Add extra indexes to MySQL

WordPress wp_options table autoload micro-optimization

Increase realpath_cache_size

NOTE: No need, as of PHP7 the default is 4M

Increase realpath_cache_size to 128K to 256K for Wordpress

realpath_cache_size is used by PHP to keep from having to look up file names. Every time you perform any of the various file functions or include/require a file and use a relative path, PHP has to look up where that file really exists. PHP caches those values so it doesn’t have to search the current working directory and include_path for the file you’re working on.

Tweaking realpath_cache_size for SugarCRM PHP open_basedir and Magento Performance Optimize PHP performance, check and set PHP realpath_cache_size Solving drupal performance problem

echo "realpath_cache_size = 128k" /usr/local/etc/php/conf.d/speed-tweaks.ini

My usage on local server was around 45K.

echo "<pre>"; die(var_export(realpath_cache_size()) . "</pre>");

See below for Plesk.

Problem with open_basedir

Normally, PHP can cache various path locations it learns after processing include_once and require_once calls via the realpath_cache. There’s a bug in PHP that effectively disables the realpath_cache entirely when combined with open_basedir.

Confirmed: When PHP’s open_basedir restriction is set, PHP disables the realpath cache for security reasons.

Whissi/realpath_turbo Speed up PHP on NFS with turbo_realpath on CentOS

Solution can be to use realpath_turbo PHP extension or to disable open_basedir completely for the site:

nano /etc/php5/fpm/pool.d/save-up.ch.conf
service php5-fpm restart

; Put this in
; php.ini custom configuration directives
php_value[short_open_tag] = on
; php_value[open_basedir] = "/var/www/vhosts/save-up.ch/:/tmp/"
php_value[open_basedir] = ""
php_value[realpath_cache_size] = "128k"

; Following directives override default pool configuration
pm.max_children = 100

date 01. Jan 0001 | modified 29. Dec 2023
filename: Server - PHP Configure & Compile