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:
- apache-devel (we’ll need the apxs file)
- php-5.6.x (we’ll use this to get the default settings for compiling)
- and php 7 source http://php.net/downloads.php#v7.0.12
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!
March 24, 2017 at 3:46 pm
Hello
I’ve tried to follow your tutorial but I encounter this error after lauching .configure… command :
expr: non-integer argument
./configure: line 16885: test: : integer expression expected
configure: error: libxml2 version 2.6.11 or greater required.
The available packages libxml2-devel and libxml2-2 in Mageia 5.1 is actually 2.9.4.
How can I fix it ?
LikeLike
March 25, 2017 at 7:22 am
Hi Philippe , I haven’t check Mageia 5.1 yet, still the error you describe seems to be related with the expected file name and not so much the version itself since you have a higher version already installed. please try to create a symbolic link . in /usr/lib/ if your system is 32bits or in the /usr/lib64 if your system is 64bits .
Assuming you are using a 64bits and as root you should do something like:
ln -s /usr/lib64/libxml2.so.2.9.4 /usr/lib64/libxml2.so
and try to configure again.
let me know how it go and if needed I’ll setup a virtual machine with mageia 5.1 to check what different steps are needed.
LikeLike
March 27, 2017 at 7:56 am
Hello,
In fact, the error was due to the lack of the needed devel package.
Note : on a 64 bits computer, the name of the needed package is lib64xml2. libxml2 is for 32 bits computer.
I’ve had other similar error messages and I’ve fixed them by installing the corresponding devel package or by removing some non-useful packages from the .configure command.
I finally obtain the error below, yet I have deleted all xml config from the .configure command.
checking for xml2-config path… (cached) /usr/bin/xml2-config
checking whether libxml build works… (cached) yes
checking whether to enable XML support… yes
checking libexpat install dir… no
checking for xml2-config path… (cached) /usr/bin/xml2-config
checking whether libxml build works… (cached) yes
checking whether to enable XMLReader support… yes
checking for xml2-config path… (cached) /usr/bin/xml2-config
checking whether libxml build works… (cached) yes
configure: error:
You’ve configured extension xmlreader to build statically, but it
depends on extension dom, which you’ve configured to build shared.
You either need to build xmlreader shared or build dom statically for the
build to be successful.
So, I’ve decided to stay in PHP 5.6 on my computer but I have a question :
I think I can I run PHP 5.6 programs on a PHP 7.07 server but will these programs benefit of the speed of PHP 7 while executed ?
LikeLike
March 27, 2017 at 8:38 am
Hi Philippe, obviously you will have some of the speed of php 7 when running programs developed with php 5.6 . Just remember to check what has changed between php 5.6 and php 7 , I can tell you one thing different is the usage of the foreach loop which behaves differently .
While php 5.6 foreach passes each item by reference , php 7 doesn’t do that by default. so to have the same behavior as php 5.6 you need to do something like foreach( $myarr as &$item) …
I’ll test the installation process on Mageia 5.1 and see what else is needed to successfully install php 7 from source .
LikeLike