How to install PHP 7 from source (tar.gz) with Apache on FreeBSD 10.2

Last post I’ve try install official PHP 7 (GA) but I then realized that I have PHP 7.1 ( I use default branch of PHP git source). A reader also shoot me an email ask for simple connection to web server. I’m glad to write that since time permit 🙂

Here step by step guide install PHP 7.0 with Apache2 and MySQL 5.5 on FreeBSD 10.2

# pkg update
Updating FreeBSD repository catalogue…
Fetching meta.txz: 100% 940 B 0.9kB/s 00:01
Fetching packagesite.txz: 100% 5 MiB 251.3kB/s 00:22
Processing entries: 100%
FreeBSD repository update completed. 24605 packages processed.

# portsnap fetch
Looking up portsnap.FreeBSD.org mirrors… none found.
Fetching public key from portsnap.FreeBSD.org… done.
Fetching snapshot tag from portsnap.FreeBSD.org… done.
Fetching snapshot metadata… done.
Fetching snapshot generated at Sat Dec 12 07:02:07 WIB 2015:
a69a8b66039839a497463d737a142cf72e71c993a4fda7100% of 70 MB 205 kBps 05m51s
Extracting snapshot… done.
Verifying snapshot integrity… done.
Fetching snapshot tag from portsnap.FreeBSD.org… done.
Fetching snapshot metadata… done.
Updating from Sat Dec 12 07:02:07 WIB 2015 to Sat Dec 12 11:21:33 WIB 2015.
Fetching 4 metadata patches… done.
Applying metadata patches… done.
Fetching 0 metadata files… done.
Fetching 4 patches.
(4/4) 100.00% done.
done.
Applying patches…
done.
Fetching 0 new ports or files… done.

Why reinvent the wheel if php7 ports for FreeBSD available.

# portsnap extract

# cd /usr/ports/
# make search name=php70
# make search name=php7

Ok, still no ports available.

Install package

# pkg install -y autoconf bison libxml2 libxslt jpeg png libxpm freetype2 gmp libmcrypt mysql55-client mysql55-server aspell recode wget apache22 curl

Compile PHP 7 source on FreeBSD 10.2

# wget http://uk1.php.net/get/php-7.0.0.tar.gz/from/this/mirror -O php-7.0.0.tar.gz

# tar xvzf php-7.0.0.tar.gz

# cd php-7.0.0

Configure, make and make install

#./configure \
--prefix=$HOME/tmp/usr \
--with-config-file-path=$HOME/tmp/usr/etc \
--enable-mbstring \
--enable-zip \
--enable-bcmath \
--enable-pcntl \
--enable-ftp \
--enable-exif \
--enable-calendar \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-curl \
--with-mcrypt \
--with-iconv \
--with-gmp \
--with-pspell \
--with-gd \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-zlib-dir=/usr \
--with-xpm-dir=/usr \
--with-freetype-dir=/usr \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-openssl \
--with-gettext=/usr \
--with-zlib=/usr \
--with-bz2=/usr \
--with-recode=/usr \
--with-mysqli=/usr/local/bin/mysql_config \
--with-apxs2

# make
# make install

Check

# /root/tmp/usr/bin/php -v
PHP 7.0.0 (cli) (built: Dec 12 2015 19:03:37) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

# /root/tmp/usr/bin/php-cgi -v
PHP 7.0.0 (cgi-fcgi) (built: Dec 12 2015 19:03:58)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Connecting PHP 7 to Apache

Set Apache autostart

# echo 'apache22_enable="YES"' >> /etc/rc.conf

Fill a file with phpinfo content

# echo '<?php phpinfo();?>' > /usr/local/www/apache22/data/info.php

# ee /usr/local/etc/apache22/httpd.conf

Make sure these lines exist in httpd.conf
LoadModule php7_module libexec/apache22/libphp7.so

…………………

…………………

<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>

…………………

………………..

<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig etc/apache22/mime.types
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

save.

Start Apache22

# /usr/local/etc/rc.d/apache22 start

Testing from browser

php70freebsd

Until ports or package og PHP 7 available for FreeBSD then you can use it for testing purpose 🙂

See you then.

Apache/2.2.31 (FreeBSD) PHP/7.0.0 mod_ssl/2.2.31 OpenSSL/1.0.1p-freebsd DAV/2