Create a gist now

Instantly share code, notes, and snippets.

Compiling PHP 7 on Ubuntu 15.04 with Various Supported Modules
#! /bin/bash
## PHP 7 Initial Compile ##
## Some help from the various places like these. ##
## Setup Ubuntu 15.04/15.10 ##
# Other dependencies for PHP 7. Add any missing ones from configure script
# complaints, plus some LAMP needs too.
sudo apt-get update
sudo apt-get install libldap2-dev \
libldap-2.4-2 \
libtool-bin \
libzip-dev \
lbzip2 \
libxml2-dev \
bzip2 \
re2c \
libbz2-dev \
apache2-dev \
libjpeg-dev \
libxpm-dev \
libxpm-dev \
libgmp-dev \
libgmp3-dev \
libmcrypt-dev \
libmysqlclient-dev \
mysql-server \
mysql-common \
libpspell-dev \
# PHP 7 does not recognize these without additional parameters or symlinks for
# Ldap.
sudo ln -sf /usr/lib/x86_64-linux-gnu/ /usr/lib/
sudo ln -sf /usr/lib/x86_64-linux-gnu/ /usr/lib/
sudo ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
# Obtain latest source
git clone
cd php-src
# Checkout latest release
git checkout PHP-7.0.3
# Helped fix configure issues.
# Setup compile options for Kubuntu 15.04. If failures occur, check dependencies
# and symlink needs above.
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/etc/php7/apache2 \
--with-config-file-scan-dir=/etc/php7/apache2/conf.d \
--enable-mbstring \
--enable-zip \
--enable-bcmath \
--enable-pcntl \
--enable-ftp \
--enable-exif \
--enable-calendar \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--enable-intl \
--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 \
--with-t1lib=/usr \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-openssl \
--with-pdo-mysql=/usr \
--with-gettext=/usr \
--with-zlib=/usr \
--with-bz2 \
--with-recode=/usr \
--with-apxs2=/usr/bin/apxs \
--with-mysqli=/usr/bin/mysql_config \
--with-ldap \
# Cleanup for previous failures.
sudo make clean
# Using as many threads as possible.
sudo make -j `cat /proc/cpuinfo | grep processor | wc -l`
# Install it accoridng to the configured path.
sudo make install
# It's own make script said to do this, but it didn't do much on my system.
libtool --finish ./libs
# Work on non-threaded version as compiled for now.
sudo a2dismod mpm_worker
sudo a2enmod mpm_prefork
# Since it is built with axps2, it sets things up correctly.
sudo a2enmod php7
# Restart Apache if all went well.
sudo systemctl restart apache2
# View any errors for Apache startup.
printf "Any errors starting Apache2 with PHP7 can be seen with 'sudo journalctl -xe' .\n"
# Update the paths on th system according to Ubuntu. Can be later removed and
# switched back.
sudo update-alternatives --install /usr/bin/php php /usr/local/php7/bin/php 50 \
--slave /usr/share/man/man1/php.1.gz php.1.gz \
# Choose your PHP version.
printf "Select the version of PHP you want active in subsequent shells and the \
sudo update-alternatives --config php
## To help enable Apache 2.4 use of PHP 7. Enable this after writing the file.
## /etc/apache2/mods-available/php7.conf
#<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
# SetHandler application/x-httpd-php
#<FilesMatch ".+\.phps$">
# SetHandler application/x-httpd-php-source
# # Deny access to raw php sources by default
# # To re-enable it's recommended to enable access to the files
# # only in specific virtual host or directory
# Require all denied
# Deny access to files without filename (e.g. '.php')
#<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
# Require all denied
# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
m1st0 commented Oct 9, 2015

Updated textual fixes and fixed configure issues. Working with PHP 7 v7.1.0.

m1st0 commented Oct 21, 2015

Understandably, I should provide a package archive likely at or similar. I didn't have time to put that deployment configuration together after this build, so I'll leave that up to you. There are nightly DEBs available, but I was trying to get LDAP working and thought this would help further to add modules needed apart from just PHP7.

m1st0 commented Dec 11, 2015

Updated for intl extension and make based on processor cores available. Working in Ubuntu 15.10, PHP 7.1.0-dev.

m1st0 commented Dec 11, 2015

Removed apt-fast since not everyone has its repo.

m1st0 commented Jan 20, 2016

Updated for use with compiled xdebug for PHP 7 and PHP 7 v7.0.3 release.


You can add commit messages to new revision, in case you didn't know. I think those would be better place for change descriptions. To achieve this, you need to clone and manage the Gist as a Git repository.


Hello, how do I install pdo_firebird driver?


I was getting the following error while enabling mpm_prefork

Considering conflict mpm_event for mpm_prefork:
ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first!
Considering conflict mpm_worker for mpm_prefork:

This ultimately led to the following error while starting apache

* The apache2 configtest failed.
Output of config test was:
[Fri Feb 19 07:25:37.100983 2016] [:crit] [pid 16524:tid 140221303203712] Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.
AH00013: Pre-configuration failed
Action 'configtest' failed.

I Solved it by apt-get install libapache2-mod-php7.0


you can save a lot of hdd space and time by shadow cloning a particular branch instead the whole repository:
$git clone = 320MB
$git clone -b PHP-7.0.6 --depth 1 = 19.7 MB
(my revision: )


I am not seeing any folder "/etc/php7/". so anyone guide me about this issue?

7snovic commented Aug 4, 2016 edited

when you run :


i got that error :

sorry i cannot run apxs. possible reasons follow

to resolve this you need to configure with :

and if you got that error :

configure: error: freetype-config not found.

you will need to install libfreetype6-dev

7snovic commented Aug 15, 2016

in some machines you will need to do some manual search for those files , , gmp.h

on AMD64 system you will not be able to locate that folder
and i found this folder under i386-linux-gnu name

so that part in some machines may be as like that

sudo ln -sf /usr/lib/i386-linux-gnu/ /usr/lib/
sudo ln -sf /usr/lib/i386-linux-gnu/ /usr/lib/
sudo ln -sf /usr/include/i386-linux-gnu/gmp.h /usr/include/gmp.h
7snovic commented Aug 15, 2016 edited

you will face a problem with --with-t1lib
T1lib To enable support for T1lib (Postscript Type 1 fonts) add --with-t1lib[=DIR] (Removed as of PHP 7.0.0).

Llbe commented Oct 12, 2016

I recommend --with-readline as well, to make sure you don't get stuck with libedit. Eg you can cut and paste text with ^U/^W and ^Y in interactive mode.

gustawdaniel commented Dec 18, 2016 edited

Line with t1lib is unnecesarry because of depreciation. (75)

T1lib To enable support for T1lib (Postscript Type 1 fonts) add --with-t1lib[=DIR] (Removed as of PHP 7.0.0).

Generally great script. I am impressed!

Miladbr commented Jan 11, 2017

On Ubuntu server 16.04 , before executing configure you should install bison package.

Configure: error: bison is required to build PHP/Zend when building a GIT checkout!
amdrade commented Jan 21, 2017

Ubuntu 15.04 ERROR: Module php7 does not exist!


I used your script to install php 5.6.
Works like a charm. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment