Some Linux distributions take their time to package new stuff! Although Mandriva was a Linux distro that was famous for bringing the cutting edge every new version , it’s successor is lagging behind ages in comparison. We’re almost at the end of 2016 and there’s still now sight of php7 packages.
Since I have a server that has been Mandriva for decades (and now is running Mageia 5) and being half world apart, swapping  Linux distro isn’t an option so I decided to give it a go and install php 7 from source.

Since php7 actually brings a huge increase on speed and resource optimization I do recommend it.  I’m focused on Mageia 5 but general instructions can be easily applied to other linux distros.

We’ll need the following packages installed:

well use the php from package to figure what was the configuration used by running from cli :

php -i | grep Configure

this should return something like :

Configure Command =>  ‘./configure’  ‘–with-apxs2=/usr/bin/apxs’ ‘–build=x86_64-mageia-linux-gnu’ ‘–prefix=/usr’ ‘–exec-prefix=/usr’ ‘–bindir=/usr/bin’ ‘–sbindir=/usr/sbin’ ‘–sysconfdir=/etc’ ‘–datadir=/usr/share’ ‘–includedir=/usr/include’ ‘–libdir=/usr/lib64’ ‘–libexecdir=/usr/libexec’ ‘–localstatedir=/var/lib’ ‘–mandir=/usr/share/man’ ‘–enable-shared=yes’ ‘–enable-static=no’ ‘–with-libdir=lib64’ ‘–with-config-file-path=/etc’ ‘–with-config-file-scan-dir=/etc/php.d’ ‘–disable-debug’ ‘–enable-inline-optimization’ ‘–with-regex=system’ ‘–with-pcre-regex=/usr’ ‘–with-zlib=/usr’ ‘–with-pdo-odbc=unixODBC’ ‘–with-zlib=shared,/usr’ ‘–with-openssl=shared,/usr’ ‘–enable-libxml=/usr’ ‘–enable-mod_charset’ ‘–without-pear’ ‘–enable-bcmath=shared’ ‘–with-bz2=shared,/usr’ ‘–enable-calendar=shared’ ‘–enable-ctype=shared’ ‘–with-curl=shared,/usr’ ‘–without-curlwrappers’ ‘–enable-dba=shared’ ‘–with-gdbm’ ‘–with-db4’ ‘–with-cdb’ ‘–enable-dom=shared,/usr’ ‘–with-enchant=shared,/usr’ ‘–enable-exif=shared’ ‘–enable-fileinfo=shared’ ‘–enable-filter=shared’ ‘–with-pcre-dir=/usr’ ‘–enable-intl=shared’ ‘–with-icu-dir=/usr’ ‘–enable-json=shared’ ‘–with-libjson’ ‘–with-openssl-dir=/usr’ ‘–enable-ftp=shared’ ‘–with-gd=shared,/usr’ ‘–with-jpeg-dir=/usr’ ‘–with-vpx-dir=/usr’ ‘–with-png-dir=/usr’ ‘–with-xpm-dir=/usr/X11R6’ ‘–with-freetype-dir=/usr’ ‘–enable-gd-native-ttf’ ‘–with-t1lib=/usr’ ‘–with-gettext=shared,/usr’ ‘–with-gmp=shared,/usr’ ‘–enable-hash=shared,/usr’ ‘–with-iconv=shared’ ‘–with-imap=shared,/usr’ ‘–with-imap-ssl=/usr’ ‘–with-ldap=shared,/usr’ ‘–with-ldap-sasl=/usr’ ‘–enable-mbstring=shared,/usr’ ‘–enable-mbregex’ ‘–with-libmbfl=/usr’ ‘–with-onig=/usr’ ‘–with-mcrypt=shared,/usr’ ‘–with-mssql=shared,/usr’ ‘–with-mysql=shared,mysqlnd’ ‘–with-mysql-sock=/var/lib/mysql/mysql.sock’ ‘–with-zlib-dir=/usr’ ‘–with-mysqli=shared,mysqlnd’ ‘–enable-mysqlnd=shared,/usr/bin/mysql_config’ ‘–with-unixODBC=shared,/usr’ ‘–enable-opcache=shared’ ‘–enable-pcntl=shared’ ‘–enable-pdo=shared,/usr’ ‘–with-pdo-dblib=shared,/usr’ ‘–with-pdo-mysql=shared,mysqlnd’ ‘–with-pdo-odbc=shared,unixODBC,/usr’ ‘–with-pdo-pgsql=shared,/usr’ ‘–with-pdo-sqlite=shared,/usr’ ‘–with-pgsql=shared,/usr’ ‘–enable-phar=shared’ ‘–enable-posix=shared’ ‘–with-readline=shared,/usr’ ‘–with-recode=shared,/usr’ ‘–enable-session=shared,/usr’ ‘–enable-shmop=shared,/usr’ ‘–enable-simplexml’ ‘–with-snmp=shared,/usr’ ‘–enable-soap=shared,/usr’ ‘–enable-sockets=shared,/usr’ ‘–with-sqlite3=shared,/usr’ ‘–with-sybase-ct=shared,/usr’ ‘–enable-sysvmsg=shared,/usr’ ‘–enable-sysvsem=shared,/usr’ ‘–enable-sysvshm=shared,/usr’ ‘–with-tidy=shared,/usr’ ‘–enable-tokenizer=shared,/usr’ ‘–enable-xml=shared,/usr’ ‘–enable-xmlreader=shared,/usr’ ‘–with-xmlrpc=shared,/usr’ ‘–enable-xmlwriter=shared,/usr’ ‘–with-xsl=shared,/usr’ ‘–enable-wddx=shared’ ‘–with-libxml-dir=/usr’ ‘–enable-zip=shared’ ‘–with-libzip=/usr’ ‘–with-interbase=shared,/usr/lib64/firebird’ ‘–with-pdo-firebird=shared,/usr/lib64/firebird’ ‘–enable-phpdbg’

After striping the single quotes we have the configuration to apply to our source code.
For mageia 5 I had to remove “–with-recode=shared,/usr”, “–enable-phpdbg” and add “–disable-phpdbg”. (My Idea is to keep it close to the distro package settings but if you know exactly what you’re going to need and want to drop some  unneeded modules just remove them from the list )
Let’s unpack php7 code , cd into code directory and execute the config command.
Be prepared to find errors that my be different from distro to distro. I’m compiling php7 on Mageia 5 so after a few tries this is the list of packages I had to install before I could execute the configure script successfully.

  • enchant-devel
  • jpeglib-devel
  • xpm-devel
  • libgd-devel
  • lib64jbig-devel
  • lib64c-client-devel
  • firebird-devel
  • onig-devel
  • libmbfl-devel
  • lib64mcrypt-devel
  • lib64freetds-devel
  • lib64readline-devel
  • lib64recode-devel
  •  net-snmp
  • net-snmp-devel
  •  lib64xmlrpc-epi-devel
  • lib64zip-devel

So if you want to compile your php7 in mageia 5 you’ll need to execute:
urpmi enchant-devel jpeglib-devel xpm-devel libgd-devel lib64jbig-devel lib64c-client-devel firebird-devel onig-devel libmbfl-devel lib64mcrypt-devel lib64freetds-devel lib64readline-devel lib64recode-devel net-snmp net-snmp-devel lib64xmlrpc-epi-devel lib64zip-devel

after we configured the code project, we need to execute make:
If you get the following error “/usr/bin/ld: cannot find -lxmlrpc” it’s because the lib file has a different name so you can just create a soft link , inside of /usr/lib or /usr/lib64
ln -s libxmlrpc-epi.so libxmlrpc.so

With Mageia 5 (64bit version) there was an issue compiling related with readline it turned out that 64 bit version needed a soft link in /lib64 so I created the link and after it running make proceeded without errors:
ln -s /lib64/libmbfl.so.1.0.1 /lib64/libmbfl.so

To finally install you just need to run make install inside the php source directory but that won’t work in mageia because the script needs to find at least one line starting LoadModule inside the httpd.conf so before running the make install we need to edit the file:
/ect/httpd/conf/httpd.conf
Find : Include conf/modules.d/*.conf
and in the next line just add LoadModule php_module modules/mod_php.so

remove installed php packages and execute make install
once is done you can check if php is the right version by running:
php -v

PHP 7.0.12 (cli) (built: Oct 21 2016 12:40:18) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

 

No we are just missing to load all the php modules we compiled . My approach was to add a single include all file into /etc/php.d  that way I can enable or disable modules by commenting lines and it looks like this: (/etc/php.d/00_all.ini)

; Compiled Modules
extension=bcmath.so
extension=bz2.so
extension=calendar.so
extension=ctype.so
extension=curl.so
extension=dba.so
extension=dom.so
extension=enchant.so
extension=exif.so
extension=fileinfo.so
extension=ftp.so
extension=gd.so
extension=gettext.so
extension=gmp.so
extension=hash.so
extension=iconv.so
extension=imap.so
extension=interbase.so
extension=intl.so
extension=json.so
extension=ldap.so
extension=mbstring.so
extension=mcrypt.so
extension=mysqli.so
extension=mysqlnd.so
extension=odbc.so
extension=opcache.so
extension=openssl.so
extension=pcntl.so
extension=pdo_dblib.so
extension=pdo_firebird.so
extension=pdo_mysql.so
extension=pdo_odbc.so
extension=pdo_pgsql.so
extension=pdo.so
extension=pdo_sqlite.so
extension=pgsql.so
extension=phar.so
extension=posix.so
extension=readline.so
extension=session.so
extension=shmop.so
extension=snmp.so
extension=soap.so
extension=sockets.so
extension=sqlite3.so
extension=sysvmsg.so
extension=sysvsem.so
extension=sysvshm.so
extension=tidy.so
extension=tokenizer.so
extension=wddx.so
extension=xmlreader.so
extension=xmlrpc.so
extension=xml.so
extension=xmlwriter.so
extension=xsl.so
extension=zip.so
extension=zlib.so

 

Finally restart your Apache and Bob is your uncle!

 

Advertisements