Install PHP 5 (5.4, 5.5, 5.6) and PHP 7 on Linux

Submitted by nuwantha on Sat, 07/02/2016 - 11:45
Question

How to Install PHP 5.4 or PHP 5.5 or PHP 5.6 on debian based linux (Mint 17, 18..., Ubuntu 12, 14,16 ...) using PPA ?

How to Install PHP 7 on Linux  (Debian, Ubuntu, Mint ...) ?

Via PPA

Install PHP 5.4 On linux (Debian, Ubuntu, Mint ...)

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-get install -y php5

NOTE:
If you have this message add-apt-repository: command not found
run : apt-get install software-properties-common

Install PHP 5.5

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.5

Install PHP 5.6 On linux (Debian, Ubuntu, Mint ...)

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.6

 

Install PHP 7 On linux (Debian, Ubuntu, Mint ...)

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.0

 

Check Installed PHP Version

php -v

 

Install PHP 5.6 Modules

Show available PHP Modules list
sudo apt-cache search php5.6-* 

Install modules which is required for you.
Example PHP 5.6:
sudo apt-get install libapache2-mod-php5.6 php5.6-cgi php5.6-cli php5.6-curl php5.6-imap php5.6-gd php5.6-mysql php5.6-pgsql php5.6-sqlite3 php5.6-mbstring php5.6-json php5.6-bz2 php5.6-mcrypt php5.6-xmlrpc php5.6-gmp php5.6-xsl php5.6-soap php5.6-xml php5.6-zip php5.6-dba

Example PHP 7:
sudo apt-get install libapache2-mod-php7.0 php7.0-common php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0-gd

 

PHP 5.6 Modules list (Example)

php-amqp - AMQP extension for PHP
php-apcu - APC User Cache for PHP
php-geoip - GeoIP module for PHP
php-igbinary - igbinary PHP serializer
php-imagick - Provides a wrapper to the ImageMagick library
php-mongodb - MongoDB driver for PHP
php-msgpack - PHP extension for interfacing with MessagePack
php-oauth - OAuth 1.0 consumer and provider extension
php-redis - PHP extension for interfacing with Redis
php-rrd - PHP bindings to rrd tool system
php-smbclient - PHP wrapper for libsmbclient
php-solr - PHP extension for communicating with Apache Solr server
php-ssh2 - Bindings for the libssh2 library
php-uuid - PHP UUID extension
php-yac - YAC (Yet Another Cache) for PHP
php-zmq - ZeroMQ messaging bindings for PHP
php-radius - radius client library for PHP
php-http - PECL HTTP module for PHP Extended HTTP Support
php-uploadprogress - file upload progress tracking extension for PHP
libapache2-mod-php5.6 - server-side, HTML-embedded scripting language (Apache 2 module)
php5.6-cgi - server-side, HTML-embedded scripting language (CGI binary)
php5.6-cli - command-line interpreter for the PHP scripting language
php5.6-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php5.6-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
libphp5.6-embed - HTML-embedded scripting language (Embedded SAPI library)
php5.6-dev - Files for PHP5.6 module development
php5.6-common - documentation, examples and common module for PHP
php5.6 - server-side, HTML-embedded scripting language (metapackage)
php5.6-curl - CURL module for PHP
php5.6-gd - GD module for PHP
php5.6-imap - IMAP module for PHP
php5.6-intl - Internationalisation module for PHP
php5.6-ldap - LDAP module for PHP
php5.6-mysql - MySQL module for PHP
php5.6-pgsql - PostgreSQL module for PHP
php5.6-pspell - pspell module for PHP
php5.6-recode - recode module for PHP
php5.6-snmp - SNMP module for PHP
php5.6-sqlite3 - SQLite3 module for PHP
php5.6-sybase - Sybase module for PHP
php5.6-tidy - tidy module for PHP
php5.6-opcache - Zend OpCache module for PHP
php-xdebug - Xdebug Module for PHP
php5.6-json - JSON module for PHP
php-memcached - memcached extension module for PHP, uses libmemcached
php5.6-bz2 - bzip2 module for PHP
php5.6-mcrypt - libmcrypt module for PHP
php5.6-odbc - ODBC module for PHP
php5.6-readline - readline module for PHP
php5.6-interbase - Interbase module for PHP
php5.6-xmlrpc - XMLRPC-EPI module for PHP
php5.6-enchant - Enchant module for PHP
php5.6-gmp - GMP module for PHP
php5.6-xsl - XSL module for PHP (dummy)
php-memcache - memcache extension module for PHP
php-gmagick - Provides a wrapper to the GraphicsMagick library
php5.6-bcmath - Bcmath module for PHP
php5.6-mbstring - MBSTRING module for PHP
php5.6-soap - SOAP module for PHP
php5.6-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php5.6-zip - Zip module for PHP
php-tideways - Tideways PHP Profiler Extension
php-mailparse - Email message manipulation for PHP
php-propro - propro module for PHP
php-raphf - raphf module for PHP
php-stomp - Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP
php-gearman - PHP wrapper to libgearman
php-xcache - fast, stable PHP opcode cacher
php-mongo - MongoDB database driver
php5.6-dba - DBA module for PHP
php-xhprof - Hierarchical Profiler for PHP 5.x

 

PHP 7 Modules list (Example)

php7.0-common - Common files for packages built from the PHP source
libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.0-dev - Files for PHP7.0 module development
php7.0-dbg - Debug symbols for PHP7.0
php7.0-curl - CURL module for PHP
php7.0-gd - GD module for PHP
php7.0-imap - IMAP module for PHP
php7.0-intl - Internationalisation module for PHP
php7.0-ldap - LDAP module for PHP
php7.0-pgsql - PostgreSQL module for PHP
php7.0-pspell - pspell module for PHP
php7.0-recode - recode module for PHP
php7.0-snmp - SNMP module for PHP
php7.0-tidy - tidy module for PHP
php7.0-json - JSON module for PHP
php-all-dev - package depending on all supported PHP development packages
php7.0-sybase - Sybase module for PHP
php7.0-modules-source - PHP 7.0 modules source package
php7.0-sqlite3 - SQLite3 module for PHP
php7.0-mysql - MySQL module for PHP
php7.0-opcache - Zend OpCache module for PHP

 

 

Via DotDeb (for debian linux)

Add deb repository to /etc/apt/sources.list.d/dotdeb.list

For Debian 8
echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list.d/dotdeb.list

For Debian 7
echo "deb http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list.d/dotdeb.list
echo "deb-src http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list.d/dotdeb.list

Then
wget -O- https://www.dotdeb.org/dotdeb.gpg | apt-key add -
apt update

Remove If another version installed

systemctl stop php5-fpm
apt-get autoremove --purge php5*

Install PHP 7 for apache

apt install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json php7.0-gd php7.0-mcrypt php7.0-msgpack php7.0-memcached php7.0-intl php7.0-sqlite3 php7.0-gmp php7.0-geoip php7.0-mbstring php7.0-xml php7.0-zip

If you want to install php5.6 on debian 8 (Jessie)

apt-get -y install php5 libapache2-mod-php5

Comments

Oleg Abrazhaev (not verified)

Sun, 11/06/2016 - 11:30

I have installed both php5.6 and php7.0 on my Ubuntu and now I want to install libevent to php7
It's alreadey installed for php5.6 but how to install it to php7.0 too?

I have tied this commands and it's doesn't help
 

sudo update-alternatives --set php /usr/bin/php7.0

sudo pecl config-set php_ini /etc/php/7.0/cli/php.ini
sudo pecl config-set ext_dir /usr/lib/php/20151012/
sudo pecl config-set bin_dir /usr/bin/
sudo pecl config-set php_bin /usr/bin/php7.0
sudo pecl config-set php_suffix 7

pecl list still shows me that libevent installed, but it's in modules list only for php5.6 ...

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.