Installing on Linux/Unix Environments
Command Line Install Using APT for PHP 7
Section titled “Command Line Install Using APT for PHP 7”This will only install PHP. If you wish to serve a PHP file to the web you will also need to install a web-server such as [Apache](http://www.apache.org/), [Nginx](https://www.nginx.com/), or use [PHP's built in web-server](http://php.net/manual/en/features.commandline.webserver.php) (**php version 5.4+**).
If you are in a Ubuntu version below 16.04 and want to use PHP 7 anyway, you can add [Ondrej's PPA repository](https://launchpad.net/%7Eondrej/+archive/ubuntu/php/) by doing: `sudo add-apt-repository ppa:ondrej/php`
Make sure that all of your repositories are up to date:
sudo apt-get updateAfter updating your system’s repositories, install PHP:
sudo apt-get install php7.0Let’s test the installation by checking the PHP version:
php --versionThis should output something like this.
Note: Your output will be slightly different.
PHP 7.0.8-0ubuntu0.16.04.1 (cli) ( NTS )Copyright (c) 1997-2016 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologieswith Zend OPcache v7.0.8-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologieswith Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick RethansYou now have the capability to run PHP from the command line.
Installing in Enterprise Linux distributions (CentOS, Scientific Linux, etc)
Section titled “Installing in Enterprise Linux distributions (CentOS, Scientific Linux, etc)”Use the yum command to manage packages in Enterprise Linux-based operating systems:
yum install phpThis installs a minimal install of PHP including some common features. If you need additional modules, you will need to install them separately. Once again, you can use yum to search for these packages:
yum search php-*Example output:
php-bcmath.x86_64 : A module for PHP applications for using the bcmath libraryphp-cli.x86_64 : Command-line interface for PHPphp-common.x86_64 : Common files for PHPphp-dba.x86_64 : A database abstraction layer module for PHP applicationsphp-devel.x86_64 : Files needed for building PHP extensionsphp-embedded.x86_64 : PHP library for embedding in applicationsphp-enchant.x86_64 : Human Language and Character Encoding Supportphp-gd.x86_64 : A module for PHP applications for using the gd graphics libraryphp-imap.x86_64 : A module for PHP applications that use IMAPTo install the gd library:
yum install php-gdEnterprise Linux distributions have always been conservative with updates, and typically do not update beyond the point release they shipped with. A number of third party repositories provide current versions of PHP:
IUS and Webtatic provide replacement packages with different names (e.g. php56u or php56w to install PHP 5.6) while Remi’s repository provides in-place upgrades by using the same names as the system packages.
Following are instructions on installing PHP 7.0 from Remi’s repository. This is the simplest example, as uninstalling the system packages is not required.
# download the RPMs; replace 6 with 7 in case of EL 7wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmwget http://rpms.remirepo.net/enterprise/remi-release-6.rpm# install the repository informationrpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm# enable the repositoryyum-config-manager --enable epel --enable remi --enable remi-safe --enable remi-php70# install the new version of PHP# NOTE: if you already have the system package installed, this will update ityum install php